1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
6 define i32 @test1(i32 %a, i32 %b) nounwind readnone {
8 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[B:%.*]], [[A:%.*]]
9 ; CHECK-NEXT: [[DOTLOBIT:%.*]] = lshr i32 [[TMP1]], 31
10 ; CHECK-NEXT: [[DOTLOBIT_NOT:%.*]] = xor i32 [[DOTLOBIT]], 1
11 ; CHECK-NEXT: ret i32 [[DOTLOBIT_NOT]]
13 %t0 = icmp sgt i32 %a, -1
14 %t1 = icmp slt i32 %b, 0
16 %t3 = zext i1 %t2 to i32
20 ; TODO: This optimizes partially but not all the way.
21 define i32 @test2(i32 %a, i32 %b) nounwind readnone {
22 ; CHECK-LABEL: @test2(
23 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
24 ; CHECK-NEXT: [[TMP2:%.*]] = lshr i32 [[TMP1]], 3
25 ; CHECK-NEXT: [[DOTLOBIT:%.*]] = and i32 [[TMP2]], 1
26 ; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[DOTLOBIT]], 1
27 ; CHECK-NEXT: ret i32 [[TMP3]]
31 %t2 = icmp eq i32 %t0, %t1
32 %t3 = zext i1 %t2 to i32
36 define i32 @test3(i32 %a, i32 %b) nounwind readnone {
37 ; CHECK-LABEL: @test3(
38 ; CHECK-NEXT: [[T2_UNSHIFTED:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
39 ; CHECK-NEXT: [[T2_UNSHIFTED_LOBIT:%.*]] = lshr i32 [[T2_UNSHIFTED]], 31
40 ; CHECK-NEXT: [[T2_UNSHIFTED_LOBIT_NOT:%.*]] = xor i32 [[T2_UNSHIFTED_LOBIT]], 1
41 ; CHECK-NEXT: ret i32 [[T2_UNSHIFTED_LOBIT_NOT]]
45 %t2 = icmp eq i32 %t0, %t1
46 %t3 = zext i1 %t2 to i32
50 ; TODO this should optimize but doesn't due to missing vector support in InstCombiner::foldICmpEquality.
51 define <2 x i32> @test3vec(<2 x i32> %a, <2 x i32> %b) nounwind readnone {
52 ; CHECK-LABEL: @test3vec(
53 ; CHECK-NEXT: [[T0:%.*]] = lshr <2 x i32> [[A:%.*]], <i32 31, i32 31>
54 ; CHECK-NEXT: [[T1:%.*]] = lshr <2 x i32> [[B:%.*]], <i32 31, i32 31>
55 ; CHECK-NEXT: [[T2:%.*]] = icmp eq <2 x i32> [[T0]], [[T1]]
56 ; CHECK-NEXT: [[T3:%.*]] = zext <2 x i1> [[T2]] to <2 x i32>
57 ; CHECK-NEXT: ret <2 x i32> [[T3]]
59 %t0 = lshr <2 x i32> %a, <i32 31, i32 31>
60 %t1 = lshr <2 x i32> %b, <i32 31, i32 31>
61 %t2 = icmp eq <2 x i32> %t0, %t1
62 %t3 = zext <2 x i1> %t2 to <2 x i32>
66 ; Variation on @test3: checking the 2nd bit in a situation where the 5th bit
68 define i32 @test3i(i32 %a, i32 %b) nounwind readnone {
69 ; CHECK-LABEL: @test3i(
70 ; CHECK-NEXT: [[T01:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
71 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[T01]], 31
72 ; CHECK-NEXT: [[T4:%.*]] = xor i32 [[TMP1]], 1
73 ; CHECK-NEXT: ret i32 [[T4]]
79 %t4 = icmp eq i32 %t2, %t3
80 %t5 = zext i1 %t4 to i32
84 define i1 @test4a(i32 %a) {
85 ; CHECK-LABEL: @test4a(
86 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[A:%.*]], 1
87 ; CHECK-NEXT: ret i1 [[C]]
92 %signum = or i32 %l, %r
93 %c = icmp slt i32 %signum, 1
97 define <2 x i1> @test4a_vec(<2 x i32> %a) {
98 ; CHECK-LABEL: @test4a_vec(
99 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i32> [[A:%.*]], <i32 1, i32 1>
100 ; CHECK-NEXT: ret <2 x i1> [[C]]
102 %l = ashr <2 x i32> %a, <i32 31, i32 31>
103 %na = sub <2 x i32> zeroinitializer, %a
104 %r = lshr <2 x i32> %na, <i32 31, i32 31>
105 %signum = or <2 x i32> %l, %r
106 %c = icmp slt <2 x i32> %signum, <i32 1, i32 1>
110 define i1 @test4b(i64 %a) {
111 ; CHECK-LABEL: @test4b(
112 ; CHECK-NEXT: [[C:%.*]] = icmp slt i64 [[A:%.*]], 1
113 ; CHECK-NEXT: ret i1 [[C]]
117 %r = lshr i64 %na, 63
118 %signum = or i64 %l, %r
119 %c = icmp slt i64 %signum, 1
123 define i1 @test4c(i64 %a) {
124 ; CHECK-LABEL: @test4c(
125 ; CHECK-NEXT: [[C:%.*]] = icmp slt i64 [[A:%.*]], 1
126 ; CHECK-NEXT: ret i1 [[C]]
130 %r = lshr i64 %na, 63
131 %signum = or i64 %l, %r
132 %signum.trunc = trunc i64 %signum to i32
133 %c = icmp slt i32 %signum.trunc, 1
137 define <2 x i1> @test4c_vec(<2 x i64> %a) {
138 ; CHECK-LABEL: @test4c_vec(
139 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i64> [[A:%.*]], <i64 1, i64 1>
140 ; CHECK-NEXT: ret <2 x i1> [[C]]
142 %l = ashr <2 x i64> %a, <i64 63, i64 63>
143 %na = sub <2 x i64> zeroinitializer, %a
144 %r = lshr <2 x i64> %na, <i64 63, i64 63>
145 %signum = or <2 x i64> %l, %r
146 %signum.trunc = trunc <2 x i64> %signum to <2 x i32>
147 %c = icmp slt <2 x i32> %signum.trunc, <i32 1, i32 1>