This is an archive of the discontinued LLVM Phabricator instance.

[MachineOutliner] Fix liveness computing.
AbandonedPublic

Authored by yroux on Jul 7 2020, 8:22 AM.

Details

Summary

There are targets, such as ARM, where if-conversion can insert a predicated terminator when merging blocks. On ARM this instruction (BX_RET) doesn't contain the information that it uses the link register (this is handled by addLiveOuts which will add calle saved regtisters if needed), thus the current implementation might miss this link register usage wrongly insert an outlined call without saving it.

Diff Detail

Event Timeline

yroux created this revision.Jul 7 2020, 8:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 7 2020, 8:22 AM

I'm not really happy with this approach; if LiveRegUnits isn't producing correct results, we should fix it, not try to hack around it.

Maybe we should revive D40061...

I guess I just don't understand why the BX_RET wouldn't be marked with using the link register in the first place?

yroux added a comment.EditedJul 9 2020, 6:14 AM

I'm not really happy with this approach; if LiveRegUnits isn't producing correct results, we should fix it, not try to hack around it.

Maybe we should revive D40061...

My attempt wasn't to hack around it, but to calculate the LiveRegUnit accurately ;-) Sorry I wasn't working on LLVM when you proposed D40061, but it is indeed a better approach, can you re-open it ?

yroux added a comment.Jul 9 2020, 6:28 AM

I guess I just don't understand why the BX_RET wouldn't be marked with using the link register in the first place?

Yes that's confusing and the first thing I tried was to add a USES = [LR] to its definition, but then LR will need to be livein everywhere my understanding is that it is handled as needed by prolog/epilog emission

@efriedma Was there much more to do on your original patch?

I think the remaining issue was that IfConversion was producing messy code in some cases. We would stick a conditional return and an unconditional branch in the same block, and the ARM analyzeBranch couldn't understand that. That led to some weird consequences for block layout. So probably not too much more work. I think I just got distracted from it because it wasn't actually solving any practical issue when I wrote it.

@efriedma Would you have time/desire to look at the patch again? Or would you mind someone else taking a look? I'd really like to get the outliner enablement unblocked.

I guess there are three possible paths forward here:

  1. Someone revives D40061, so it's impossible to have a terminator in the middle of a block.
  2. We fix LiveRegUnits to handle this.
  3. We accumulate technical debt by repeatedly fixing the same issue in every user of LiveRegUnits.

It should be obvious why (3) isn't appealing.

I don't see any problem with the logic in this patch, in the sense that the result of the analysis should correctly reflect reality.

If someone else wants to take over D40061, I'd be fine with that; I probably won't have time to work on it in the next few weeks.

Okay, thanks - I will take a look at it then. It appears that the lingering unconditional branches, that you were concerned about, are no longer there. It looks like most of the work will be updating all the MIR tests...

yroux abandoned this revision.Sep 1 2020, 5:01 AM

Issue fixed by D40061