aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-06-18 16:32:49 +0200
committerNikita Popov <npopov@redhat.com>2024-06-18 16:32:49 +0200
commitd314cf241d61410fa4bd925c1c4355e87209da17 (patch)
tree62b24b86779396caae6b75c0cd8f17f6039958e9
parent76e889d3b024c187880187b1a14fe9ab0ea7aa36 (diff)
downloadllvm-d314cf241d61410fa4bd925c1c4355e87209da17.zip
llvm-d314cf241d61410fa4bd925c1c4355e87209da17.tar.gz
llvm-d314cf241d61410fa4bd925c1c4355e87209da17.tar.bz2
[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.
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
index ed2a98b..b342656 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
@@ -391,12 +391,12 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) {
return Builder.CreateShl(NegOp0, I->getOperand(1), I->getName() + ".neg",
/* HasNUW */ false, IsNSW);
// Otherwise, `shl %x, C` can be interpreted as `mul %x, 1<<C`.
- auto *Op1C = dyn_cast<Constant>(I->getOperand(1));
- if (!Op1C || !IsTrulyNegation)
+ Constant *Op1C;
+ if (!match(I->getOperand(1), m_ImmConstant(Op1C)) || !IsTrulyNegation)
return nullptr;
return Builder.CreateMul(
I->getOperand(0),
- ConstantExpr::getShl(Constant::getAllOnesValue(Op1C->getType()), Op1C),
+ Builder.CreateShl(Constant::getAllOnesValue(Op1C->getType()), Op1C),
I->getName() + ".neg", /* HasNUW */ false, IsNSW);
}
case Instruction::Or: {