1 ; RUN: opt -S -codegenprepare < %s | FileCheck %s --check-prefix=SLOW
2 ; RUN: opt -S -codegenprepare -mattr=+bmi < %s | FileCheck %s --check-prefix=FAST_TZ
3 ; RUN: opt -S -codegenprepare -mattr=+lzcnt < %s | FileCheck %s --check-prefix=FAST_LZ
5 target triple = "x86_64-unknown-unknown"
6 target datalayout = "e-n32:64"
8 ; If the intrinsic is cheap, nothing should change.
9 ; If the intrinsic is expensive, check if the input is zero to avoid the call.
10 ; This is undoing speculation that may have been created by SimplifyCFG + InstCombine.
12 define i64 @cttz(i64 %A) {
14 %z = call i64 @llvm.cttz.i64(i64 %A, i1 false)
19 ; SLOW: %cmpz = icmp eq i64 %A, 0
20 ; SLOW: br i1 %cmpz, label %cond.end, label %cond.false
22 ; SLOW: %z = call i64 @llvm.cttz.i64(i64 %A, i1 true)
23 ; SLOW: br label %cond.end
25 ; SLOW: %ctz = phi i64 [ 64, %entry ], [ %z, %cond.false ]
28 ; FAST_TZ-LABEL: @cttz(
29 ; FAST_TZ: %z = call i64 @llvm.cttz.i64(i64 %A, i1 false)
33 define i64 @ctlz(i64 %A) {
35 %z = call i64 @llvm.ctlz.i64(i64 %A, i1 false)
40 ; SLOW: %cmpz = icmp eq i64 %A, 0
41 ; SLOW: br i1 %cmpz, label %cond.end, label %cond.false
43 ; SLOW: %z = call i64 @llvm.ctlz.i64(i64 %A, i1 true)
44 ; SLOW: br label %cond.end
46 ; SLOW: %ctz = phi i64 [ 64, %entry ], [ %z, %cond.false ]
49 ; FAST_LZ-LABEL: @ctlz(
50 ; FAST_LZ: %z = call i64 @llvm.ctlz.i64(i64 %A, i1 false)
54 declare i64 @llvm.cttz.i64(i64, i1)
55 declare i64 @llvm.ctlz.i64(i64, i1)