This is an archive of the discontinued LLVM Phabricator instance.

[Inline Spiller] Consider bundles when marking defs as dead
ClosedPublic

Authored by piotr on Aug 3 2023, 6:34 AM.

Details

Summary

Fix bug where the code expects just a single MI, but a series of
bundled MIs need to be handled instead.

The semi-formed bundled are created by SplitKit for the case where
not all lanes are live (buildSingleSubRegCopy). Then the remat
kicks in, and since the values that are copied in the bundle do not
need to be preserved due to the remat (dead defs), all instructions
in the bundle should be marked as dead.

However, only the first one gets marked as dead, which causes the
verifier to complain later with error: "Live range continues after
dead def flag".

Diff Detail

Event Timeline

piotr created this revision.Aug 3 2023, 6:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 6:34 AM
piotr requested review of this revision.Aug 3 2023, 6:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2023, 6:34 AM
piotr added a comment.Aug 3 2023, 6:39 AM

The test case is dependent on AMDGPU-specific D154083, which rematerializes instructions with wide registers. I was not able to observe the erroneous behaviour without it, but should be possible to trigger it somehow.

piotr added a comment.EditedAug 3 2023, 6:40 AM

I am open to suggestions how to handle this more gracefully.

arsenm added inline comments.Aug 3 2023, 6:47 AM
llvm/lib/CodeGen/InlineSpiller.cpp
762

I don't think you can necessarily just delete any dead defs within the bundle without knowing you can delete all the dead defs in the bundle (with the possible exception of copies)

765

this is just ++It

arsenm added inline comments.Aug 3 2023, 6:48 AM
llvm/lib/CodeGen/InlineSpiller.cpp
759

I also think addRegisterDead only needs to be done for one instruction in the bundle?

piotr added inline comments.Aug 3 2023, 6:51 AM
llvm/lib/CodeGen/InlineSpiller.cpp
762

How can I know if it is safe to delete the dead defs in the bundle then? Do I need a stricter check somewhere? Should this be checking for the COPY explicitly?

piotr added inline comments.Aug 3 2023, 7:00 AM
llvm/lib/CodeGen/InlineSpiller.cpp
762

Are you suggesting this should just go through the defs first and see if all of them can be deleted, and only then do the deletion?

arsenm added inline comments.Aug 10 2023, 1:49 PM
llvm/lib/CodeGen/InlineSpiller.cpp
762

Yes, with the possible exception of copies. I'm unclear on the rules since these aren't fully formed bundles.

arsenm requested changes to this revision.Aug 14 2023, 2:48 PM

Don't think you can just rip out instructions in the middle of a bundle (except maybe for copy)

This revision now requires changes to proceed.Aug 14 2023, 2:48 PM
piotr added inline comments.Aug 25 2023, 8:27 AM
llvm/lib/CodeGen/InlineSpiller.cpp
762

The verifier error I'm chasing here only happens for copies, as it is hitting copies produced in buildSingleSubRegCopy, so special-casing copies would work here. I'll post an update soon.

piotr updated this revision to Diff 553921.Aug 28 2023, 7:11 AM

Reworked to check for copy.

arsenm added inline comments.
llvm/lib/CodeGen/InlineSpiller.cpp
764

Think you need to check isCopyInstr, not the lower level isCopy

768

My point was you should delete the whole bundle at a time, not just prune the copies out of it

piotr added inline comments.Sep 8 2023, 7:14 AM
llvm/lib/CodeGen/InlineSpiller.cpp
768

Ok, I see. I thought copies are safe to just delete. Will make the change.

piotr updated this revision to Diff 556440.Sep 11 2023, 9:12 AM

Delete only if all copies are dead, use isCopyInstr.

arsenm added inline comments.Sep 12 2023, 8:50 AM
llvm/lib/CodeGen/InlineSpiller.cpp
768

You need to check the outputs from isCopyInstr, it's not a boolean and you can't expect the operand indexes

piotr updated this revision to Diff 556658.Sep 13 2023, 6:07 AM

Corrected the use of isCopyInstr.

arsenm accepted this revision.Sep 13 2023, 6:10 AM
This revision is now accepted and ready to land.Sep 13 2023, 6:10 AM
This revision was landed with ongoing or failed builds.Oct 26 2023, 2:56 AM
This revision was automatically updated to reflect the committed changes.