[SimplifyLibCalls] Remove useless bits of this tests.
[oota-llvm.git] / test / Transforms / InstCombine / compare-signs.ll
1 ; RUN: opt -instcombine -S < %s | FileCheck %s
2 ; PR5438
3
4 ; TODO: This should also optimize down.
5 ;define i32 @test1(i32 %a, i32 %b) nounwind readnone {
6 ;entry:
7 ;        %0 = icmp sgt i32 %a, -1        ; <i1> [#uses=1]
8 ;        %1 = icmp slt i32 %b, 0         ; <i1> [#uses=1]
9 ;        %2 = xor i1 %1, %0              ; <i1> [#uses=1]
10 ;        %3 = zext i1 %2 to i32          ; <i32> [#uses=1]
11 ;        ret i32 %3
12 ;}
13
14 ; TODO: This optimizes partially but not all the way.
15 ;define i32 @test2(i32 %a, i32 %b) nounwind readnone {
16 ;entry:
17 ;        %0 = and i32 %a, 8            ;<i32>  [#uses=1]
18 ;        %1 = and i32 %b, 8            ;<i32>  [#uses=1]
19 ;        %2 = icmp eq i32 %0, %1         ;<i1>  [#uses=1]
20 ;        %3 = zext i1 %2 to i32          ;<i32>  [#uses=1]
21 ;        ret i32 %3
22 ;}
23
24 define i32 @test3(i32 %a, i32 %b) nounwind readnone {
25 ; CHECK-LABEL: @test3(
26 entry:
27 ; CHECK: [[XOR1:%.*]] = xor i32 %a, %b
28 ; CHECK: [[SHIFT:%.*]] = lshr i32 [[XOR1]], 31
29 ; CHECK: [[XOR2:%.*]] = xor i32 [[SHIFT]], 1
30         %0 = lshr i32 %a, 31            ; <i32> [#uses=1]
31         %1 = lshr i32 %b, 31            ; <i32> [#uses=1]
32         %2 = icmp eq i32 %0, %1         ; <i1> [#uses=1]
33         %3 = zext i1 %2 to i32          ; <i32> [#uses=1]
34         ret i32 %3
35 ; CHECK-NOT: icmp
36 ; CHECK-NOT: zext
37 ; CHECK: ret i32 [[XOR2]]
38 }
39
40 ; Variation on @test3: checking the 2nd bit in a situation where the 5th bit
41 ; is one, not zero.
42 define i32 @test3i(i32 %a, i32 %b) nounwind readnone {
43 ; CHECK-LABEL: @test3i(
44 entry:
45 ; CHECK: xor i32 %a, %b
46 ; CHECK: lshr i32 %0, 31
47 ; CHECK: xor i32 %1, 1
48         %0 = lshr i32 %a, 29            ; <i32> [#uses=1]
49         %1 = lshr i32 %b, 29            ; <i32> [#uses=1]
50         %2 = or i32 %0, 35
51         %3 = or i32 %1, 35
52         %4 = icmp eq i32 %2, %3         ; <i1> [#uses=1]
53         %5 = zext i1 %4 to i32          ; <i32> [#uses=1]
54         ret i32 %5
55 ; CHECK-NOT: icmp
56 ; CHECK-NOT: zext
57 ; CHECK: ret i32 %2
58 }
59
60 define i1 @test4a(i32 %a) {
61 ; CHECK-LABEL: @test4a(
62  entry:
63 ; CHECK: %c = icmp slt i32 %a, 1
64 ; CHECK-NEXT: ret i1 %c
65   %l = ashr i32 %a, 31
66   %na = sub i32 0, %a
67   %r = lshr i32 %na, 31
68   %signum = or i32 %l, %r
69   %c = icmp slt i32 %signum, 1
70   ret i1 %c
71 }
72
73 define i1 @test4b(i64 %a) {
74 ; CHECK-LABEL: @test4b(
75  entry:
76 ; CHECK: %c = icmp slt i64 %a, 1
77 ; CHECK-NEXT: ret i1 %c
78   %l = ashr i64 %a, 63
79   %na = sub i64 0, %a
80   %r = lshr i64 %na, 63
81   %signum = or i64 %l, %r
82   %c = icmp slt i64 %signum, 1
83   ret i1 %c
84 }
85
86 define i1 @test4c(i64 %a) {
87 ; CHECK-LABEL: @test4c(
88  entry:
89 ; CHECK: %c = icmp slt i64 %a, 1
90 ; CHECK-NEXT: ret i1 %c
91   %l = ashr i64 %a, 63
92   %na = sub i64 0, %a
93   %r = lshr i64 %na, 63
94   %signum = or i64 %l, %r
95   %signum.trunc = trunc i64 %signum to i32
96   %c = icmp slt i32 %signum.trunc, 1
97   ret i1 %c
98 }