Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / test / Transforms / InstCombine / canonicalize-constant-low-bit-mask-and-icmp-sgt-to-icmp-sgt.ll
blob299ee78b7db429a238839d0819dd385e6440f941
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
6 ; Pattern:
7 ;   x s> x & C
8 ; Should be transformed into:
9 ;   x s> C
10 ; Iff: isPowerOf2(C + 1)
12 ; NOTE: this pattern is not commutative!
14 declare i8 @gen8()
15 declare <2 x i8> @gen2x8()
16 declare <3 x i8> @gen3x8()
18 ; ============================================================================ ;
19 ; Basic positive tests
20 ; ============================================================================ ;
22 define i1 @p0() {
23 ; CHECK-LABEL: @p0(
24 ; CHECK-NEXT:    [[X:%.*]] = call i8 @gen8()
25 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp sgt i8 [[X]], 3
26 ; CHECK-NEXT:    ret i1 [[TMP1]]
28   %x = call i8 @gen8()
29   %tmp0 = and i8 %x, 3
30   %ret = icmp sgt i8 %x, %tmp0
31   ret i1 %ret
34 define i1 @pv(i8 %y) {
35 ; CHECK-LABEL: @pv(
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]]
41   %x = call i8 @gen8()
42   %tmp0 = lshr i8 -1, %y
43   %tmp1 = and i8 %tmp0, %x
44   %ret = icmp sgt i8 %x, %tmp1
45   ret i1 %ret
48 ; ============================================================================ ;
49 ; Vector tests
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
61   ret <2 x i1> %ret
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
73   ret <2 x i1> %ret
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
85   ret <3 x i1> %ret
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]]
102   %x = call i8 @gen8()
103   %tmp0 = and i8 %x, 3
104   call void @use8(i8 %tmp0)
105   %ret = icmp sgt i8 %x, %tmp0
106   ret i1 %ret
109 ; ============================================================================ ;
110 ; Negative tests
111 ; ============================================================================ ;
113 ; ============================================================================ ;
114 ; Commutativity tests.
115 ; ============================================================================ ;
117 define i1 @c0(i8 %x) {
118 ; CHECK-LABEL: @c0(
119 ; CHECK-NEXT:    [[TMP0:%.*]] = and i8 [[X:%.*]], 3
120 ; CHECK-NEXT:    [[RET:%.*]] = icmp sgt i8 [[TMP0]], [[X]]
121 ; CHECK-NEXT:    ret i1 [[RET]]
123   %tmp0 = and i8 %x, 3
124   %ret = icmp sgt i8 %tmp0, %x ; swapped order
125   ret i1 %ret
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]]
140   %x = call i8 @gen8()
141   %tmp0 = lshr i8 -1, %y
142   %tmp1 = and i8 %tmp0, %x ; swapped order
143   %ret = icmp sgt i8 %x, %tmp1
144   ret i1 %ret
147 define i1 @cv1(i8 %y) {
148 ; CHECK-LABEL: @cv1(
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]]
155   %x = call i8 @gen8()
156   %tmp0 = lshr i8 -1, %y
157   %tmp1 = and i8 %x, %tmp0
158   %ret = icmp sgt i8 %tmp1, %x ; swapped order
159   ret i1 %ret
162 define i1 @cv2(i8 %x, i8 %y) {
163 ; CHECK-LABEL: @cv2(
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
172   ret i1 %ret
175 ; ============================================================================ ;
176 ; Normal negative tests
177 ; ============================================================================ ;
179 define i1 @n0() {
180 ; CHECK-LABEL: @n0(
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]]
186   %x = call i8 @gen8()
187   %tmp0 = and i8 %x, 4 ; power-of-two, but invalid.
188   %ret = icmp sgt i8 %x, %tmp0
189   ret i1 %ret
192 define i1 @n1(i8 %y, i8 %notx) {
193 ; CHECK-LABEL: @n1(
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]]
199   %x = call i8 @gen8()
200   %tmp0 = and i8 %x, 3
201   %ret = icmp sgt i8 %tmp0, %notx ; not %x
202   ret i1 %ret
205 define <2 x i1> @n2() {
206 ; CHECK-LABEL: @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
215   ret <2 x i1> %ret