This is an archive of the discontinued LLVM Phabricator instance.

[LAA] Fix estimation of number of memchecks
ClosedPublic

Authored by sbaranga on Jun 3 2015, 9:43 AM.

Details

Summary

We need to add a runtime memcheck for pair of accesses (x,y) where at least one of x and y
are writes.

Assuming we have w writes and r reads, currently this number is estimated as being
w* (w+r-1). This estimation will count (write,write) pairs twice and will overestimate
the number of checks required.

This change adds a getNumberOfChecks method to RuntimePointerCheck, which
will count the number of runtime checks needed (similar in implementation to
needsAnyChecking) and uses it to produce the correct number of runtime checks.

Diff Detail

Event Timeline

sbaranga updated this revision to Diff 27044.Jun 3 2015, 9:43 AM
sbaranga retitled this revision from to [LAA] Fix estimation of number of memchecks.
sbaranga updated this object.
sbaranga edited the test plan for this revision. (Show Details)
sbaranga added a reviewer: anemet.
sbaranga added a subscriber: Unknown Object (MLST).

A minor comment inline:

lib/Analysis/LoopAccessAnalysis.cpp
1212–1213

Would it be more readable if we write this as

CanDoRt = !NeedRTCheck || canCheckPtrAtRT(...)

?

anemet edited edge metadata.Jun 3 2015, 5:37 PM

With this change I don't think there is a reason to cache NumComparisons anymore. What do you think?

Specifically I mean:

include/llvm/Analysis/LoopAccessAnalysis.h
390–395

I think that this guy should now forward to getNumberOfChecks() and probably take a partition (by default nullptr) parameter.

469–470

To avoid confusion we should probably remove this.

lib/Analysis/LoopAccessAnalysis.cpp
228–234

I don't think there is a reason for this function to return NumComparisons now. It should probably return NeedRTCheck instead (used in the caller).

sbaranga updated this revision to Diff 27124.Jun 4 2015, 8:40 AM
sbaranga edited edge metadata.

Removed the caching of getNumberOfCheck and updated the API to not return it as part of canCheckPtrAtRT.
Removed some dead code (NumReadPtrChecks and NumWritePtrChecks are no longer needed).

NeedRTCheck is now returned by canCheckPtrAtRT. I've also changed the logic that computes NeedRTChecks according to Michaels comment to make it more readable, and that change ended up being in canCheckPtrAtRT.

sbaranga added inline comments.Jun 4 2015, 8:42 AM
lib/Analysis/LoopAccessAnalysis.cpp
1212–1213

Yes, that looks better. I've included the change in the new revision.

With this change I don't think there is a reason to cache NumComparisons anymore. What do you think?

Specifically I mean:

Yes, that makes sense. I've removed it in the newer revision. I've also found some other code that was made dead by the interface changes and removed it as well.

The patch LGTM.

Minor nitpicks:

lib/Analysis/LoopAccessAnalysis.cpp
356

This looks a bit confusing (probably, because of the variable names) - why do we need a RT check if we can't add them? A comment would be helpful here.

1223–1224

The debug message no longer needs "if needed" part.

And by the way, why do we need this change? To me the original and changed versions seem equivalent except that we won't print any message if NeedRTCheck==false and CanDoRT==true .

anemet accepted this revision.Jun 4 2015, 12:35 PM
anemet edited edge metadata.

Very nice! LGTM.

lib/Analysis/LoopAccessAnalysis.cpp
1216–1219

Looks like you only use NumComparison in the DEBUG message now. With a release compiler this will probably give you a warning.

This revision is now accepted and ready to land.Jun 4 2015, 12:35 PM

Thanks both! I'll commit this on Monday (with the fixed remaining issues).

lib/Analysis/LoopAccessAnalysis.cpp
1223–1224

Good point. I'll remove this from the final version.

sbaranga updated this revision to Diff 27290.Jun 8 2015, 3:22 AM
sbaranga updated this object.
sbaranga edited edge metadata.

Removed NumComparisons and replaced it with a call to
getNumberOfChecks().

Added comments to explain the NeedRTCheck logic.

Keep the original behaviour of the
"We can perform a memory runtime check if needed" debug
message.

sbaranga closed this revision.Jun 8 2015, 3:31 AM