[llvm] [ArgPromotion] Perform alias analysis on actual arguments of Calls (PR #106216)
Matthew Devereau via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 6 07:00:55 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.
----------------
MDevereau wrote:
This comment, the one on line 492, the one on line 488/499, and the function name all pretty much say the same thing. Maybe delete the ones in the function body
https://github.com/llvm/llvm-project/pull/106216
More information about the llvm-commits
mailing list