signbit-shl-and-icmpeq-zero.ll
8.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
; For pattern (X & (signbit << Y)) ==/!= 0
; it may be optimal to fold into (X l>> Y) >=/< 0
; Scalar tests
define i1 @scalar_i8_signbit_shl_and_eq(i8 %x, i8 %y) {
; CHECK-LABEL: @scalar_i8_signbit_shl_and_eq(
; CHECK-NEXT: [[SHL:%.*]] = shl i8 -128, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i8 [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i8 128, %y
%and = and i8 %shl, %x
%r = icmp eq i8 %and, 0
ret i1 %r
}
define i1 @scalar_i16_signbit_shl_and_eq(i16 %x, i16 %y) {
; CHECK-LABEL: @scalar_i16_signbit_shl_and_eq(
; CHECK-NEXT: [[SHL:%.*]] = shl i16 -32768, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i16 [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq i16 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i16 32768, %y
%and = and i16 %shl, %x
%r = icmp eq i16 %and, 0
ret i1 %r
}
define i1 @scalar_i32_signbit_shl_and_eq(i32 %x, i32 %y) {
; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq(
; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i32 2147483648, %y
%and = and i32 %shl, %x
%r = icmp eq i32 %and, 0
ret i1 %r
}
define i1 @scalar_i64_signbit_shl_and_eq(i64 %x, i64 %y) {
; CHECK-LABEL: @scalar_i64_signbit_shl_and_eq(
; CHECK-NEXT: [[SHL:%.*]] = shl i64 -9223372036854775808, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i64 [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq i64 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i64 9223372036854775808, %y
%and = and i64 %shl, %x
%r = icmp eq i64 %and, 0
ret i1 %r
}
define i1 @scalar_i32_signbit_shl_and_ne(i32 %x, i32 %y) {
; CHECK-LABEL: @scalar_i32_signbit_shl_and_ne(
; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp ne i32 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i32 2147483648, %y
%and = and i32 %shl, %x
%r = icmp ne i32 %and, 0 ; check 'ne' predicate
ret i1 %r
}
; Vector tests
define <4 x i1> @vec_4xi32_signbit_shl_and_eq(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @vec_4xi32_signbit_shl_and_eq(
; CHECK-NEXT: [[SHL:%.*]] = shl <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq <4 x i32> [[AND]], zeroinitializer
; CHECK-NEXT: ret <4 x i1> [[R]]
;
%shl = shl <4 x i32> <i32 2147483648, i32 2147483648, i32 2147483648, i32 2147483648>, %y
%and = and <4 x i32> %shl, %x
%r = icmp eq <4 x i32> %and, <i32 0, i32 0, i32 0, i32 0>
ret <4 x i1> %r
}
define <4 x i1> @vec_4xi32_signbit_shl_and_eq_undef1(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @vec_4xi32_signbit_shl_and_eq_undef1(
; CHECK-NEXT: [[SHL:%.*]] = shl <4 x i32> <i32 -2147483648, i32 undef, i32 -2147483648, i32 2147473648>, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq <4 x i32> [[AND]], zeroinitializer
; CHECK-NEXT: ret <4 x i1> [[R]]
;
%shl = shl <4 x i32> <i32 2147483648, i32 undef, i32 2147483648, i32 2147473648>, %y
%and = and <4 x i32> %shl, %x
%r = icmp eq <4 x i32> %and, <i32 0, i32 0, i32 0, i32 0>
ret <4 x i1> %r
}
define <4 x i1> @vec_4xi32_signbit_shl_and_eq_undef2(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @vec_4xi32_signbit_shl_and_eq_undef2(
; CHECK-NEXT: [[SHL:%.*]] = shl <4 x i32> <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 2147473648>, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq <4 x i32> [[AND]], <i32 0, i32 0, i32 0, i32 undef>
; CHECK-NEXT: ret <4 x i1> [[R]]
;
%shl = shl <4 x i32> <i32 2147483648, i32 2147483648, i32 2147483648, i32 2147473648>, %y
%and = and <4 x i32> %shl, %x
%r = icmp eq <4 x i32> %and, <i32 0, i32 0, i32 0, i32 undef>
ret <4 x i1> %r
}
define <4 x i1> @vec_4xi32_signbit_shl_and_eq_undef3(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @vec_4xi32_signbit_shl_and_eq_undef3(
; CHECK-NEXT: [[SHL:%.*]] = shl <4 x i32> <i32 -2147483648, i32 undef, i32 -2147483648, i32 2147473648>, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and <4 x i32> [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq <4 x i32> [[AND]], <i32 undef, i32 0, i32 0, i32 0>
; CHECK-NEXT: ret <4 x i1> [[R]]
;
%shl = shl <4 x i32> <i32 2147483648, i32 undef, i32 2147483648, i32 2147473648>, %y
%and = and <4 x i32> %shl, %x
%r = icmp eq <4 x i32> %and, <i32 undef, i32 0, i32 0, i32 0>
ret <4 x i1> %r
}
; Extra use
; Fold happened
define i1 @scalar_i32_signbit_shl_and_eq_extra_use_shl(i32 %x, i32 %y, i32 %z, i32* %p) {
; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_extra_use_shl(
; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[SHL]], [[Z:%.*]]
; CHECK-NEXT: store i32 [[XOR]], i32* [[P:%.*]], align 4
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i32 2147483648, %y
%xor = xor i32 %shl, %z ; extra use of shl
store i32 %xor, i32* %p
%and = and i32 %shl, %x
%r = icmp eq i32 %and, 0
ret i1 %r
}
; Not fold
define i1 @scalar_i32_signbit_shl_and_eq_extra_use_and(i32 %x, i32 %y, i32 %z, i32* %p) {
; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_extra_use_and(
; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[AND]], [[Z:%.*]]
; CHECK-NEXT: store i32 [[MUL]], i32* [[P:%.*]], align 4
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i32 2147483648, %y
%and = and i32 %shl, %x
%mul = mul i32 %and, %z ; extra use of and
store i32 %mul, i32* %p
%r = icmp eq i32 %and, 0
ret i1 %r
}
; Not fold
define i1 @scalar_i32_signbit_shl_and_eq_extra_use_shl_and(i32 %x, i32 %y, i32 %z, i32* %p, i32* %q) {
; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_extra_use_shl_and(
; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
; CHECK-NEXT: store i32 [[AND]], i32* [[P:%.*]], align 4
; CHECK-NEXT: [[ADD:%.*]] = add i32 [[SHL]], [[Z:%.*]]
; CHECK-NEXT: store i32 [[ADD]], i32* [[Q:%.*]], align 4
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i32 2147483648, %y
%and = and i32 %shl, %x
store i32 %and, i32* %p ; extra use of and
%add = add i32 %shl, %z ; extra use of shl
store i32 %add, i32* %q
%r = icmp eq i32 %and, 0
ret i1 %r
}
; X is constant
define i1 @scalar_i32_signbit_shl_and_eq_X_is_constant1(i32 %y) {
; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_X_is_constant1(
; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], 12345
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i32 2147483648, %y
%and = and i32 %shl, 12345
%r = icmp eq i32 %and, 0
ret i1 %r
}
define i1 @scalar_i32_signbit_shl_and_eq_X_is_constant2(i32 %y) {
; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_X_is_constant2(
; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], 1
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i32 2147483648, %y
%and = and i32 %shl, 1
%r = icmp eq i32 %and, 0
ret i1 %r
}
; Negative tests
; Check 'slt' predicate
define i1 @scalar_i32_signbit_shl_and_slt(i32 %x, i32 %y) {
; CHECK-LABEL: @scalar_i32_signbit_shl_and_slt(
; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp slt i32 [[AND]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i32 2147483648, %y
%and = and i32 %shl, %x
%r = icmp slt i32 %and, 0
ret i1 %r
}
; Compare with nonzero
define i1 @scalar_i32_signbit_shl_and_eq_nonzero(i32 %x, i32 %y) {
; CHECK-LABEL: @scalar_i32_signbit_shl_and_eq_nonzero(
; CHECK-NEXT: [[SHL:%.*]] = shl i32 -2147483648, [[Y:%.*]]
; CHECK-NEXT: [[AND:%.*]] = and i32 [[SHL]], [[X:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[AND]], 1
; CHECK-NEXT: ret i1 [[R]]
;
%shl = shl i32 2147483648, %y
%and = and i32 %shl, %x
%r = icmp eq i32 %and, 1 ; should be comparing with 0
ret i1 %r
}