[llvm] [ArgPromotion] Handle pointer arguments of recursive calls (PR #78735)

Vedant Paranjape via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 02:24:12 PDT 2024


================
@@ -610,6 +639,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) {
----------------
vedantparanjape-amd wrote:

 I get your point that strips are anyways not there in opaque ptrs, but how to collect offsets ? I couldn't find a function which will accumulate constant offsets on a Value! Please take a look at testcase recursion-non-zero.ll submitted with this PR. We are trying to check if a ptr is being offset at some non-zero offset.

https://github.com/llvm/llvm-project/pull/78735


More information about the llvm-commits mailing list