Fix lowering of cttz to work with signed values
llvm-svn: 21874
This commit is contained in:
parent
9ec975a4b5
commit
fe5759b022
|
@ -251,13 +251,12 @@ void DefaultIntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Intrinsic::cttz: {
|
case Intrinsic::cttz: {
|
||||||
|
// cttz(x) -> ctpop(~X & (X-1))
|
||||||
Value *Src = CI->getOperand(1);
|
Value *Src = CI->getOperand(1);
|
||||||
Value *NotSrc = BinaryOperator::createNot(Src, Src->getName()+".not", CI);
|
Value *NotSrc = BinaryOperator::createNot(Src, Src->getName()+".not", CI);
|
||||||
Src = BinaryOperator::createAnd(NotSrc,
|
Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
|
||||||
BinaryOperator::createSub(Src,
|
SrcM1 = BinaryOperator::createSub(Src, SrcM1, "", CI);
|
||||||
ConstantUInt::get(CI->getOperand(0)->getType(), 1), "", CI));
|
Src = LowerCTPOP(BinaryOperator::createAnd(NotSrc, SrcM1, "", CI), CI);
|
||||||
|
|
||||||
Src = LowerCTPOP(Src, CI);
|
|
||||||
CI->replaceAllUsesWith(Src);
|
CI->replaceAllUsesWith(Src);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue