This is an archive of the discontinued LLVM Phabricator instance.

LivePhysRegs: Fix addLiveOutsNoPristines() for return blocks past PEI
ClosedPublic

Authored by MatzeB on Apr 24 2017, 7:34 PM.

Details

Summary

It turns out addLiveOutsNoPristines missed to add non-pristine callee saved registers in the return block. This probably went unnoticed, because we usually start walking backwards from the block end and at the time we actually queried/looked at the information we were before the epilogue code and it didn't matter anymore. This of course was not true for shrink-wrapping situations leading to bugs like the example in D32156.

In this patch:

  • addLiveOutsNoPristines() needs to add callee saved registers that are actually saved and restored somewhere to the set (they are not pristine).
  • Cleanup/rewrite the code for addLiveOuts()/addLiveOutsNoPristines().

This fixes the problem from D32156.

Diff Detail

Repository
rL LLVM

Event Timeline

MatzeB created this revision.Apr 24 2017, 7:34 PM
MatzeB edited the summary of this revision. (Show Details)Apr 24 2017, 7:37 PM

Note that I'll probably rework the test from D32156 for this if we agree on this patch.

timshen added inline comments.Apr 25 2017, 12:52 PM
lib/CodeGen/LivePhysRegs.cpp
194 ↗(On Diff #96492)

If MBB is empty but not a return block, is it the intended behavior here?

MatzeB added inline comments.Apr 25 2017, 12:55 PM
lib/CodeGen/LivePhysRegs.cpp
194 ↗(On Diff #96492)

Callee save register only need to be maintained when we actually leave the function.
Having succ_empty() but not a return block only happens in instance where we are not leaving the function: unreachable statements or calls to noreturn functions such as exit or abort are typical examples we don't need to restore CSRs for that.

194 ↗(On Diff #96492)

I should have said "not returning from the function" instead of "not leaving the function".

timshen edited edge metadata.Apr 25 2017, 1:20 PM

LGTM. Let's wait for @qcolombet.

gberry added a subscriber: gberry.May 4 2017, 8:10 AM
This revision is now accepted and ready to land.May 18 2017, 12:03 PM

Hi Matthias,

Do you want to use the test case in D32156?

This revision was automatically updated to reflect the committed changes.