[llvm] [ArgPromotion] Handle pointer arguments of recursive calls (PR #78735)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 05:59:41 PDT 2024
================
@@ -610,6 +638,45 @@ static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR,
// unknown users
}
+ auto *CB = dyn_cast<CallBase>(V);
+ Value *PtrArg = cast<Value>(U);
+ if (CB && PtrArg && CB->getCalledFunction() == CB->getFunction()) {
+ Type *PtrTy = PtrArg->getType();
+ APInt Offset(DL.getIndexTypeSizeInBits(PtrTy), 0);
+ PtrArg = PtrArg->stripAndAccumulateConstantOffsets(
+ DL, Offset,
+ /* AllowNonInbounds= */ true);
+ if (PtrArg != Arg)
+ return false;
+
+ if (Offset.getSignificantBits() >= 64)
+ return false;
+
+ int64_t Off = Offset.getSExtValue();
+ if (Off) {
+ LLVM_DEBUG(dbgs() << "ArgPromotion of " << *Arg << " failed: "
+ << "pointer offset is not equal to zero\n");
+ return false;
+ }
----------------
nikic wrote:
Let me spell this out explicitly. Here is the change you should do:
```suggestion
if (PtrArg != Arg)
return false;
```
https://github.com/llvm/llvm-project/pull/78735
More information about the llvm-commits
mailing list