[llvm] [InstCombine] Canonicalize more geps with constant gep bases and constant offsets. (PR #110033)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 12:59:09 PDT 2024
================
@@ -2822,11 +2822,17 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// This has better support in BasicAA.
// - gep i32 p, mul(O, C) -> gep i8, p, mul(O, C*4) to fold the two
// multiplies together.
- if (GEPEltType->isScalableTy() ||
- (!GEPEltType->isIntegerTy(8) && GEP.getNumIndices() == 1 &&
- match(GEP.getOperand(1),
- m_OneUse(m_CombineOr(m_Mul(m_Value(), m_ConstantInt()),
- m_Shl(m_Value(), m_ConstantInt())))))) {
+ // - gep (gep @global, C1), %x, C2 is expanded so the two constants can
+ // possibly be merged together.
+ if (!GEPEltType->isIntegerTy(8) &&
+ (GEPEltType->isScalableTy() ||
+ (GEP.getNumIndices() == 1 &&
+ match(GEP.getOperand(1),
+ m_OneUse(m_CombineOr(m_Mul(m_Value(), m_ConstantInt()),
+ m_Shl(m_Value(), m_ConstantInt()))))) ||
+ (isa<GEPOperator>(PtrOp) && isa<ConstantExpr>(PtrOp) &&
+ any_of(drop_begin(GEP.indices()),
+ [](Value *V) { return isa<Constant>(V); })))) {
----------------
nikic wrote:
I think this condition has reached the point where it wants to live in its own function :)
I'm also wondering whether zero constants should be excluded from this heuristic, as they don't add any actual offset. And then you wouldn't need the drop_begin? Or at least I don't fully get why the drop_begin() is there.
https://github.com/llvm/llvm-project/pull/110033
More information about the llvm-commits
mailing list