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