This is an archive of the discontinued LLVM Phabricator instance.

[AggressiveAntiDepBreaker] Refix renaming a subregister of a live register
ClosedPublic

Authored by foad on Aug 2 2023, 5:12 AM.

Details

Summary

This patch reworks the fix from D20627 "Do not rename registers that do
not start an independent live range". That fix depended on the scheduler
dependency graph having redundant edges. Those edges are removed by
D156552 "[MachineScheduler] Track physical register dependencies
per-regunit" with the result that on several Hexagon lit tests, the
post-RA scheduler would schedule the code in a way that fails machine
verification.

Consider this code where D11 is a pair R23:R22:

SU(0): %R2<def> = A2_add %R23, %R17<kill>
    (anti dependency on R23 here)
SU(8): %R23<def> = S2_asr_i_r %R22, 31
    (data dependency on R23->D11 here)
SU(10): %D0<def> = A2_tfrp %D11<kill>

The original fix would detect this situation by examining the dependency
from SU(8) to SU(10) and seeing that D11 is not a subreg of R23.

A slightly more complicated example:

SU(0): %R2<def> = A2_add %R23, %R17<kill>
    (anti dependency on R23 here)
SU(8): %R23<def> = S2_asr_i_r %R22, 31
    (data dependency on R23 here)
SU(9): %R23<def> = S2_asr_i_r %R23, 31
    (data dependency on R23->D11 here)
SU(10): %D0<def> = A2_tfrp %D11<kill>

The original fix also worked on this example, but only because
ScheduleDAGInstrs adds an extra data dependency edge directly from SU(8)
to SU(10). This edge is redundant, since you could infer it transitively
from the edges SU(8)->SU(9) and SU(9)->SU(10), and since none of the
data that SU(8) writes to R23 is read by SU(10).

After D156552 the redundant edge SU(8)->SU(10) will not be present, so
when we examine the successors of SU(8) we will not find any that read
from a superreg of R23.

This patch removes the original fix from D20627, which examined edges in
the dependency graph. Instead it extends a check that was already being
done in FindSuitableFreeRegisters: instead of checking that *some*
register is a superreg of all registers in the rename group, we now
check that the specific register that carries the anti-dependency that
we want to break is a superreg of all registers in the rename group.

Diff Detail

Event Timeline

foad created this revision.Aug 2 2023, 5:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2023, 5:12 AM
foad requested review of this revision.Aug 2 2023, 5:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2023, 5:12 AM
arsenm added inline comments.Aug 2 2023, 5:15 AM
llvm/lib/CodeGen/AggressiveAntiDepBreaker.h
179–181

use Register instead of unsigned

arsenm accepted this revision.Aug 2 2023, 5:20 AM

I don't know if there are any legitimate reasons to use MCRegAliasIterator anymore, deleting them is good

This revision is now accepted and ready to land.Aug 2 2023, 5:20 AM
foad added inline comments.
llvm/lib/CodeGen/AggressiveAntiDepBreaker.h
179–181

Good idea, but I'd prefer to do that as a separate cleanup for all the code in this pass.