diff options
author | Davide Italiano <davide@freebsd.org> | 2016-12-15 23:11:00 +0000 |
---|---|---|
committer | Davide Italiano <davide@freebsd.org> | 2016-12-15 23:11:00 +0000 |
commit | 890e8503483c8f1755ad9ad71b1b22d803782186 (patch) | |
tree | fbb858fbd89f85d11eabad69f186ad789c7cf3cb | |
parent | 136e9f466ec506c12ded1761a7dd4c785889cae3 (diff) | |
download | bcm5719-llvm-890e8503483c8f1755ad9ad71b1b22d803782186.tar.gz bcm5719-llvm-890e8503483c8f1755ad9ad71b1b22d803782186.zip |
[SimplifyLibCalls] Remove redundant folding logic for ffs().
Lowering to llvm.cttz() will result in constant folding anyway
if the argument to ffs is a constant. Pointed out by Eli for
fls() in D14590.
llvm-svn: 289888
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 39e109c9e1c..d3eae6e3d87 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1521,21 +1521,11 @@ void LibCallSimplifier::replaceTrigInsts(SmallVectorImpl<CallInst *> &Calls, //===----------------------------------------------------------------------===// Value *LibCallSimplifier::optimizeFFS(CallInst *CI, IRBuilder<> &B) { - Function *Callee = CI->getCalledFunction(); - Value *Op = CI->getArgOperand(0); - - // Constant fold. - if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) { - if (CI->isZero()) // ffs(0) -> 0. - return B.getInt32(0); - // ffs(c) -> cttz(c)+1 - return B.getInt32(CI->getValue().countTrailingZeros() + 1); - } - // ffs(x) -> x != 0 ? (i32)llvm.cttz(x)+1 : 0 + Value *Op = CI->getArgOperand(0); Type *ArgType = Op->getType(); - Value *F = - Intrinsic::getDeclaration(Callee->getParent(), Intrinsic::cttz, ArgType); + Value *F = Intrinsic::getDeclaration(CI->getCalledFunction()->getParent(), + Intrinsic::cttz, ArgType); Value *V = B.CreateCall(F, {Op, B.getTrue()}, "cttz"); V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1)); V = B.CreateIntCast(V, B.getInt32Ty(), false); |