This is an archive of the discontinued LLVM Phabricator instance.

[SelectOpti] Fix lifetime intrinsic bug
ClosedPublic

Authored by apostolakis on Sep 13 2022, 7:45 AM.

Details

Summary

When a select is converted to a branch and load instructions are sinked to the true/false blocks,
lifetime intrinsics (if present) could be made unsound if not moved.

This conservatively moves all lifetime intrinsics in a transformed BB to the end block to ensure
preserved lifetime semantics.

Diff Detail

Event Timeline

apostolakis created this revision.Sep 13 2022, 7:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2022, 7:45 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
apostolakis requested review of this revision.Sep 13 2022, 7:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 13 2022, 7:45 AM
apostolakis edited the summary of this revision. (Show Details)Sep 13 2022, 8:11 AM
apostolakis added a reviewer: davidxl.
apostolakis edited the summary of this revision. (Show Details)

Move lifetime intrinsics only if there is sinking

davidxl added inline comments.Sep 13 2022, 9:25 AM
llvm/lib/CodeGen/SelectOptimize.cpp
432

is it better to track the life end variable and inserted after the target instruction?

davidxl accepted this revision.Sep 13 2022, 11:23 AM

It is unclear that the more precise life time tracking can make a big difference given the code region (post transformation) is small, so this handling LGTM.

This revision is now accepted and ready to land.Sep 13 2022, 11:23 AM
apostolakis marked an inline comment as done.Sep 13 2022, 11:28 AM
apostolakis added inline comments.
llvm/lib/CodeGen/SelectOptimize.cpp
432

Yes as you said, the potential gains are small since the code region is just a single split basic block.

Also note that, to begin with, currently-emitted lifetimes intrinsics are not very tight to the actual lifetime of objects.
This is probably because other optimizations are also conservative when placing them and moving them .
For example, for the case that caused the bug, the lifetime ended 4 instructions after the final use of the variable.

This revision was landed with ongoing or failed builds.Sep 13 2022, 12:15 PM
This revision was automatically updated to reflect the committed changes.
apostolakis marked an inline comment as done.