diff options
author | Nikita Popov <npopov@redhat.com> | 2024-06-18 16:29:40 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2024-06-18 16:29:40 +0200 |
commit | 76e889d3b024c187880187b1a14fe9ab0ea7aa36 (patch) | |
tree | 89dba08279bce2261a9880e16e1f0c48c6f683bc | |
parent | 440af98a04402929b8c644b983add05cf420b5f8 (diff) | |
download | llvm-76e889d3b024c187880187b1a14fe9ab0ea7aa36.zip llvm-76e889d3b024c187880187b1a14fe9ab0ea7aa36.tar.gz llvm-76e889d3b024c187880187b1a14fe9ab0ea7aa36.tar.bz2 |
[InstCombine] Avoid use of ConstantExpr::getShl()
Use the constant folding API instead (we later call isNotMinSignedValue
on it, so we do need the Constant* return type here). Use ImmConstant
to guarantee that constant folding succeeds.
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index ca1b192..8fcb354 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -223,11 +223,13 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) { Value *NewOp; Constant *C1, *C2; const APInt *IVal; - if (match(&I, m_Mul(m_Shl(m_Value(NewOp), m_Constant(C2)), - m_Constant(C1))) && + if (match(&I, m_Mul(m_Shl(m_Value(NewOp), m_ImmConstant(C2)), + m_ImmConstant(C1))) && match(C1, m_APInt(IVal))) { // ((X << C2)*C1) == (X * (C1 << C2)) - Constant *Shl = ConstantExpr::getShl(C1, C2); + Constant *Shl = + ConstantFoldBinaryOpOperands(Instruction::Shl, C1, C2, DL); + assert(Shl && "Constant folding of immediate constants failed"); BinaryOperator *Mul = cast<BinaryOperator>(I.getOperand(0)); BinaryOperator *BO = BinaryOperator::CreateMul(NewOp, Shl); if (HasNUW && Mul->hasNoUnsignedWrap()) |