Skip to content

Commit d314cf2

Browse files
committed
[InstCombine] Avoid use of ConstantExpr::getShl()
Use IRBuilder instead, as we don't care about the return type here. Use ImmConstant to ensure that constant folding will succeed.
1 parent 76e889d commit d314cf2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,12 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) {
391391
return Builder.CreateShl(NegOp0, I->getOperand(1), I->getName() + ".neg",
392392
/* HasNUW */ false, IsNSW);
393393
// Otherwise, `shl %x, C` can be interpreted as `mul %x, 1<<C`.
394-
auto *Op1C = dyn_cast<Constant>(I->getOperand(1));
395-
if (!Op1C || !IsTrulyNegation)
394+
Constant *Op1C;
395+
if (!match(I->getOperand(1), m_ImmConstant(Op1C)) || !IsTrulyNegation)
396396
return nullptr;
397397
return Builder.CreateMul(
398398
I->getOperand(0),
399-
ConstantExpr::getShl(Constant::getAllOnesValue(Op1C->getType()), Op1C),
399+
Builder.CreateShl(Constant::getAllOnesValue(Op1C->getType()), Op1C),
400400
I->getName() + ".neg", /* HasNUW */ false, IsNSW);
401401
}
402402
case Instruction::Or: {

0 commit comments

Comments
 (0)