This is an archive of the discontinued LLVM Phabricator instance.

[MachineBasicBlock] Skip over debug instructions in computeRegisterLiveness before checking for begin/end.
ClosedPublic

Authored by craig.topper on Oct 29 2019, 11:55 PM.

Details

Summary

If there are debug instructions before/after the stopping point,
we need to skip over them before checking for begin/end in order
to avoid having the debug instructions effect behavior.

Fixes PR43758.

Diff Detail

Event Timeline

craig.topper created this revision.Oct 29 2019, 11:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2019, 11:55 PM

Create the diff correctly. I forgot to commit the test case before running arcanist.

craig.topper retitled this revision from [X86] Add test case for PR43758. NFC to [MachineBasicBlock] Skip over debug instructions in computeRegisterLiveness before checking for begin/end..Oct 30 2019, 12:40 AM
craig.topper edited the summary of this revision. (Show Details)
yechunliang added inline comments.
llvm/lib/CodeGen/MachineBasicBlock.cpp
1410–1411

Does this code duplicated with the line: 1392-1394?

for (; I != end() && N > 0; ++I) {
   if (I->isDebugInstr())
     continue;

Will it be better to use getFirstNonDebugInstr() instead of begin() on line 1475?

// Did we get to the start of the block?
-   if (I == begin()) {
+   if (I == getFirstNonDebugInstr()) {
craig.topper marked an inline comment as done.Oct 30 2019, 8:05 AM

Will it be better to use getFirstNonDebugInstr() instead of begin() on line 1475?

// Did we get to the start of the block?
-   if (I == begin()) {
+   if (I == getFirstNonDebugInstr()) {

Not sure. I guess it depends on whether its more likely that there are debug instructions at the beginning of the block or the current iterator. If we use getFirstNonDebugInstr we're starting a separate scan from the beginning of the block. The code I have here starts from the current iterator.

llvm/lib/CodeGen/MachineBasicBlock.cpp
1410–1411

But that code stops when N is 0. So we can exit the loop without being at end() and have debug instructions after right?

efriedma added inline comments.Oct 30 2019, 4:58 PM
llvm/lib/CodeGen/MachineBasicBlock.cpp
1410–1411

Yes, but it's probably better to refactor the loop to use an an early exit, or something like that.

Look at the debugging printf information, I found the begin() is the first instruction of the BasicBlock, but the end() is not the last instruction, it's something unknown or none flag.
If what I found is correct, and would say end() could not be debug instruction, and maybe we needn't consider about debug instruction impact for end() part.

llvm/lib/CodeGen/MachineBasicBlock.cpp
1410–1411

Before N--, the above code " if (I->isDebugInstr()) continue" will skip the DebugInstr. So the variable "I" could not be DebugInstr when N=0.
So when case N=0, the variable "I" should be real instruction. And Line 1409-1411 will be duplicate.

Remove the end part of the code

This revision is now accepted and ready to land.Oct 31 2019, 12:23 PM
This revision was automatically updated to reflect the committed changes.