Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / test / Transforms / InstCombine / canonicalize-constant-low-bit-mask-and-icmp-ne-to-icmp-ugt.ll
blob850266381e7ea328930e29eca32df16e866e268f
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 & C != x
8 ; Should be transformed into:
9 ;   x u> C
10 ; Iff: isPowerOf2(C + 1)
12 ; ============================================================================ ;
13 ; Basic positive tests
14 ; ============================================================================ ;
16 define i1 @p0(i8 %x) {
17 ; CHECK-LABEL: @p0(
18 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ugt i8 [[X:%.*]], 3
19 ; CHECK-NEXT:    ret i1 [[TMP1]]
21   %tmp0 = and i8 %x, 3
22   %ret = icmp ne i8 %tmp0, %x
23   ret i1 %ret
26 define i1 @pv(i8 %x, i8 %y) {
27 ; CHECK-LABEL: @pv(
28 ; CHECK-NEXT:    [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
29 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i8 [[TMP0]], [[X:%.*]]
30 ; CHECK-NEXT:    ret i1 [[TMP1]]
32   %tmp0 = lshr i8 -1, %y
33   %tmp1 = and i8 %tmp0, %x
34   %ret = icmp ne i8 %tmp1, %x
35   ret i1 %ret
38 ; ============================================================================ ;
39 ; Vector tests
40 ; ============================================================================ ;
42 define <2 x i1> @p1_vec_splat(<2 x i8> %x) {
43 ; CHECK-LABEL: @p1_vec_splat(
44 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 3>
45 ; CHECK-NEXT:    ret <2 x i1> [[TMP1]]
47   %tmp0 = and <2 x i8> %x, <i8 3, i8 3>
48   %ret = icmp ne <2 x i8> %tmp0, %x
49   ret <2 x i1> %ret
52 define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
53 ; CHECK-LABEL: @p2_vec_nonsplat(
54 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 15>
55 ; CHECK-NEXT:    ret <2 x i1> [[TMP1]]
57   %tmp0 = and <2 x i8> %x, <i8 3, i8 15> ; doesn't have to be splat.
58   %ret = icmp ne <2 x i8> %tmp0, %x
59   ret <2 x i1> %ret
62 define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
63 ; CHECK-LABEL: @p3_vec_splat_undef(
64 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ugt <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>
65 ; CHECK-NEXT:    ret <3 x i1> [[TMP1]]
67   %tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 3>
68   %ret = icmp ne <3 x i8> %tmp0, %x
69   ret <3 x i1> %ret
72 ; ============================================================================ ;
73 ; Commutativity tests.
74 ; ============================================================================ ;
76 declare i8 @gen8()
78 define i1 @c0() {
79 ; CHECK-LABEL: @c0(
80 ; CHECK-NEXT:    [[X:%.*]] = call i8 @gen8()
81 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ugt i8 [[X]], 3
82 ; CHECK-NEXT:    ret i1 [[TMP1]]
84   %x = call i8 @gen8()
85   %tmp0 = and i8 %x, 3
86   %ret = icmp ne i8 %x, %tmp0 ; swapped order
87   ret i1 %ret
90 ; ============================================================================ ;
91 ; Commutativity tests with variable
92 ; ============================================================================ ;
94 define i1 @cv0(i8 %y) {
95 ; CHECK-LABEL: @cv0(
96 ; CHECK-NEXT:    [[X:%.*]] = call i8 @gen8()
97 ; CHECK-NEXT:    [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
98 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ugt i8 [[X]], [[TMP0]]
99 ; CHECK-NEXT:    ret i1 [[TMP1]]
101   %x = call i8 @gen8()
102   %tmp0 = lshr i8 -1, %y
103   %tmp1 = and i8 %x, %tmp0 ; swapped order
104   %ret = icmp ne i8 %tmp1, %x
105   ret i1 %ret
108 define i1 @cv1(i8 %y) {
109 ; CHECK-LABEL: @cv1(
110 ; CHECK-NEXT:    [[X:%.*]] = call i8 @gen8()
111 ; CHECK-NEXT:    [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
112 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ugt i8 [[X]], [[TMP0]]
113 ; CHECK-NEXT:    ret i1 [[TMP1]]
115   %x = call i8 @gen8()
116   %tmp0 = lshr i8 -1, %y
117   %tmp1 = and i8 %tmp0, %x
118   %ret = icmp ne i8 %x, %tmp1 ; swapped order
119   ret i1 %ret
122 define i1 @cv2(i8 %y) {
123 ; CHECK-LABEL: @cv2(
124 ; CHECK-NEXT:    [[X:%.*]] = call i8 @gen8()
125 ; CHECK-NEXT:    [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
126 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ugt i8 [[X]], [[TMP0]]
127 ; CHECK-NEXT:    ret i1 [[TMP1]]
129   %x = call i8 @gen8()
130   %tmp0 = lshr i8 -1, %y
131   %tmp1 = and i8 %x, %tmp0 ; swapped order
132   %ret = icmp ne i8 %x, %tmp1 ; swapped order
133   ret i1 %ret
136 ; ============================================================================ ;
137 ; One-use tests. We don't care about multi-uses here.
138 ; ============================================================================ ;
140 declare void @use8(i8)
142 define i1 @oneuse0(i8 %x) {
143 ; CHECK-LABEL: @oneuse0(
144 ; CHECK-NEXT:    [[TMP0:%.*]] = and i8 [[X:%.*]], 3
145 ; CHECK-NEXT:    call void @use8(i8 [[TMP0]])
146 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ugt i8 [[X]], 3
147 ; CHECK-NEXT:    ret i1 [[TMP1]]
149   %tmp0 = and i8 %x, 3
150   call void @use8(i8 %tmp0)
151   %ret = icmp ne i8 %tmp0, %x
152   ret i1 %ret
155 ; ============================================================================ ;
156 ; Negative tests
157 ; ============================================================================ ;
159 define i1 @n0(i8 %x) {
160 ; CHECK-LABEL: @n0(
161 ; CHECK-NEXT:    [[TMP0:%.*]] = and i8 [[X:%.*]], 4
162 ; CHECK-NEXT:    [[RET:%.*]] = icmp ne i8 [[TMP0]], [[X]]
163 ; CHECK-NEXT:    ret i1 [[RET]]
165   %tmp0 = and i8 %x, 4 ; power-of-two, but invalid.
166   %ret = icmp ne i8 %tmp0, %x
167   ret i1 %ret
170 define i1 @n1(i8 %x, i8 %y, i8 %notx) {
171 ; CHECK-LABEL: @n1(
172 ; CHECK-NEXT:    [[TMP0:%.*]] = and i8 [[X:%.*]], 3
173 ; CHECK-NEXT:    [[RET:%.*]] = icmp ne i8 [[TMP0]], [[NOTX:%.*]]
174 ; CHECK-NEXT:    ret i1 [[RET]]
176   %tmp0 = and i8 %x, 3
177   %ret = icmp ne i8 %tmp0, %notx ; not %x
178   ret i1 %ret
181 define <2 x i1> @n2(<2 x i8> %x) {
182 ; CHECK-LABEL: @n2(
183 ; CHECK-NEXT:    [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 16>
184 ; CHECK-NEXT:    [[RET:%.*]] = icmp ne <2 x i8> [[TMP0]], [[X]]
185 ; CHECK-NEXT:    ret <2 x i1> [[RET]]
187   %tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.
188   %ret = icmp ne <2 x i8> %tmp0, %x
189   ret <2 x i1> %ret