This is an archive of the discontinued LLVM Phabricator instance.

[MachineSink] Use SkipPHIsAndLabels for sink insertion points
ClosedPublic

Authored by critson on Feb 9 2022, 7:03 PM.

Details

Summary

For AMDGPU the insertion point for a block may not be the first
non-PHI instruction. This happens when a block contains EXEC
mask manipulation related to control flow (converging lanes).

Use SkipPHIsAndLabels to determine the block insertion point
so that the target can skip any block prologue instructions.

Diff Detail

Event Timeline

critson created this revision.Feb 9 2022, 7:03 PM
critson requested review of this revision.Feb 9 2022, 7:03 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 9 2022, 7:03 PM

The test is based on new wave transform control flow, and does not occur with current control flow which uses pseudo instructions which are typically lowered after machine sinking.

llvm/test/CodeGen/AMDGPU/sink-after-control-flow.mir
72

Without this change this instruction is inserted before the S_OR_B32 above.

This revision is now accepted and ready to land.Feb 10 2022, 9:03 AM
ruiling added inline comments.
llvm/lib/CodeGen/MachineSink.cpp
1396

I would suggest we use SkipPHIsAndLabels() to determine the insertion point here. It will make sure we are inserting after prologue instructions. I would also suggest we fix the other two getFirstNonPHI() uses in this file.

lkail added a subscriber: shchenz.Feb 10 2022, 7:41 PM
critson updated this revision to Diff 408312.Feb 13 2022, 6:45 PM
critson marked an inline comment as done.
  • Rework to fixing MachineSink with SkipPHIsAndLabels
llvm/lib/CodeGen/MachineSink.cpp
1396

Thank you for this suggestion.
It is a much cleaner solution to fix MachineSink to use SkipPHIsAndLabels.
I was unaware of TII->isBasicBlockPrologue.

critson retitled this revision from [MachineSink] Allow target to adjust sink insertion point to [MachineSink] Use SkipPHIsAndLabels for sink insertion points.Feb 13 2022, 6:49 PM
critson edited the summary of this revision. (Show Details)
ruiling accepted this revision.Feb 14 2022, 5:41 AM

LGTM

arsenm added inline comments.Feb 14 2022, 6:50 AM
llvm/test/CodeGen/AMDGPU/sink-after-control-flow.mir
3

The -mattr can be removed, wave32 is the default

4

Add a brief comment explaining the test?

123–184

Can you prune out some of these blocks?

critson updated this revision to Diff 408667.Feb 14 2022, 4:34 PM
critson marked 3 inline comments as done.
  • Address reviewer comments
  • Further prune test
This revision was landed with ongoing or failed builds.Feb 15 2022, 7:45 PM
This revision was automatically updated to reflect the committed changes.