summaryrefslogtreecommitdiff
path: root/test/CodeGen/X86/lzcnt-zext-cmp.ll
blob: 6123bdfc0dbfabe8e6aea13784c3736fd48e6307 (plain)
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; Test patterns which generates lzcnt instructions.
; Eg: zext(or(setcc(cmp), setcc(cmp))) -> shr(or(lzcnt, lzcnt))
; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=btver2 | FileCheck --check-prefix=ALL --check-prefix=FASTLZCNT %s
; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=btver2 -mattr=-fast-lzcnt | FileCheck --check-prefix=ALL --check-prefix=NOFASTLZCNT %s
; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=znver1 | FileCheck --check-prefix=ALL --check-prefix=FASTLZCNT %s
; RUN: llc < %s -mtriple=x86_64-pc-linux -mcpu=znver1 -mattr=-fast-lzcnt | FileCheck --check-prefix=ALL --check-prefix=NOFASTLZCNT %s

; Test one 32-bit input, output is 32-bit, no transformations expected.
define i32 @test_zext_cmp0(i32 %a) {
; ALL-LABEL: test_zext_cmp0:
; ALL:       # %bb.0: # %entry
; ALL-NEXT:    xorl %eax, %eax
; ALL-NEXT:    testl %edi, %edi
; ALL-NEXT:    sete %al
; ALL-NEXT:    retq
entry:
  %cmp = icmp eq i32 %a, 0
  %conv = zext i1 %cmp to i32
  ret i32 %conv
}

; Test two 32-bit inputs, output is 32-bit.
define i32 @test_zext_cmp1(i32 %a, i32 %b) {
; FASTLZCNT-LABEL: test_zext_cmp1:
; FASTLZCNT:       # %bb.0:
; FASTLZCNT-NEXT:    lzcntl %edi, %ecx
; FASTLZCNT-NEXT:    lzcntl %esi, %eax
; FASTLZCNT-NEXT:    orl %ecx, %eax
; FASTLZCNT-NEXT:    shrl $5, %eax
; FASTLZCNT-NEXT:    retq
;
; NOFASTLZCNT-LABEL: test_zext_cmp1:
; NOFASTLZCNT:       # %bb.0:
; NOFASTLZCNT-NEXT:    testl %edi, %edi
; NOFASTLZCNT-NEXT:    sete %al
; NOFASTLZCNT-NEXT:    testl %esi, %esi
; NOFASTLZCNT-NEXT:    sete %cl
; NOFASTLZCNT-NEXT:    orb %al, %cl
; NOFASTLZCNT-NEXT:    movzbl %cl, %eax
; NOFASTLZCNT-NEXT:    retq
  %cmp = icmp eq i32 %a, 0
  %cmp1 = icmp eq i32 %b, 0
  %or = or i1 %cmp, %cmp1
  %lor.ext = zext i1 %or to i32
  ret i32 %lor.ext
}

; Test two 64-bit inputs, output is 64-bit.
define i64 @test_zext_cmp2(i64 %a, i64 %b) {
; FASTLZCNT-LABEL: test_zext_cmp2:
; FASTLZCNT:       # %bb.0:
; FASTLZCNT-NEXT:    lzcntq %rdi, %rcx
; FASTLZCNT-NEXT:    lzcntq %rsi, %rax
; FASTLZCNT-NEXT:    orl %ecx, %eax
; FASTLZCNT-NEXT:    shrl $6, %eax
; FASTLZCNT-NEXT:    retq
;
; NOFASTLZCNT-LABEL: test_zext_cmp2:
; NOFASTLZCNT:       # %bb.0:
; NOFASTLZCNT-NEXT:    testq %rdi, %rdi
; NOFASTLZCNT-NEXT:    sete %al
; NOFASTLZCNT-NEXT:    testq %rsi, %rsi
; NOFASTLZCNT-NEXT:    sete %cl
; NOFASTLZCNT-NEXT:    orb %al, %cl
; NOFASTLZCNT-NEXT:    movzbl %cl, %eax
; NOFASTLZCNT-NEXT:    retq
  %cmp = icmp eq i64 %a, 0
  %cmp1 = icmp eq i64 %b, 0
  %or = or i1 %cmp, %cmp1
  %lor.ext = zext i1 %or to i64
  ret i64 %lor.ext
}

; Test two 16-bit inputs, output is 16-bit.
; The transform is disabled for the 16-bit case, as we still have to clear the
; upper 16-bits, adding one more instruction.
define i16 @test_zext_cmp3(i16 %a, i16 %b) {
; ALL-LABEL: test_zext_cmp3:
; ALL:       # %bb.0:
; ALL-NEXT:    testw %di, %di
; ALL-NEXT:    sete %al
; ALL-NEXT:    testw %si, %si
; ALL-NEXT:    sete %cl
; ALL-NEXT:    orb %al, %cl
; ALL-NEXT:    movzbl %cl, %eax
; ALL-NEXT:    # kill: %ax<def> %ax<kill> %eax<kill>
; ALL-NEXT:    retq
  %cmp = icmp eq i16 %a, 0
  %cmp1 = icmp eq i16 %b, 0
  %or = or i1 %cmp, %cmp1
  %lor.ext = zext i1 %or to i16
  ret i16 %lor.ext
}

; Test two 32-bit inputs, output is 64-bit.
define i64 @test_zext_cmp4(i32 %a, i32 %b) {
; FASTLZCNT-LABEL: test_zext_cmp4:
; FASTLZCNT:       # %bb.0: # %entry
; FASTLZCNT-NEXT:    lzcntl %edi, %ecx
; FASTLZCNT-NEXT:    lzcntl %esi, %eax
; FASTLZCNT-NEXT:    orl %ecx, %eax
; FASTLZCNT-NEXT:    shrl $5, %eax
; FASTLZCNT-NEXT:    retq
;
; NOFASTLZCNT-LABEL: test_zext_cmp4:
; NOFASTLZCNT:       # %bb.0: # %entry
; NOFASTLZCNT-NEXT:    testl %edi, %edi
; NOFASTLZCNT-NEXT:    sete %al
; NOFASTLZCNT-NEXT:    testl %esi, %esi
; NOFASTLZCNT-NEXT:    sete %cl
; NOFASTLZCNT-NEXT:    orb %al, %cl
; NOFASTLZCNT-NEXT:    movzbl %cl, %eax
; NOFASTLZCNT-NEXT:    retq
entry:
  %cmp = icmp eq i32 %a, 0
  %cmp1 = icmp eq i32 %b, 0
  %0 = or i1 %cmp, %cmp1
  %conv = zext i1 %0 to i64
  ret i64 %conv
}

; Test two 64-bit inputs, output is 32-bit.
define i32 @test_zext_cmp5(i64 %a, i64 %b) {
; FASTLZCNT-LABEL: test_zext_cmp5:
; FASTLZCNT:       # %bb.0: # %entry
; FASTLZCNT-NEXT:    lzcntq %rdi, %rcx
; FASTLZCNT-NEXT:    lzcntq %rsi, %rax
; FASTLZCNT-NEXT:    orl %ecx, %eax
; FASTLZCNT-NEXT:    shrl $6, %eax
; FASTLZCNT-NEXT:    # kill: %eax<def> %eax<kill> %rax<kill>
; FASTLZCNT-NEXT:    retq
;
; NOFASTLZCNT-LABEL: test_zext_cmp5:
; NOFASTLZCNT:       # %bb.0: # %entry
; NOFASTLZCNT-NEXT:    testq %rdi, %rdi
; NOFASTLZCNT-NEXT:    sete %al
; NOFASTLZCNT-NEXT:    testq %rsi, %rsi
; NOFASTLZCNT-NEXT:    sete %cl
; NOFASTLZCNT-NEXT:    orb %al, %cl
; NOFASTLZCNT-NEXT:    movzbl %cl, %eax
; NOFASTLZCNT-NEXT:    retq
entry:
  %cmp = icmp eq i64 %a, 0
  %cmp1 = icmp eq i64 %b, 0
  %0 = or i1 %cmp, %cmp1
  %lor.ext = zext i1 %0 to i32
  ret i32 %lor.ext
}

; Test three 32-bit inputs, output is 32-bit.
define i32 @test_zext_cmp6(i32 %a, i32 %b, i32 %c) {
; FASTLZCNT-LABEL: test_zext_cmp6:
; FASTLZCNT:       # %bb.0: # %entry
; FASTLZCNT-NEXT:    lzcntl %edi, %eax
; FASTLZCNT-NEXT:    lzcntl %esi, %ecx
; FASTLZCNT-NEXT:    orl %eax, %ecx
; FASTLZCNT-NEXT:    lzcntl %edx, %eax
; FASTLZCNT-NEXT:    orl %ecx, %eax
; FASTLZCNT-NEXT:    shrl $5, %eax
; FASTLZCNT-NEXT:    retq
;
; NOFASTLZCNT-LABEL: test_zext_cmp6:
; NOFASTLZCNT:       # %bb.0: # %entry
; NOFASTLZCNT-NEXT:    testl %edi, %edi
; NOFASTLZCNT-NEXT:    sete %al
; NOFASTLZCNT-NEXT:    testl %esi, %esi
; NOFASTLZCNT-NEXT:    sete %cl
; NOFASTLZCNT-NEXT:    orb %al, %cl
; NOFASTLZCNT-NEXT:    testl %edx, %edx
; NOFASTLZCNT-NEXT:    sete %al
; NOFASTLZCNT-NEXT:    orb %cl, %al
; NOFASTLZCNT-NEXT:    movzbl %al, %eax
; NOFASTLZCNT-NEXT:    retq
entry:
  %cmp = icmp eq i32 %a, 0
  %cmp1 = icmp eq i32 %b, 0
  %or.cond = or i1 %cmp, %cmp1
  %cmp2 = icmp eq i32 %c, 0
  %.cmp2 = or i1 %or.cond, %cmp2
  %lor.ext = zext i1 %.cmp2 to i32
  ret i32 %lor.ext
}

; Test three 32-bit inputs, output is 32-bit, but compared to test_zext_cmp6 test,
; %.cmp2 inputs' order is inverted.
define i32 @test_zext_cmp7(i32 %a, i32 %b, i32 %c) {
; FASTLZCNT-LABEL: test_zext_cmp7:
; FASTLZCNT:       # %bb.0: # %entry
; FASTLZCNT-NEXT:    lzcntl %edi, %eax
; FASTLZCNT-NEXT:    lzcntl %esi, %ecx
; FASTLZCNT-NEXT:    orl %eax, %ecx
; FASTLZCNT-NEXT:    lzcntl %edx, %eax
; FASTLZCNT-NEXT:    orl %ecx, %eax
; FASTLZCNT-NEXT:    shrl $5, %eax
; FASTLZCNT-NEXT:    retq
;
; NOFASTLZCNT-LABEL: test_zext_cmp7:
; NOFASTLZCNT:       # %bb.0: # %entry
; NOFASTLZCNT-NEXT:    testl %edi, %edi
; NOFASTLZCNT-NEXT:    sete %al
; NOFASTLZCNT-NEXT:    testl %esi, %esi
; NOFASTLZCNT-NEXT:    sete %cl
; NOFASTLZCNT-NEXT:    orb %al, %cl
; NOFASTLZCNT-NEXT:    testl %edx, %edx
; NOFASTLZCNT-NEXT:    sete %al
; NOFASTLZCNT-NEXT:    orb %cl, %al
; NOFASTLZCNT-NEXT:    movzbl %al, %eax
; NOFASTLZCNT-NEXT:    retq
entry:
  %cmp = icmp eq i32 %a, 0
  %cmp1 = icmp eq i32 %b, 0
  %or.cond = or i1 %cmp, %cmp1
  %cmp2 = icmp eq i32 %c, 0
  %.cmp2 = or i1 %cmp2, %or.cond
  %lor.ext = zext i1 %.cmp2 to i32
  ret i32 %lor.ext
}

; Test four 32-bit inputs, output is 32-bit.
define i32 @test_zext_cmp8(i32 %a, i32 %b, i32 %c, i32 %d) {
; FASTLZCNT-LABEL: test_zext_cmp8:
; FASTLZCNT:       # %bb.0: # %entry
; FASTLZCNT-NEXT:    lzcntl %edi, %eax
; FASTLZCNT-NEXT:    lzcntl %esi, %esi
; FASTLZCNT-NEXT:    lzcntl %edx, %edx
; FASTLZCNT-NEXT:    orl %eax, %esi
; FASTLZCNT-NEXT:    lzcntl %ecx, %eax
; FASTLZCNT-NEXT:    orl %edx, %eax
; FASTLZCNT-NEXT:    orl %esi, %eax
; FASTLZCNT-NEXT:    shrl $5, %eax
; FASTLZCNT-NEXT:    retq
;
; NOFASTLZCNT-LABEL: test_zext_cmp8:
; NOFASTLZCNT:       # %bb.0: # %entry
; NOFASTLZCNT-NEXT:    testl %edi, %edi
; NOFASTLZCNT-NEXT:    sete %dil
; NOFASTLZCNT-NEXT:    testl %esi, %esi
; NOFASTLZCNT-NEXT:    sete %al
; NOFASTLZCNT-NEXT:    orb %dil, %al
; NOFASTLZCNT-NEXT:    testl %edx, %edx
; NOFASTLZCNT-NEXT:    sete %dl
; NOFASTLZCNT-NEXT:    testl %ecx, %ecx
; NOFASTLZCNT-NEXT:    sete %cl
; NOFASTLZCNT-NEXT:    orb %dl, %cl
; NOFASTLZCNT-NEXT:    orb %al, %cl
; NOFASTLZCNT-NEXT:    movzbl %cl, %eax
; NOFASTLZCNT-NEXT:    retq
entry:
  %cmp = icmp eq i32 %a, 0
  %cmp1 = icmp eq i32 %b, 0
  %or.cond = or i1 %cmp, %cmp1
  %cmp3 = icmp eq i32 %c, 0
  %or.cond5 = or i1 %or.cond, %cmp3
  %cmp4 = icmp eq i32 %d, 0
  %.cmp4 = or i1 %or.cond5, %cmp4
  %lor.ext = zext i1 %.cmp4 to i32
  ret i32 %lor.ext
}

; Test one 32-bit input, one 64-bit input, output is 32-bit.
define i32 @test_zext_cmp9(i32 %a, i64 %b) {
; FASTLZCNT-LABEL: test_zext_cmp9:
; FASTLZCNT:       # %bb.0: # %entry
; FASTLZCNT-NEXT:    lzcntq %rsi, %rax
; FASTLZCNT-NEXT:    lzcntl %edi, %ecx
; FASTLZCNT-NEXT:    shrl $5, %ecx
; FASTLZCNT-NEXT:    shrl $6, %eax
; FASTLZCNT-NEXT:    orl %ecx, %eax
; FASTLZCNT-NEXT:    # kill: %eax<def> %eax<kill> %rax<kill>
; FASTLZCNT-NEXT:    retq
;
; NOFASTLZCNT-LABEL: test_zext_cmp9:
; NOFASTLZCNT:       # %bb.0: # %entry
; NOFASTLZCNT-NEXT:    testl %edi, %edi
; NOFASTLZCNT-NEXT:    sete %al
; NOFASTLZCNT-NEXT:    testq %rsi, %rsi
; NOFASTLZCNT-NEXT:    sete %cl
; NOFASTLZCNT-NEXT:    orb %al, %cl
; NOFASTLZCNT-NEXT:    movzbl %cl, %eax
; NOFASTLZCNT-NEXT:    retq
entry:
  %cmp = icmp eq i32 %a, 0
  %cmp1 = icmp eq i64 %b, 0
  %0 = or i1 %cmp, %cmp1
  %lor.ext = zext i1 %0 to i32
  ret i32 %lor.ext
}

; Test 2 128-bit inputs, output is 32-bit, no transformations expected.
define i32 @test_zext_cmp10(i64 %a.coerce0, i64 %a.coerce1, i64 %b.coerce0, i64 %b.coerce1) {
; ALL-LABEL: test_zext_cmp10:
; ALL:       # %bb.0: # %entry
; ALL-NEXT:    orq %rsi, %rdi
; ALL-NEXT:    sete %al
; ALL-NEXT:    orq %rcx, %rdx
; ALL-NEXT:    sete %cl
; ALL-NEXT:    orb %al, %cl
; ALL-NEXT:    movzbl %cl, %eax
; ALL-NEXT:    retq
entry:
  %a.sroa.2.0.insert.ext = zext i64 %a.coerce1 to i128
  %a.sroa.2.0.insert.shift = shl nuw i128 %a.sroa.2.0.insert.ext, 64
  %a.sroa.0.0.insert.ext = zext i64 %a.coerce0 to i128
  %a.sroa.0.0.insert.insert = or i128 %a.sroa.2.0.insert.shift, %a.sroa.0.0.insert.ext
  %b.sroa.2.0.insert.ext = zext i64 %b.coerce1 to i128
  %b.sroa.2.0.insert.shift = shl nuw i128 %b.sroa.2.0.insert.ext, 64
  %b.sroa.0.0.insert.ext = zext i64 %b.coerce0 to i128
  %b.sroa.0.0.insert.insert = or i128 %b.sroa.2.0.insert.shift, %b.sroa.0.0.insert.ext
  %cmp = icmp eq i128 %a.sroa.0.0.insert.insert, 0
  %cmp3 = icmp eq i128 %b.sroa.0.0.insert.insert, 0
  %0 = or i1 %cmp, %cmp3
  %lor.ext = zext i1 %0 to i32
  ret i32 %lor.ext
}

; PR31902 Fix a crash in combineOrCmpEqZeroToCtlzSrl under fast math.
define i32 @test_zext_cmp11(double %a, double %b) "no-nans-fp-math"="true" {
;
; ALL-LABEL: test_zext_cmp11:
; ALL:       # %bb.0: # %entry
; ALL-NEXT:    vxorps %xmm2, %xmm2, %xmm2
; ALL-NEXT:    vucomisd %xmm2, %xmm0
; ALL-NEXT:    sete %al
; ALL-NEXT:    vucomisd %xmm2, %xmm1
; ALL-NEXT:    sete %cl
; ALL-NEXT:    orb %al, %cl
; ALL-NEXT:    movzbl %cl, %eax
; ALL-NEXT:    retq
entry:
  %cmp = fcmp fast oeq double %a, 0.000000e+00
  %cmp1 = fcmp fast oeq double %b, 0.000000e+00
  %0 = or i1 %cmp, %cmp1
  %conv = zext i1 %0 to i32
  ret i32 %conv
}