This is an archive of the discontinued LLVM Phabricator instance.

[MachineVerifier] Relax checkLivenessAtDef regarding dead subreg defs
ClosedPublic

Authored by bjope on Sep 18 2018, 8:28 AM.

Details

Summary

Consider an instruction that has multiple defs of the same
vreg, but defining different subregs:

%7.sub1:rc, dead %7.sub2:rc = inst

Calling checkLivenessAtDef for the live interval associated
with %7 incorrectly reported "live range continues after a
dead def". The live range for %7 has a dead def at the slot
index for "inst" even if the live range continues (given that
there are later uses of %7.sub1).

This patch adjusts MachineVerifier::checkLivenessAtDef
to allow dead subregister definitions, unless we are checking
a subrange (when tracking subregister liveness).

A limitation is that we do not detect the situation when the
live range continues past an instruction that defines the
full virtual register by multiple dead subreg defines.

I also removed some dead code related to physical register
in checkLivenessAtDef. Wwe only call that method for virtual
registers, so I added an assertion instead.

Diff Detail

Repository
rL LLVM

Event Timeline

bjope created this revision.Sep 18 2018, 8:28 AM
bjope planned changes to this revision.Sep 18 2018, 8:32 AM

Almost forgot, I'll try to find a test case for an in-tree target!

In general, looking at a single instruction is not sufficient to tell whether a given register becomes dead or not, so I wouldn't worry about the limitation you mentioned. Cases that we can reliably handle are (sub)ranges corresponding to the parts of the register that is given in the operand (i.e. the entire register if there is no subregister).

lib/CodeGen/MachineVerifier.cpp
1572 ↗(On Diff #165986)

I think this is also wrong. What's worse is that we seem to be tracking the liveness of whole registers here, not register:subreg. In a case with %0.sub1, dead %0.sub2 = ..., a subsequent use of %0.sub1 could cause verification failure. I'm not sure how much work it would take to fix this, it doesn't have to be in this patch.

bjope updated this revision to Diff 166133.Sep 19 2018, 8:14 AM

Added a reproducer using hexagon as target, that way it was possible to show the difference between having subregister liveness or not.

bjope added inline comments.Sep 19 2018, 8:21 AM
lib/CodeGen/MachineVerifier.cpp
1572 ↗(On Diff #165986)

Yes, it looks suspicious. Although, I got a feeling that it is out-of-scope for this patch.

Depending on how regsDead is used it might just make the verifier let bad things pass without any remarks. That could explain why we do not have problems with this.

kparzysz accepted this revision.Sep 19 2018, 10:02 AM
This revision is now accepted and ready to land.Sep 19 2018, 10:02 AM
This revision was automatically updated to reflect the committed changes.