1; RUN: opt < %s -instcombine -S | FileCheck %s
2
3target triple = "x86_64-unknown-freebsd11.0"
4
5
6; CHECK-LABEL: define i32 @myfls(
7; CHECK: ret i32 6
8; CHECK: }
9
10define i32 @myfls() {
11entry:
12  %call = call i32 @fls(i32 42)
13  ret i32 %call
14}
15
16; CHECK-LABEL: define i32 @myflsl(
17; CHECK: ret i32 6
18; CHECK: }
19
20define i32 @myflsl() {
21  %patatino = call i32 @flsl(i64 42)
22  ret i32 %patatino
23}
24
25; CHECK-LABEL: define i32 @myflsll(
26; CHECK: ret i32 6
27; CHECK: }
28
29define i32 @myflsll() {
30  %whatever = call i32 @flsll(i64 42)
31  ret i32 %whatever
32}
33
34; Lower to llvm.ctlz() if the argument is not a constant
35; CHECK-LABEL: define i32 @flsnotconst(
36; CHECK-NEXT:  %ctlz = call i64 @llvm.ctlz.i64(i64 %z, i1 false)
37; CHECK-NEXT:  %1 = sub nsw i64 64, %ctlz
38; CHECK-NEXT:  %2 = trunc i64 %1 to i32
39; CHECK-NEXT:  ret i32 %2
40
41define i32 @flsnotconst(i64 %z) {
42  %goo = call i32 @flsl(i64 %z)
43  ret i32 %goo
44}
45
46; Make sure we lower fls(0) to 0 and not to `undef`.
47; CHECK-LABEL: define i32 @flszero(
48; CHECK: ret i32 0
49; CHECK: }
50define i32 @flszero() {
51  %zero = call i32 @fls(i32 0)
52  ret i32 %zero
53}
54
55declare i32 @fls(i32)
56declare i32 @flsl(i64)
57declare i32 @flsll(i64)
58