1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -mtriple=x86_64-unknown-unknown -mattr=+bmi < %s | FileCheck %s
3 ; RUN: opt -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -mtriple=x86_64-unknown-unknown -mattr=+lzcnt < %s | FileCheck %s
4 ; RUN: opt -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
7 define i64 @test1(i64 %A) {
10 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[A:%.*]], 0
11 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[A]], i1 true)
12 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i64 64, i64 [[TMP0]]
13 ; CHECK-NEXT: ret i64 [[SPEC_SELECT]]
16 %tobool = icmp eq i64 %A, 0
17 br i1 %tobool, label %cond.end, label %cond.true
19 cond.true: ; preds = %entry
20 %0 = tail call i64 @llvm.ctlz.i64(i64 %A, i1 true)
23 cond.end: ; preds = %entry, %cond.true
24 %cond = phi i64 [ %0, %cond.true ], [ 64, %entry ]
28 define i32 @test2(i32 %A) {
29 ; CHECK-LABEL: @test2(
31 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0
32 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[A]], i1 true)
33 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[TMP0]]
34 ; CHECK-NEXT: ret i32 [[SPEC_SELECT]]
37 %tobool = icmp eq i32 %A, 0
38 br i1 %tobool, label %cond.end, label %cond.true
40 cond.true: ; preds = %entry
41 %0 = tail call i32 @llvm.ctlz.i32(i32 %A, i1 true)
44 cond.end: ; preds = %entry, %cond.true
45 %cond = phi i32 [ %0, %cond.true ], [ 32, %entry ]
50 define signext i16 @test3(i16 signext %A) {
51 ; CHECK-LABEL: @test3(
53 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0
54 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i16 @llvm.ctlz.i16(i16 [[A]], i1 true)
55 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i16 16, i16 [[TMP0]]
56 ; CHECK-NEXT: ret i16 [[SPEC_SELECT]]
59 %tobool = icmp eq i16 %A, 0
60 br i1 %tobool, label %cond.end, label %cond.true
62 cond.true: ; preds = %entry
63 %0 = tail call i16 @llvm.ctlz.i16(i16 %A, i1 true)
66 cond.end: ; preds = %entry, %cond.true
67 %cond = phi i16 [ %0, %cond.true ], [ 16, %entry ]
72 define i64 @test1b(i64 %A) {
73 ; CHECK-LABEL: @test1b(
75 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[A:%.*]], 0
76 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[A]], i1 true)
77 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i64 64, i64 [[TMP0]]
78 ; CHECK-NEXT: ret i64 [[SPEC_SELECT]]
81 %tobool = icmp eq i64 %A, 0
82 br i1 %tobool, label %cond.end, label %cond.true
84 cond.true: ; preds = %entry
85 %0 = tail call i64 @llvm.cttz.i64(i64 %A, i1 true)
88 cond.end: ; preds = %entry, %cond.true
89 %cond = phi i64 [ %0, %cond.true ], [ 64, %entry ]
94 define i32 @test2b(i32 %A) {
95 ; CHECK-LABEL: @test2b(
97 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[A:%.*]], 0
98 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[A]], i1 true)
99 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i32 32, i32 [[TMP0]]
100 ; CHECK-NEXT: ret i32 [[SPEC_SELECT]]
103 %tobool = icmp eq i32 %A, 0
104 br i1 %tobool, label %cond.end, label %cond.true
106 cond.true: ; preds = %entry
107 %0 = tail call i32 @llvm.cttz.i32(i32 %A, i1 true)
110 cond.end: ; preds = %entry, %cond.true
111 %cond = phi i32 [ %0, %cond.true ], [ 32, %entry ]
116 define signext i16 @test3b(i16 signext %A) {
117 ; CHECK-LABEL: @test3b(
119 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i16 [[A:%.*]], 0
120 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i16 @llvm.cttz.i16(i16 [[A]], i1 true)
121 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL]], i16 16, i16 [[TMP0]]
122 ; CHECK-NEXT: ret i16 [[SPEC_SELECT]]
125 %tobool = icmp eq i16 %A, 0
126 br i1 %tobool, label %cond.end, label %cond.true
128 cond.true: ; preds = %entry
129 %0 = tail call i16 @llvm.cttz.i16(i16 %A, i1 true)
132 cond.end: ; preds = %entry, %cond.true
133 %cond = phi i16 [ %0, %cond.true ], [ 16, %entry ]
137 ; The following tests verify that calls to cttz/ctlz are speculated even if
138 ; basic block %cond.true has an extra zero extend/truncate which is "free"
141 define i64 @test1e(i32 %x) {
142 ; CHECK-LABEL: @test1e(
144 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0
145 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true)
146 ; CHECK-NEXT: [[PHITMP2:%.*]] = zext i32 [[TMP0]] to i64
147 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i64 32, i64 [[PHITMP2]]
148 ; CHECK-NEXT: ret i64 [[COND]]
151 %tobool = icmp eq i32 %x, 0
152 br i1 %tobool, label %cond.end, label %cond.true
154 cond.true: ; preds = %entry
155 %0 = tail call i32 @llvm.cttz.i32(i32 %x, i1 true)
156 %phitmp2 = zext i32 %0 to i64
159 cond.end: ; preds = %entry, %cond.true
160 %cond = phi i64 [ %phitmp2, %cond.true ], [ 32, %entry ]
164 define i32 @test2e(i64 %x) {
165 ; CHECK-LABEL: @test2e(
167 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0
168 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X]], i1 true)
169 ; CHECK-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i32
170 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 64, i32 [[CAST]]
171 ; CHECK-NEXT: ret i32 [[COND]]
174 %tobool = icmp eq i64 %x, 0
175 br i1 %tobool, label %cond.end, label %cond.true
177 cond.true: ; preds = %entry
178 %0 = tail call i64 @llvm.cttz.i64(i64 %x, i1 true)
179 %cast = trunc i64 %0 to i32
182 cond.end: ; preds = %entry, %cond.true
183 %cond = phi i32 [ %cast, %cond.true ], [ 64, %entry ]
187 define i64 @test3e(i32 %x) {
188 ; CHECK-LABEL: @test3e(
190 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0
191 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X]], i1 true)
192 ; CHECK-NEXT: [[PHITMP2:%.*]] = zext i32 [[TMP0]] to i64
193 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i64 32, i64 [[PHITMP2]]
194 ; CHECK-NEXT: ret i64 [[COND]]
197 %tobool = icmp eq i32 %x, 0
198 br i1 %tobool, label %cond.end, label %cond.true
200 cond.true: ; preds = %entry
201 %0 = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true)
202 %phitmp2 = zext i32 %0 to i64
205 cond.end: ; preds = %entry, %cond.true
206 %cond = phi i64 [ %phitmp2, %cond.true ], [ 32, %entry ]
210 define i32 @test4e(i64 %x) {
211 ; CHECK-LABEL: @test4e(
213 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0
214 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[X]], i1 true)
215 ; CHECK-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i32
216 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i32 64, i32 [[CAST]]
217 ; CHECK-NEXT: ret i32 [[COND]]
220 %tobool = icmp eq i64 %x, 0
221 br i1 %tobool, label %cond.end, label %cond.true
223 cond.true: ; preds = %entry
224 %0 = tail call i64 @llvm.ctlz.i64(i64 %x, i1 true)
225 %cast = trunc i64 %0 to i32
228 cond.end: ; preds = %entry, %cond.true
229 %cond = phi i32 [ %cast, %cond.true ], [ 64, %entry ]
233 define i16 @test5e(i64 %x) {
234 ; CHECK-LABEL: @test5e(
236 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0
237 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.ctlz.i64(i64 [[X]], i1 true)
238 ; CHECK-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i16
239 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 64, i16 [[CAST]]
240 ; CHECK-NEXT: ret i16 [[COND]]
243 %tobool = icmp eq i64 %x, 0
244 br i1 %tobool, label %cond.end, label %cond.true
246 cond.true: ; preds = %entry
247 %0 = tail call i64 @llvm.ctlz.i64(i64 %x, i1 true)
248 %cast = trunc i64 %0 to i16
251 cond.end: ; preds = %entry, %cond.true
252 %cond = phi i16 [ %cast, %cond.true ], [ 64, %entry ]
256 define i16 @test6e(i32 %x) {
257 ; CHECK-LABEL: @test6e(
259 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0
260 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X]], i1 true)
261 ; CHECK-NEXT: [[CAST:%.*]] = trunc i32 [[TMP0]] to i16
262 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 32, i16 [[CAST]]
263 ; CHECK-NEXT: ret i16 [[COND]]
266 %tobool = icmp eq i32 %x, 0
267 br i1 %tobool, label %cond.end, label %cond.true
269 cond.true: ; preds = %entry
270 %0 = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true)
271 %cast = trunc i32 %0 to i16
274 cond.end: ; preds = %entry, %cond.true
275 %cond = phi i16 [ %cast, %cond.true ], [ 32, %entry ]
279 define i16 @test7e(i64 %x) {
280 ; CHECK-LABEL: @test7e(
282 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i64 [[X:%.*]], 0
283 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X]], i1 true)
284 ; CHECK-NEXT: [[CAST:%.*]] = trunc i64 [[TMP0]] to i16
285 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 64, i16 [[CAST]]
286 ; CHECK-NEXT: ret i16 [[COND]]
289 %tobool = icmp eq i64 %x, 0
290 br i1 %tobool, label %cond.end, label %cond.true
292 cond.true: ; preds = %entry
293 %0 = tail call i64 @llvm.cttz.i64(i64 %x, i1 true)
294 %cast = trunc i64 %0 to i16
297 cond.end: ; preds = %entry, %cond.true
298 %cond = phi i16 [ %cast, %cond.true ], [ 64, %entry ]
302 define i16 @test8e(i32 %x) {
303 ; CHECK-LABEL: @test8e(
305 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[X:%.*]], 0
306 ; CHECK-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.cttz.i32(i32 [[X]], i1 true)
307 ; CHECK-NEXT: [[CAST:%.*]] = trunc i32 [[TMP0]] to i16
308 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[TOBOOL]], i16 32, i16 [[CAST]]
309 ; CHECK-NEXT: ret i16 [[COND]]
312 %tobool = icmp eq i32 %x, 0
313 br i1 %tobool, label %cond.end, label %cond.true
315 cond.true: ; preds = %entry
316 %0 = tail call i32 @llvm.cttz.i32(i32 %x, i1 true)
317 %cast = trunc i32 %0 to i16
320 cond.end: ; preds = %entry, %cond.true
321 %cond = phi i16 [ %cast, %cond.true ], [ 32, %entry ]
326 declare i64 @llvm.ctlz.i64(i64, i1)
327 declare i32 @llvm.ctlz.i32(i32, i1)
328 declare i16 @llvm.ctlz.i16(i16, i1)
329 declare i64 @llvm.cttz.i64(i64, i1)
330 declare i32 @llvm.cttz.i32(i32, i1)
331 declare i16 @llvm.cttz.i16(i16, i1)