aboutsummaryrefslogtreecommitdiff
path: root/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
commita801172e504b45b2266486ec68adb64f7fcf8e17 (patch)
tree8f13940aaf1de57985cc4e0036d45da160a6c9d0 /lib/CodeGen/IntrinsicLowering.cpp
parent86f3e0c24e8834e6ad5ac61f2459fb335549bc24 (diff)
Fix lowering of cttz to work with signed values
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21874 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/IntrinsicLowering.cpp')
-rw-r--r--lib/CodeGen/IntrinsicLowering.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp
index 1817ade1cd..634f959f3c 100644
--- a/lib/CodeGen/IntrinsicLowering.cpp
+++ b/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;
}