@@ -487,7 +487,7 @@ static bool allCallersPassValidPointerForArgument(
487
487
488
488
// Try to prove that all Calls to F do not modify the memory pointed to by Arg,
489
489
// using alias analysis local to each caller of F.
490
- static bool isArgUnmodifiedByAllCalls (Argument *Arg,
490
+ static bool isArgUnmodifiedByAllCalls (Argument *Arg, const LocationSize &Size,
491
491
FunctionAnalysisManager &FAM) {
492
492
for (User *U : Arg->getParent ()->users ()) {
493
493
@@ -499,6 +499,9 @@ static bool isArgUnmodifiedByAllCalls(Argument *Arg,
499
499
MemoryLocation Loc =
500
500
MemoryLocation::getForArgument (Call, Arg->getArgNo (), nullptr );
501
501
502
+ // Refine the MemoryLocation Size using information from Loads of Arg.
503
+ Loc = Loc.getWithNewSize (Size);
504
+
502
505
AAResults &AAR = FAM.getResult <AAManager>(*Call->getFunction ());
503
506
// Bail as soon as we find a Call where Arg may be modified.
504
507
if (isModSet (AAR.getModRefInfo (Call, Loc)))
@@ -743,10 +746,16 @@ static bool findArgParts(Argument *Arg, const DataLayout &DL, AAResults &AAR,
743
746
// Okay, now we know that the argument is only used by load instructions, and
744
747
// it is safe to unconditionally perform all of them.
745
748
746
- // If we can determine that no call to the Function modifies the memory
747
- // pointed to by Arg, through alias analysis using actual arguments in the
749
+ // If we can determine that no call to the Function modifies the memory region
750
+ // accessed through Arg, through alias analysis using actual arguments in the
748
751
// callers, we know that it is guaranteed to be safe to promote the argument.
749
- if (isArgUnmodifiedByAllCalls (Arg, FAM))
752
+
753
+ // Compute the size of the memory region accessed by the Loads through Arg.
754
+ LocationSize Size = LocationSize::precise (0 );
755
+ for (LoadInst *Load : Loads) {
756
+ Size = Size.unionWith (MemoryLocation::get (Load).Size );
757
+ }
758
+ if (isArgUnmodifiedByAllCalls (Arg, Size, FAM))
750
759
return true ;
751
760
752
761
// Otherwise, use alias analysis to check if the pointer is guaranteed to not
0 commit comments