This is an archive of the discontinued LLVM Phabricator instance.

[MemoryLocation] Don't require nocapture in getForDest()
ClosedPublic

Authored by nikic on Dec 22 2021, 2:08 AM.

Details

Summary

As @reames mentioned on related reviews, we don't need the nocapture requirement here. First of all, from an API perspective, this is not something that MemoryLocation::getForDest() should be checking in the first place, because it does not affect which memory this particular call can access; it's an orthogonal concern that should be handled by the caller if necessary.

However, for both of the motivating users in DSE and InstCombine, we don't need the nocapture requirement, because the capture can either be purely local to the call (a pointer identity check that is irrelevant to us), be part of the return value (which we check is unused), or be written in the dest location, which we have determined to be dead.

This allows us to remove the special handling for libcalls as well.

Diff Detail

Event Timeline

nikic created this revision.Dec 22 2021, 2:08 AM
nikic requested review of this revision.Dec 22 2021, 2:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 22 2021, 2:08 AM
fhahn added inline comments.Dec 22 2021, 2:14 AM
llvm/test/Transforms/DeadStoreElimination/trivial-dse-calls.ll
231

The capture can only be in the return value

There is no return value in the test :)

Should we add a variant of the test where either the first argument is not local or there's a return value? I guess in both cases we won't remove for non-capture related reasons, but still might be good to have here for completeness

nikic updated this revision to Diff 395822.Dec 22 2021, 2:45 AM

Add tests where return value is used.

fhahn accepted this revision.Dec 22 2021, 2:59 AM

LGTM, thanks!

llvm/test/Transforms/DeadStoreElimination/trivial-dse-calls.ll
223

nit: %bitcast2 may by captured via the return value.

This revision is now accepted and ready to land.Dec 22 2021, 2:59 AM
This revision was landed with ongoing or failed builds.Dec 22 2021, 3:20 AM
This revision was automatically updated to reflect the committed changes.

Thanks for following up on this. For the record, LGTM by me as well. :)