Davide Italiano | 85ad36b | 2016-12-15 23:45:11 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -instcombine -S | FileCheck %s |
| 2 | |
| 3 | target triple = "x86_64-unknown-freebsd11.0" |
| 4 | |
| 5 | |
| 6 | ; CHECK-LABEL: define i32 @myfls( |
| 7 | ; CHECK: ret i32 6 |
| 8 | ; CHECK: } |
| 9 | |
| 10 | define i32 @myfls() { |
| 11 | entry: |
| 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 | |
| 20 | define 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 | |
| 29 | define 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 | |
| 41 | define i32 @flsnotconst(i64 %z) { |
| 42 | %goo = call i32 @flsl(i64 %z) |
| 43 | ret i32 %goo |
| 44 | } |
| 45 | |
| 46 | declare i32 @fls(i32) |
| 47 | declare i32 @flsl(i64) |
| 48 | declare i32 @flsll(i64) |