SimplifyLibcalls: The return value of ffsll is always i32, even when the input is zero.
Fixes PR13028. llvm-svn: 166313
This commit is contained in:
parent
14e0bb54a5
commit
317d6c621d
|
@ -772,8 +772,8 @@ struct FFSOpt : public LibCallOptimization {
|
||||||
|
|
||||||
// Constant fold.
|
// Constant fold.
|
||||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
|
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
|
||||||
if (CI->getValue() == 0) // ffs(0) -> 0.
|
if (CI->isZero()) // ffs(0) -> 0.
|
||||||
return Constant::getNullValue(CI->getType());
|
return B.getInt32(0);
|
||||||
// ffs(c) -> cttz(c)+1
|
// ffs(c) -> cttz(c)+1
|
||||||
return B.getInt32(CI->getValue().countTrailingZeros() + 1);
|
return B.getInt32(CI->getValue().countTrailingZeros() + 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
; Test that the ToAsciiOptimizer works correctly
|
; Test that FFSOpt works correctly
|
||||||
; RUN: opt < %s -simplify-libcalls -S | \
|
; RUN: opt < %s -simplify-libcalls -S | FileCheck %s
|
||||||
; RUN: not grep "call.*@ffs"
|
|
||||||
|
; CHECK-NOT: call{{.*}}@ffs
|
||||||
|
|
||||||
@non_const = external global i32 ; <i32*> [#uses=1]
|
@non_const = external global i32 ; <i32*> [#uses=1]
|
||||||
|
|
||||||
|
@ -34,3 +35,11 @@ define i32 @a(i64) nounwind {
|
||||||
%2 = call i32 @ffsll(i64 %0) ; <i32> [#uses=1]
|
%2 = call i32 @ffsll(i64 %0) ; <i32> [#uses=1]
|
||||||
ret i32 %2
|
ret i32 %2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; PR13028
|
||||||
|
define i32 @b() nounwind {
|
||||||
|
%ffs = call i32 @ffsll(i64 0)
|
||||||
|
ret i32 %ffs
|
||||||
|
; CHECK: @b
|
||||||
|
; CHECK-NEXT: ret i32 0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue