This is an archive of the discontinued LLVM Phabricator instance.

[MemCpyOpt] Work around PR54682
ClosedPublic

Authored by nikic on Apr 1 2022, 8:33 AM.

Details

Summary

As discussed on https://github.com/llvm/llvm-project/issues/54682, MemorySSA currently has a bug when computing the clobber of calls that access loop-varying locations. I think a "proper" fix for this on the MemorySSA side might be non-trivial, but we can easily work around this in MemCpyOpt:

Currently, MemCpyOpt uses a location-less getClobberingMemoryAccess() call to find a clobber on either the src or dest location, and then refines it for the src and dest clobber. This was intended as an optimization, as the location-less API is cached, while the location-affected APIs are not.

However, I don't think this really makes a difference in practice, because I don't think anything will use the cached clobbers on those calls later anyway. Per http://llvm-compile-time-tracker.com/compare.php?from=cd55e51516f03203f3bf632ff4a65ae7518a8319&to=3a6ff3cb24c5e2fc4b9cd70c80f96bdce6cfa405&stat=instructions the impact seems to be very mildly positive actually.

So I think this is a reasonable way to avoid the problem for now, though MemorySSA should also get a fix.

Diff Detail

Event Timeline

nikic created this revision.Apr 1 2022, 8:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2022, 8:33 AM
nikic requested review of this revision.Apr 1 2022, 8:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2022, 8:33 AM
fhahn accepted this revision.Apr 1 2022, 8:51 AM

LGTM, thanks!

Not sure if it is directly related, but DSE has some code to check whether locations are guaranteed to be loop invariant (or are accessed in the same loop iteration) to deal with AA queries across loop boundaries.

This revision is now accepted and ready to land.Apr 1 2022, 8:51 AM
Allen added a subscriber: Allen.Apr 1 2022, 6:07 PM
This revision was landed with ongoing or failed builds.Apr 4 2022, 1:21 AM
This revision was automatically updated to reflect the committed changes.