diff options
author | Nikita Popov <npopov@redhat.com> | 2025-06-13 12:29:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-13 12:29:50 +0200 |
commit | 6fc8ec720ea590bbdb94e19acefaf5bafdfcf817 (patch) | |
tree | d0cdb91a89ae040a820c77d408573af7e0f0261d /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
parent | e2c27fd66a13c7a37cccbf4309532fcbce86c09b (diff) | |
download | llvm-6fc8ec720ea590bbdb94e19acefaf5bafdfcf817.zip llvm-6fc8ec720ea590bbdb94e19acefaf5bafdfcf817.tar.gz llvm-6fc8ec720ea590bbdb94e19acefaf5bafdfcf817.tar.bz2 |
[InstCombine] Restore splat gep support in OptimizePointerDifference() (#143906)
When looking for the common base pointer, support the case where the
type changes because the GEP goes from pointer to vector of pointers.
This was supported prior to #142958.
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 86d3189..0d91e7d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -2088,8 +2088,6 @@ CommonPointerBase CommonPointerBase::compute(Value *LHS, Value *RHS) { // Find common base and collect RHS GEPs. while (true) { if (Ptrs.contains(RHS)) { - if (LHS->getType() != RHS->getType()) - return Base; Base.Ptr = RHS; break; } @@ -2132,12 +2130,15 @@ Value *InstCombinerImpl::OptimizePointerDifference(Value *LHS, Value *RHS, // TODO: We should probably do this even if there is only one GEP. bool RewriteGEPs = !Base.LHSGEPs.empty() && !Base.RHSGEPs.empty(); - Type *IdxTy = DL.getIndexType(Base.Ptr->getType()); + Type *IdxTy = DL.getIndexType(LHS->getType()); auto EmitOffsetFromBase = [&](ArrayRef<GEPOperator *> GEPs, GEPNoWrapFlags NW) -> Value * { Value *Sum = nullptr; for (GEPOperator *GEP : reverse(GEPs)) { Value *Offset = EmitGEPOffset(GEP, RewriteGEPs); + if (Offset->getType() != IdxTy) + Offset = Builder.CreateVectorSplat( + cast<VectorType>(IdxTy)->getElementCount(), Offset); if (Sum) Sum = Builder.CreateAdd(Sum, Offset, "", NW.hasNoUnsignedWrap(), NW.isInBounds()); |