1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[InstCombine] move bitmanipulation-of-select folds

This is no outwardly-visible-difference-intended,
but it is obviously better to have all transforms
for an intrinsic housed together since we already
have helper functions in place.

It is also potentially more efficient to zap a
simple pattern match before trying to do expensive
computeKnownBits() calls.
This commit is contained in:
Sanjay Patel 2021-06-21 11:27:52 -04:00
parent 844287b90f
commit d8dba3ce64

View File

@ -454,6 +454,11 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) {
return IC.replaceInstUsesWith(II, ConstantInt::getNullValue(II.getType()));
}
// If the operand is a select with constant arm(s), try to hoist ctlz/cttz.
if (auto *Sel = dyn_cast<SelectInst>(Op0))
if (Instruction *R = IC.FoldOpIntoSelect(II, Sel))
return R;
if (IsTZ) {
// cttz(-x) -> cttz(x)
if (match(Op0, m_Neg(m_Value(X))))
@ -573,6 +578,11 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {
return CastInst::Create(Instruction::ZExt, NarrowPop, Ty);
}
// If the operand is a select with constant arm(s), try to hoist ctpop.
if (auto *Sel = dyn_cast<SelectInst>(Op0))
if (Instruction *R = IC.FoldOpIntoSelect(II, Sel))
return R;
KnownBits Known(BitWidth);
IC.computeKnownBits(Op0, Known, 0, &II);
@ -1080,21 +1090,11 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
case Intrinsic::ctlz:
if (auto *I = foldCttzCtlz(*II, *this))
return I;
// If the operand is a select with constant arm(s), try to hoist ctlz/cttz.
if (auto *Sel = dyn_cast<SelectInst>(II->getArgOperand(0)))
if (Instruction *R = FoldOpIntoSelect(*II, Sel))
return R;
break;
case Intrinsic::ctpop:
if (auto *I = foldCtpop(*II, *this))
return I;
// If the operand is a select with constant arm(s), try to hoist ctpop.
if (auto *Sel = dyn_cast<SelectInst>(II->getArgOperand(0)))
if (Instruction *R = FoldOpIntoSelect(*II, Sel))
return R;
break;
case Intrinsic::fshl: