summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/IntrinsicLowering.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-05-11 20:02:14 +0000
committerChris Lattner <sabre@nondot.org>2005-05-11 20:02:14 +0000
commitfe5759b0220d40637ece3df293a38039758febab (patch)
treebc21db2a591ec63ea75606aa2e2cfc97333856c8 /llvm/lib/CodeGen/IntrinsicLowering.cpp
parent9ec975a4b57895cb7b2334607403f9766a742855 (diff)
downloadbcm5719-llvm-fe5759b0220d40637ece3df293a38039758febab.tar.gz
bcm5719-llvm-fe5759b0220d40637ece3df293a38039758febab.zip
Fix lowering of cttz to work with signed values
llvm-svn: 21874
Diffstat (limited to 'llvm/lib/CodeGen/IntrinsicLowering.cpp')
-rw-r--r--llvm/lib/CodeGen/IntrinsicLowering.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/IntrinsicLowering.cpp b/llvm/lib/CodeGen/IntrinsicLowering.cpp
index 1817ade1cdb..634f959f3c4 100644
--- a/llvm/lib/CodeGen/IntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/IntrinsicLowering.cpp
@@ -251,13 +251,12 @@ void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
break;
}
case Intrinsic::cttz: {
+ // cttz(x) -> ctpop(~X & (X-1))
Value *Src = CI->getOperand(1);
Value *NotSrc = BinaryOperator::createNot(Src, Src->getName()+".not", CI);
- Src = BinaryOperator::createAnd(NotSrc,
- BinaryOperator::createSub(Src,
- ConstantUInt::get(CI->getOperand(0)->getType(), 1), "", CI));
-
- Src = LowerCTPOP(Src, CI);
+ Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
+ SrcM1 = BinaryOperator::createSub(Src, SrcM1, "", CI);
+ Src = LowerCTPOP(BinaryOperator::createAnd(NotSrc, SrcM1, "", CI), CI);
CI->replaceAllUsesWith(Src);
break;
}
OpenPOWER on IntegriCloud