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

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 12 10:23:24 PDT 2024


================
@@ -422,13 +422,16 @@ doPromotion(Function *F, FunctionAnalysisManager &FAM,
 
 /// Return true if we can prove that all callees pass in a valid pointer for the
 /// specified function argument.
-static bool allCallersPassValidPointerForArgument(Argument *Arg,
-                                                  Align NeededAlign,
-                                                  uint64_t NeededDerefBytes) {
+static bool allCallersPassValidPointerForArgument(
+    Argument *Arg, SmallPtrSet<CallBase *, 4> &RecursiveCalls,
+    Align NeededAlign, uint64_t NeededDerefBytes) {
   Function *Callee = Arg->getParent();
   const DataLayout &DL = Callee->getParent()->getDataLayout();
   APInt Bytes(64, NeededDerefBytes);
 
+  if (RecursiveCalls.size())
+    return true;
----------------
efriedma-quic wrote:

Reading the testcase... the argument isn't marked dereferenceable for the definition of foo(), and we don't have any information in bar(), so the current logic can't prove it's dereferenceable.

It might be possible to prove the argument is dereferenceable because there's a load on all paths through foo(), but that logic shouldn't be in ArgPromotion; it should be in function-attrs, or something like that.

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


More information about the llvm-commits mailing list