This is an archive of the discontinued LLVM Phabricator instance.

[DSE,MSSA] Treat passed by value args as invisible to caller.
ClosedPublic

Authored by fhahn on Jun 19 2020, 11:31 AM.

Details

Summary

This updates the MemorySSA backed implementation to treat arguments
passed by value similar to allocas: in they are assumed to be invisible
in the caller. This is similar to how they are treated in legacy DSE.

Diff Detail

Event Timeline

fhahn created this revision.Jun 19 2020, 11:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 19 2020, 11:31 AM
efriedma added inline comments.Jun 19 2020, 12:08 PM
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1568

For inalloca and preallocated, the argument has the same address in the caller and the callee. So if I'm understanding correctly, InvisibleToCallerBeforeRet should only apply specifically to byval.

efriedma added inline comments.Jun 19 2020, 12:09 PM
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1566–1572

Is there an incorrectly resolved merge conflict here?

fhahn updated this revision to Diff 272163.Jun 19 2020, 12:44 PM

Remove unintended duplication, limit InivisibleBeforeRet to byval.

fhahn marked 2 inline comments as done.Jun 19 2020, 12:47 PM
fhahn added inline comments.
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1566–1572

Yes that was unintentional. sorry about that!

1568

Right, I thought the caller cannot expect to observe any writes to any PassPointeeByVal argument, but it is not entirely clear from the langref. I've updated the code as suggested. Legacy DSE seems to treat them at least as if writes are not observable after the function returns.

efriedma added inline comments.Jun 19 2020, 1:32 PM
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1568

For all of byval, inalloca, and preallocated, the allocation is implicitly freed when the function's stack frame is freed (when the function returns or unwinds).

The aspect where inalloca and preallocated differ is related to escaping. Essentially, for inalloca/preallocated arguments, the address has already escaped before the function starts executing.

Not sure what "even if the function exits through an exception" means in this context. The comment should be something more like "for byval, the caller doesn't know the address of the allocation".

fhahn updated this revision to Diff 272302.Jun 21 2020, 4:39 AM

Update comment as suggested, thanks Eli!

fhahn marked an inline comment as done.Jun 21 2020, 4:43 AM
fhahn added inline comments.
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
1568

Makes sense, I've updated the comment, thanks!

Currently the InvisbleToCallerSets are framed as the object being invisible to the caller, but I think the key point is whether modifications in the callee are visible to the caller. I think then it would be possible to include inalloca & preallocate as invisible before returning (i.e. when unwinding). But that's potential for another patch.

This revision is now accepted and ready to land.Jun 22 2020, 12:20 PM
This revision was automatically updated to reflect the committed changes.