Skip to content

Commit 198b79c

Browse files
committed
[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.
1 parent 2251f33 commit 198b79c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,11 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) {
454454
return IC.replaceInstUsesWith(II, ConstantInt::getNullValue(II.getType()));
455455
}
456456

457+
// If the operand is a select with constant arm(s), try to hoist ctlz/cttz.
458+
if (auto *Sel = dyn_cast<SelectInst>(Op0))
459+
if (Instruction *R = IC.FoldOpIntoSelect(II, Sel))
460+
return R;
461+
457462
if (IsTZ) {
458463
// cttz(-x) -> cttz(x)
459464
if (match(Op0, m_Neg(m_Value(X))))
@@ -573,6 +578,11 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {
573578
return CastInst::Create(Instruction::ZExt, NarrowPop, Ty);
574579
}
575580

581+
// If the operand is a select with constant arm(s), try to hoist ctpop.
582+
if (auto *Sel = dyn_cast<SelectInst>(Op0))
583+
if (Instruction *R = IC.FoldOpIntoSelect(II, Sel))
584+
return R;
585+
576586
KnownBits Known(BitWidth);
577587
IC.computeKnownBits(Op0, Known, 0, &II);
578588

@@ -1080,21 +1090,11 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
10801090
case Intrinsic::ctlz:
10811091
if (auto *I = foldCttzCtlz(*II, *this))
10821092
return I;
1083-
1084-
// If the operand is a select with constant arm(s), try to hoist ctlz/cttz.
1085-
if (auto *Sel = dyn_cast<SelectInst>(II->getArgOperand(0)))
1086-
if (Instruction *R = FoldOpIntoSelect(*II, Sel))
1087-
return R;
10881093
break;
10891094

10901095
case Intrinsic::ctpop:
10911096
if (auto *I = foldCtpop(*II, *this))
10921097
return I;
1093-
1094-
// If the operand is a select with constant arm(s), try to hoist ctpop.
1095-
if (auto *Sel = dyn_cast<SelectInst>(II->getArgOperand(0)))
1096-
if (Instruction *R = FoldOpIntoSelect(*II, Sel))
1097-
return R;
10981098
break;
10991099

11001100
case Intrinsic::fshl:

0 commit comments

Comments
 (0)