aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-06-18 16:39:32 +0200
committerNikita Popov <npopov@redhat.com>2024-06-18 16:39:32 +0200
commite64ed1db46967fe9963751873b5d0098b57c9316 (patch)
tree7026ee80407dcdaa165a55784e47af819cd608b2
parentd314cf241d61410fa4bd925c1c4355e87209da17 (diff)
downloadllvm-e64ed1db46967fe9963751873b5d0098b57c9316.zip
llvm-e64ed1db46967fe9963751873b5d0098b57c9316.tar.gz
llvm-e64ed1db46967fe9963751873b5d0098b57c9316.tar.bz2
[InstCombine] Avoid use of ConstantExpr::getShl()
Either use IRBuilder or the constant folding API instead. For the IRBuilder uses, also switch to ImmConstant to make sure that folding will succeed.
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index d451eb9..06b4348 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -257,8 +257,11 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift,
// And compute the mask as usual: ~(-1 << (SumOfShAmts))
auto *ExtendedAllOnes = ConstantExpr::getAllOnesValue(ExtendedTy);
- auto *ExtendedInvertedMask =
- ConstantExpr::getShl(ExtendedAllOnes, ExtendedSumOfShAmts);
+ Constant *ExtendedInvertedMask = ConstantFoldBinaryOpOperands(
+ Instruction::Shl, ExtendedAllOnes, ExtendedSumOfShAmts, Q.DL);
+ if (!ExtendedInvertedMask)
+ return nullptr;
+
NewMask = ConstantExpr::getNot(ExtendedInvertedMask);
} else if (match(Masked, m_c_And(m_CombineOr(MaskC, MaskD), m_Value(X))) ||
match(Masked, m_Shr(m_Shl(m_Value(X), m_Value(MaskShAmt)),
@@ -1218,16 +1221,16 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
}
Constant *C1;
- if (match(Op1, m_Constant(C1))) {
+ if (match(Op1, m_ImmConstant(C1))) {
Constant *C2;
Value *X;
// (X * C2) << C1 --> X * (C2 << C1)
- if (match(Op0, m_Mul(m_Value(X), m_Constant(C2))))
- return BinaryOperator::CreateMul(X, ConstantExpr::getShl(C2, C1));
+ if (match(Op0, m_Mul(m_Value(X), m_ImmConstant(C2))))
+ return BinaryOperator::CreateMul(X, Builder.CreateShl(C2, C1));
// shl (zext i1 X), C1 --> select (X, 1 << C1, 0)
if (match(Op0, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) {
- auto *NewC = ConstantExpr::getShl(ConstantInt::get(Ty, 1), C1);
+ auto *NewC = Builder.CreateShl(ConstantInt::get(Ty, 1), C1);
return SelectInst::Create(X, NewC, ConstantInt::getNullValue(Ty));
}
}