[llvm] [ArgPromotion] Handle pointer arguments of recursive calls (PR #78735)
Vedant Paranjape via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 05:50:47 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:
@nikic the function https://github.com/llvm/llvm-project/blob/e4163c0927772f2ec73cf16d53e000614c419c45/llvm/lib/IR/Value.cpp#L731 pretty much runs a do-while loop and traverses the GEP tree to accumulate the offsets. If it encounters a bitcast (which it won't), it doesn't do much. So, I would want to ideally pull out just the traversal code out from the function, skipping the bitcasts code. But I think that can another patch, is it blocking this one ?
https://github.com/llvm/llvm-project/pull/78735
More information about the llvm-commits
mailing list