[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 20 10:11:49 PDT 2024
================
@@ -716,10 +744,22 @@ static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR,
return true;
// Okay, now we know that the argument is only used by load instructions, and
- // it is safe to unconditionally perform all of them. Use alias analysis to
- // check to see if the pointer is guaranteed to not be modified from entry of
- // the function to each of the load instructions.
+ // it is safe to unconditionally perform all of them.
+
+ // If we can determine that no call to the Function modifies the memory region
+ // accessed through Arg, through alias analysis using actual arguments in the
+ // callers, we know that it is guaranteed to be safe to promote the argument.
+
+ // Compute the size of the memory region accessed by the Loads through Arg.
+ LocationSize Size = LocationSize::precise(0);
+ for (LoadInst *Load : Loads) {
+ Size = Size.unionWith(MemoryLocation::get(Load).Size);
+ }
----------------
hazzlim wrote:
Sorry about this - I got that completely wrong there.
I have fixed this to re-use the Size that is computed during the check that the parts are non-overlapping - which I believe is correct. I think that this is more conservative than it could be, as it computes the Size of the Memory Location from base pointer Arg, but you could have the case where all loads are from some non-zero offset from Arg. However it's not obvious to me how we could "add" this offset to the Pointer from the Caller in the Memory Location used in `isArgUnmodifiedByAllCalls()`.
I struggled to come up with a test for the Size of the Memory Location, I don't know if you have any ideas there?
https://github.com/llvm/llvm-project/pull/106216
More information about the llvm-commits
mailing list