[llvm] [ArgPromotion] Perform alias analysis on actual arguments of Calls (PR #106216)

Hari Limaye via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 6 11:48:37 PDT 2024


================
@@ -485,11 +485,39 @@ static bool allCallersPassValidPointerForArgument(
   });
 }
 
+// Try to prove that all Calls to F do not modify the memory pointed to by Arg,
+// using alias analysis local to each caller of F.
+static bool isArgUnmodifiedByAllCalls(Function *F, unsigned ArgNo,
+                                      FunctionAnalysisManager &FAM) {
+  // Check if all Users of F are Calls which do not modify Arg.
+  for (User *U : F->users()) {
+
+    // Bail if we find an unexpected (non CallInst) use of the function.
+    auto *Call = dyn_cast<CallInst>(U);
+    if (!Call)
+      return false;
+
+    Value *ArgOp = Call->getArgOperand(ArgNo);
+    assert(ArgOp->getType()->isPointerTy() && "Argument must be Pointer Type!");
+
+    MemoryLocation Loc = MemoryLocation::getForArgument(Call, ArgNo, nullptr);
+
+    AAResults &AAR = FAM.getResult<AAManager>(*Call->getFunction());
+    // Bail as soon as we find a Call where Arg may be modified.
+    if (isModSet(AAR.getModRefInfo(Call, Loc)))
+      return false;
+  }
+
+  // All Users are Calls which do not modify the Arg.
----------------
hazzlim wrote:

Removed redundant comments in [Address review comments 2](https://github.com/llvm/llvm-project/pull/106216/commits/aa809e9dc8a9bf5b5fc0cdc6f56549bd7806879d)

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


More information about the llvm-commits mailing list