1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -instcombine -S | FileCheck %s
4 ; For pattern (X & (signbit << Y)) ==/!= 0
5 ; it may be optimal to fold into (X l>> Y) >=/< 0
9 define i1 @scalar_i8_signbit_shl_and_eq(i8 %x, i8 %y) {
10 ; CHECK-LABEL: @scalar_i8_signbit_shl_and_eq(
11 ; CHECK-NEXT: [[SHL:%.*]] = shl i8 -128, [[Y:%.*]]
12 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[SHL]], [[X:%.*]]
13 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 0
14 ; CHECK-NEXT: ret i1 [[R]]
17 %and = and i8 %shl, %x
18 %r = icmp eq i8 %and, 0
22 define i1 @scalar_i16_signbit_shl_and_eq(i16 %x, i16 %y) {
23 ; CHECK-LABEL: @scalar_i16_signbit_shl_and_eq(
24 ; CHECK-NEXT: [[SHL:%.*]] = shl i16 -32768, [[Y:%.*]]
25 ; CHECK-NEXT: [[AND:%.*]] = and i16 [[SHL]], [[X:%.*]]
26 ; CHECK-NEXT: [[R:%.*]] = icmp eq i16 [[AND]], 0
27 ; CHECK-NEXT: ret i1 [[R]]
29 %shl = shl i16 32768, %y
30 %and = and i16 %shl, %x
31 %r = icmp eq i16 %and, 0
35 define i1 @scalar_i32_signbit_shl_and_eq(i32 %x, i32 %y) {
36 ; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq(
37 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
38 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
39 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
40 ; CHECK-NEXT: ret i1 [[R]]
42 %shl = shl i32 2147483648, %y
43 %and = and i32 %shl, %x
44 %r = icmp eq i32 %and, 0
48 define i1 @scalar_i64_signbit_shl_and_eq(i64 %x, i64 %y) {
49 ; CHECK-LABEL: @scalar_i64_signbit_shl_and_eq(
50 ; CHECK-NEXT: [[SHL:%.*]] = shl i64 -9223372036854775808, [[Y:%.*]]
51 ; CHECK-NEXT: [[AND:%.*]] = and i64 [[SHL]], [[X:%.*]]
52 ; CHECK-NEXT: [[R:%.*]] = icmp eq i64 [[AND]], 0
53 ; CHECK-NEXT: ret i1 [[R]]
55 %shl = shl i64 9223372036854775808, %y
56 %and = and i64 %shl, %x
57 %r = icmp eq i64 %and, 0
61 define i1 @scalar_i32_signbit_shl_and_ne(i32 %x, i32 %y) {
62 ; CHECK-LABEL: @scalar_i32_signbit_shl_and_ne(
63 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
64 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
65 ; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[AND]], 0
66 ; CHECK-NEXT: ret i1 [[R]]
68 %shl = shl i32 2147483648, %y
69 %and = and i32 %shl, %x
70 %r = icmp ne i32 %and, 0 ; check 'ne' predicate
76 define <4 x i1> @vec_4xi32_signbit_shl_and_eq(<4 x i32> %x, <4 x i32> %y) {
77 ; CHECK-LABEL: @vec_4xi32_signbit_shl_and_eq(
78 ; CHECK-NEXT: [[SHL:%.*]] = shl <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, [[Y:%.*]]
79 ; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[X:%.*]]
80 ; CHECK-NEXT: [[R:%.*]] = icmp eq <4 x i32> [[AND]], zeroinitializer
81 ; CHECK-NEXT: ret <4 x i1> [[R]]
83 %shl = shl <4 x i32> <i32 2147483648, i32 2147483648, i32 2147483648, i32 2147483648>, %y
84 %and = and <4 x i32> %shl, %x
85 %r = icmp eq <4 x i32> %and, <i32 0, i32 0, i32 0, i32 0>
89 define <4 x i1> @vec_4xi32_signbit_shl_and_eq_undef1(<4 x i32> %x, <4 x i32> %y) {
90 ; CHECK-LABEL: @vec_4xi32_signbit_shl_and_eq_undef1(
91 ; CHECK-NEXT: [[SHL:%.*]] = shl <4 x i32> <i32 -2147483648, i32 undef, i32 -2147483648, i32 2147473648>, [[Y:%.*]]
92 ; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[X:%.*]]
93 ; CHECK-NEXT: [[R:%.*]] = icmp eq <4 x i32> [[AND]], zeroinitializer
94 ; CHECK-NEXT: ret <4 x i1> [[R]]
96 %shl = shl <4 x i32> <i32 2147483648, i32 undef, i32 2147483648, i32 2147473648>, %y
97 %and = and <4 x i32> %shl, %x
98 %r = icmp eq <4 x i32> %and, <i32 0, i32 0, i32 0, i32 0>
102 define <4 x i1> @vec_4xi32_signbit_shl_and_eq_undef2(<4 x i32> %x, <4 x i32> %y) {
103 ; CHECK-LABEL: @vec_4xi32_signbit_shl_and_eq_undef2(
104 ; CHECK-NEXT: [[SHL:%.*]] = shl <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 2147473648>, [[Y:%.*]]
105 ; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[X:%.*]]
106 ; CHECK-NEXT: [[R:%.*]] = icmp eq <4 x i32> [[AND]], <i32 0, i32 0, i32 0, i32 undef>
107 ; CHECK-NEXT: ret <4 x i1> [[R]]
109 %shl = shl <4 x i32> <i32 2147483648, i32 2147483648, i32 2147483648, i32 2147473648>, %y
110 %and = and <4 x i32> %shl, %x
111 %r = icmp eq <4 x i32> %and, <i32 0, i32 0, i32 0, i32 undef>
115 define <4 x i1> @vec_4xi32_signbit_shl_and_eq_undef3(<4 x i32> %x, <4 x i32> %y) {
116 ; CHECK-LABEL: @vec_4xi32_signbit_shl_and_eq_undef3(
117 ; CHECK-NEXT: [[SHL:%.*]] = shl <4 x i32> <i32 -2147483648, i32 undef, i32 -2147483648, i32 2147473648>, [[Y:%.*]]
118 ; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[X:%.*]]
119 ; CHECK-NEXT: [[R:%.*]] = icmp eq <4 x i32> [[AND]], <i32 undef, i32 0, i32 0, i32 0>
120 ; CHECK-NEXT: ret <4 x i1> [[R]]
122 %shl = shl <4 x i32> <i32 2147483648, i32 undef, i32 2147483648, i32 2147473648>, %y
123 %and = and <4 x i32> %shl, %x
124 %r = icmp eq <4 x i32> %and, <i32 undef, i32 0, i32 0, i32 0>
131 define i1 @scalar_i32_signbit_shl_and_eq_extra_use_shl(i32 %x, i32 %y, i32 %z, i32* %p) {
132 ; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_extra_use_shl(
133 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
134 ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[SHL]], [[Z:%.*]]
135 ; CHECK-NEXT: store i32 [[XOR]], i32* [[P:%.*]], align 4
136 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
137 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
138 ; CHECK-NEXT: ret i1 [[R]]
140 %shl = shl i32 2147483648, %y
141 %xor = xor i32 %shl, %z ; extra use of shl
142 store i32 %xor, i32* %p
143 %and = and i32 %shl, %x
144 %r = icmp eq i32 %and, 0
149 define i1 @scalar_i32_signbit_shl_and_eq_extra_use_and(i32 %x, i32 %y, i32 %z, i32* %p) {
150 ; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_extra_use_and(
151 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
152 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
153 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[AND]], [[Z:%.*]]
154 ; CHECK-NEXT: store i32 [[MUL]], i32* [[P:%.*]], align 4
155 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
156 ; CHECK-NEXT: ret i1 [[R]]
158 %shl = shl i32 2147483648, %y
159 %and = and i32 %shl, %x
160 %mul = mul i32 %and, %z ; extra use of and
161 store i32 %mul, i32* %p
162 %r = icmp eq i32 %and, 0
167 define i1 @scalar_i32_signbit_shl_and_eq_extra_use_shl_and(i32 %x, i32 %y, i32 %z, i32* %p, i32* %q) {
168 ; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_extra_use_shl_and(
169 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
170 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
171 ; CHECK-NEXT: store i32 [[AND]], i32* [[P:%.*]], align 4
172 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[SHL]], [[Z:%.*]]
173 ; CHECK-NEXT: store i32 [[ADD]], i32* [[Q:%.*]], align 4
174 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
175 ; CHECK-NEXT: ret i1 [[R]]
177 %shl = shl i32 2147483648, %y
178 %and = and i32 %shl, %x
179 store i32 %and, i32* %p ; extra use of and
180 %add = add i32 %shl, %z ; extra use of shl
181 store i32 %add, i32* %q
182 %r = icmp eq i32 %and, 0
188 define i1 @scalar_i32_signbit_shl_and_eq_X_is_constant1(i32 %y) {
189 ; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_X_is_constant1(
190 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
191 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], 12345
192 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
193 ; CHECK-NEXT: ret i1 [[R]]
195 %shl = shl i32 2147483648, %y
196 %and = and i32 %shl, 12345
197 %r = icmp eq i32 %and, 0
201 define i1 @scalar_i32_signbit_shl_and_eq_X_is_constant2(i32 %y) {
202 ; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_X_is_constant2(
203 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
204 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], 1
205 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
206 ; CHECK-NEXT: ret i1 [[R]]
208 %shl = shl i32 2147483648, %y
209 %and = and i32 %shl, 1
210 %r = icmp eq i32 %and, 0
216 ; Check 'slt' predicate
218 define i1 @scalar_i32_signbit_shl_and_slt(i32 %x, i32 %y) {
219 ; CHECK-LABEL: @scalar_i32_signbit_shl_and_slt(
220 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
221 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
222 ; CHECK-NEXT: [[R:%.*]] = icmp slt i32 [[AND]], 0
223 ; CHECK-NEXT: ret i1 [[R]]
225 %shl = shl i32 2147483648, %y
226 %and = and i32 %shl, %x
227 %r = icmp slt i32 %and, 0
231 ; Compare with nonzero
233 define i1 @scalar_i32_signbit_shl_and_eq_nonzero(i32 %x, i32 %y) {
234 ; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_nonzero(
235 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
236 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
237 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 1
238 ; CHECK-NEXT: ret i1 [[R]]
240 %shl = shl i32 2147483648, %y
241 %and = and i32 %shl, %x
242 %r = icmp eq i32 %and, 1 ; should be comparing with 0