This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Fix the liveins for ppc-early-ret pass
AbandonedPublic

Authored by ZhangKang on Apr 18 2020, 6:54 PM.

Details

Reviewers
jsji
nemanjai
hfinkel
steven.zhang
efriedma
Group Reviewers
Restricted Project
Summary

The pass ppc-early-ret doesn't update the liveins after doing early return. It will cause assertion error when enable verify-machineinstrs.

Fo below mir:

bb.2:
  successors: %bb.3(0x80000000)
  liveins: $zero8

  renamable $x5 = ADDI8 $zero8, 0

bb.3:
  liveins: $x3, $x4, $x5

  BLR8 implicit $lr8, implicit $rm, implicit killed $x3, implicit killed $x4, implicit killed $x5

After doing ppc-early-ret, we will get:

bb.2:
  liveins: $zero8

  renamable $x5 = ADDI8 $zero8, 0
  BLR8 implicit $lr8, implicit $rm, implicit killed $x3, implicit killed $x4, implicit killed $x5

Above result will cause assertion error: Using an undefined physical register, because we have use undef $x3, $x4, $x5 in bb.2.

The right result should be:

bb.2:
  liveins: $zero8, $x3, $x4, $x5

  renamable $x5 = ADDI8 $zero8, 0
  BLR8 implicit $lr8, implicit $rm, implicit killed $x3, implicit killed $x4, implicit killed $x5

This patch is to fix the liveins for ppc-early-ret pass.

Diff Detail

Event Timeline

ZhangKang created this revision.Apr 18 2020, 6:54 PM
ZhangKang edited the summary of this revision. (Show Details)Apr 18 2020, 6:56 PM
jsji added a reviewer: Restricted Project.Apr 18 2020, 7:46 PM
jsji added a project: Restricted Project.

A physical register is "livein" when on entry to that block, the register contains some meaningful value, and that value is used in that block or one of its successors. Moving an instruction at the end of a block can't affect the liveness at the beginning of that block. If the register didn't contain a meaningful value before, it still won't contain a meaningful value afterwards.

Please take another look at the input and output to ppc-early-ret, and try to figure out what the correct liveness actually looks like. Blindly calling addLiveIn might satisfy the verifier, but it won't make the result correct.

ZhangKang planned changes to this revision.Apr 20 2020, 1:46 AM

A physical register is "livein" when on entry to that block, the register contains some meaningful value, and that value is used in that block or one of its successors. Moving an instruction at the end of a block can't affect the liveness at the beginning of that block. If the register didn't contain a meaningful value before, it still won't contain a meaningful value afterwards.

Please take another look at the input and output to ppc-early-ret, and try to figure out what the correct liveness actually looks like. Blindly calling addLiveIn might satisfy the verifier, but it won't make the result correct.

Yes, you are right. The real error is in ppc-expand-isel pass. I have create the patch https://reviews.llvm.org/D78657 for this. So I will close this patch.