Skip to content

Commit

Permalink
[MachineCopyPropagation] When the source of PreviousCopy is undef, we…
Browse files Browse the repository at this point in the history
… cannot replace sub register

The `postrapseudos` may replace `mov w8, w0` with `mov x8, x0`.
  • Loading branch information
DianQK committed Dec 7, 2023
1 parent 5a5ade3 commit fd364a3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions llvm/lib/CodeGen/MachineCopyPropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ static bool isNopCopy(const MachineInstr &PreviousCopy, MCRegister Src,
return true;
if (!TRI->isSubRegister(PreviousSrc, Src))
return false;
// When the source of PreviousCopy is undef, we cannot replace sub register.
if (CopyOperands->Source->isUndef())
return false;
unsigned SubIdx = TRI->getSubRegIndex(PreviousSrc, Src);
return SubIdx == TRI->getSubRegIndex(PreviousDef, Def);
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/CodeGen/AArch64/machine-cp-undef.mir
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ body: |
; CHECK-NEXT: successors: %bb.1(0x80000000)
; CHECK-NEXT: liveins: $w0
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: $x8 = ORRXrs $xzr, $x0, 0, implicit $w0
; CHECK-NEXT: $x8 = ORRXrs $xzr, undef $x0, 0, implicit $w0
; CHECK-NEXT: $w8 = ORRWrs $wzr, $w0, 0, implicit-def $x8
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: bb.1:
; CHECK-NEXT: liveins: $x8
Expand Down

0 comments on commit fd364a3

Please sign in to comment.