1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; https://bugs.llvm.org/show_bug.cgi?id=38123
8 ; Should be transformed into:
10 ; Iff: isPowerOf2(C + 1)
12 ; NOTE: this pattern is not commutative!
15 declare <2 x i8> @gen2x8()
16 declare <3 x i8> @gen3x8()
18 ; ============================================================================ ;
19 ; Basic positive tests
20 ; ============================================================================ ;
24 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
25 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[X]], 3
26 ; CHECK-NEXT: ret i1 [[TMP1]]
30 %ret = icmp sgt i8 %x, %tmp0
34 define i1 @pv(i8 %y) {
36 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
37 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
38 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[X]], [[TMP0]]
39 ; CHECK-NEXT: ret i1 [[TMP1]]
42 %tmp0 = lshr i8 -1, %y
43 %tmp1 = and i8 %tmp0, %x
44 %ret = icmp sgt i8 %x, %tmp1
48 ; ============================================================================ ;
50 ; ============================================================================ ;
52 define <2 x i1> @p1_vec_splat() {
53 ; CHECK-LABEL: @p1_vec_splat(
54 ; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
55 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X]], <i8 3, i8 3>
56 ; CHECK-NEXT: ret <2 x i1> [[TMP1]]
58 %x = call <2 x i8> @gen2x8()
59 %tmp0 = and <2 x i8> %x, <i8 3, i8 3>
60 %ret = icmp sgt <2 x i8> %x, %tmp0
64 define <2 x i1> @p2_vec_nonsplat() {
65 ; CHECK-LABEL: @p2_vec_nonsplat(
66 ; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
67 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X]], <i8 3, i8 15>
68 ; CHECK-NEXT: ret <2 x i1> [[TMP1]]
70 %x = call <2 x i8> @gen2x8()
71 %tmp0 = and <2 x i8> %x, <i8 3, i8 15> ; doesn't have to be splat.
72 %ret = icmp sgt <2 x i8> %x, %tmp0
76 define <3 x i1> @p3_vec_splat_undef() {
77 ; CHECK-LABEL: @p3_vec_splat_undef(
78 ; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8()
79 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <3 x i8> [[X]], <i8 3, i8 undef, i8 3>
80 ; CHECK-NEXT: ret <3 x i1> [[TMP1]]
82 %x = call <3 x i8> @gen3x8()
83 %tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 3>
84 %ret = icmp sgt <3 x i8> %x, %tmp0
88 ; ============================================================================ ;
89 ; One-use tests. We don't care about multi-uses here.
90 ; ============================================================================ ;
92 declare void @use8(i8)
94 define i1 @oneuse0() {
95 ; CHECK-LABEL: @oneuse0(
96 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
97 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 3
98 ; CHECK-NEXT: call void @use8(i8 [[TMP0]])
99 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[X]], 3
100 ; CHECK-NEXT: ret i1 [[TMP1]]
104 call void @use8(i8 %tmp0)
105 %ret = icmp sgt i8 %x, %tmp0
109 ; ============================================================================ ;
111 ; ============================================================================ ;
113 ; ============================================================================ ;
114 ; Commutativity tests.
115 ; ============================================================================ ;
117 define i1 @c0(i8 %x) {
119 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3
120 ; CHECK-NEXT: [[RET:%.*]] = icmp sgt i8 [[TMP0]], [[X]]
121 ; CHECK-NEXT: ret i1 [[RET]]
124 %ret = icmp sgt i8 %tmp0, %x ; swapped order
128 ; ============================================================================ ;
129 ; Commutativity tests with variable
130 ; ============================================================================ ;
132 ; Ok, this one should fold. We only testing commutativity of 'and'.
133 define i1 @cv0_GOOD(i8 %y) {
134 ; CHECK-LABEL: @cv0_GOOD(
135 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
136 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
137 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[X]], [[TMP0]]
138 ; CHECK-NEXT: ret i1 [[TMP1]]
141 %tmp0 = lshr i8 -1, %y
142 %tmp1 = and i8 %tmp0, %x ; swapped order
143 %ret = icmp sgt i8 %x, %tmp1
147 define i1 @cv1(i8 %y) {
149 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
150 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
151 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
152 ; CHECK-NEXT: [[RET:%.*]] = icmp sgt i8 [[TMP1]], [[X]]
153 ; CHECK-NEXT: ret i1 [[RET]]
156 %tmp0 = lshr i8 -1, %y
157 %tmp1 = and i8 %x, %tmp0
158 %ret = icmp sgt i8 %tmp1, %x ; swapped order
162 define i1 @cv2(i8 %x, i8 %y) {
164 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
165 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X:%.*]]
166 ; CHECK-NEXT: [[RET:%.*]] = icmp sgt i8 [[TMP1]], [[X]]
167 ; CHECK-NEXT: ret i1 [[RET]]
169 %tmp0 = lshr i8 -1, %y
170 %tmp1 = and i8 %tmp0, %x ; swapped order
171 %ret = icmp sgt i8 %tmp1, %x ; swapped order
175 ; ============================================================================ ;
176 ; Normal negative tests
177 ; ============================================================================ ;
181 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
182 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 4
183 ; CHECK-NEXT: [[RET:%.*]] = icmp sgt i8 [[X]], [[TMP0]]
184 ; CHECK-NEXT: ret i1 [[RET]]
187 %tmp0 = and i8 %x, 4 ; power-of-two, but invalid.
188 %ret = icmp sgt i8 %x, %tmp0
192 define i1 @n1(i8 %y, i8 %notx) {
194 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
195 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 3
196 ; CHECK-NEXT: [[RET:%.*]] = icmp sgt i8 [[TMP0]], [[NOTX:%.*]]
197 ; CHECK-NEXT: ret i1 [[RET]]
201 %ret = icmp sgt i8 %tmp0, %notx ; not %x
205 define <2 x i1> @n2() {
207 ; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
208 ; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X]], <i8 3, i8 16>
209 ; CHECK-NEXT: [[RET:%.*]] = icmp sgt <2 x i8> [[X]], [[TMP0]]
210 ; CHECK-NEXT: ret <2 x i1> [[RET]]
212 %x = call <2 x i8> @gen2x8()
213 %tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.
214 %ret = icmp sgt <2 x i8> %x, %tmp0