This is an archive of the discontinued LLVM Phabricator instance.

MachineSink debug invariance
ClosedPublic

Authored by markus on Jun 7 2022, 5:27 AM.

Details

Summary

https://github.com/llvm/llvm-project/issues/55914

When counting instructions to compare with threshold debug instructions need to be ignored in order to be invariant wrt to debuginfo

Diff Detail

Event Timeline

markus created this revision.Jun 7 2022, 5:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 5:27 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
markus requested review of this revision.Jun 7 2022, 5:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2022, 5:27 AM
markus added a comment.Jun 7 2022, 5:29 AM

Should add a .mir test

llvm/lib/CodeGen/MachineSink.cpp
271

Don't we already have some utility function for this?

Orlando added a subscriber: Orlando.Jun 7 2022, 6:06 AM

Should add a .mir test

+1

This change looks ok to me but FTR I haven't touched the MachineSink pass before.

llvm/lib/CodeGen/MachineSink.cpp
271

It looks like we have .instructionsWithoutDebug() and .sizeWithoutDebug() for BasicBlock but I'm not sure if there's an equivalent for MachineBasicBlock. Maybe it'd be worth adding to MachineBasicBlock?

274

Should this be .isMetaInstr() (rather than .isDebugInstr()) to cover other non-debug that do not correspond to executable instructions?

markus updated this revision to Diff 434806.Jun 7 2022, 6:59 AM
markus added a reviewer: Orlando.

Add MachineBasicBlock::sizeWithoutDebug() to make more similar to IR.

markus added inline comments.Jun 7 2022, 7:03 AM
llvm/lib/CodeGen/MachineSink.cpp
274

Not sure but the way we do it now should be equivalent to how it works in BasicBlock::sizeWithoutDebug() which I guess is the way it should be.

The code changes look good to me, so just waiting for the test before approving now.

jmorse added a comment.Jun 8 2022, 6:47 AM

Also LGTM with a regression test, thanks for finding this.

fhahn added a subscriber: fhahn.Jun 8 2022, 8:27 AM
fhahn added inline comments.
llvm/lib/CodeGen/MachineBasicBlock.cpp
1622

One issue with this helper is that it needs to iterate over all instructions in the block to count them and the limit is used to decide whether the block is too big to process.

Not sure there's a good alternative, but maybe have something like sizeWIthoutDebugLargerThan(x) so we can at least bail out once the limit is reached.

jmorse added inline comments.Jun 8 2022, 8:52 AM
llvm/lib/CodeGen/MachineBasicBlock.cpp
1622

IIUC, basic block size is ilist size, which is already linear time anyway, so this wouldn't be a regression. That being said, putting a bound on this would be a neat extension.

markus updated this revision to Diff 435467.Jun 9 2022, 2:39 AM

Added lit-test.

markus added inline comments.Jun 9 2022, 2:43 AM
llvm/lib/CodeGen/MachineBasicBlock.cpp
1622

Agree that it would be better to limit the number of instructions scanned but I worry that introducing such a function in MachineBasicBlock would make it slightly unsymmetric wrt its IR equivalent. Maybe it is worth it though, I can't really tell.

The test LGTM - I'll leave it to @jmorse or @fhahn to accept when a consensus is reached on whether a bounded version of sizeWithoutDebug should be added or not.

markus updated this revision to Diff 435529.Jun 9 2022, 6:34 AM

Fixed typo in lit-test.

markus updated this revision to Diff 435840.Jun 10 2022, 1:57 AM
markus added a reviewer: fhahn.

MachineBasicBlock::sizeWithoutDebugLargerThan(unsigned Limit)

jmorse accepted this revision.Jun 20 2022, 7:38 AM

LGTM, adding a size-with-limit method looks good too.

This revision is now accepted and ready to land.Jun 20 2022, 7:38 AM
This revision was landed with ongoing or failed builds.Jun 20 2022, 11:13 PM
This revision was automatically updated to reflect the committed changes.