Skip to content

Commit fd364a3

Browse files
committed
[MachineCopyPropagation] When the source of PreviousCopy is undef, we cannot replace sub register
The `postrapseudos` may replace `mov w8, w0` with `mov x8, x0`.
1 parent 5a5ade3 commit fd364a3

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

llvm/lib/CodeGen/MachineCopyPropagation.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ static bool isNopCopy(const MachineInstr &PreviousCopy, MCRegister Src,
443443
return true;
444444
if (!TRI->isSubRegister(PreviousSrc, Src))
445445
return false;
446+
// When the source of PreviousCopy is undef, we cannot replace sub register.
447+
if (CopyOperands->Source->isUndef())
448+
return false;
446449
unsigned SubIdx = TRI->getSubRegIndex(PreviousSrc, Src);
447450
return SubIdx == TRI->getSubRegIndex(PreviousDef, Def);
448451
}

llvm/test/CodeGen/AArch64/machine-cp-undef.mir

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ body: |
1010
; CHECK-NEXT: successors: %bb.1(0x80000000)
1111
; CHECK-NEXT: liveins: $w0
1212
; CHECK-NEXT: {{ $}}
13-
; CHECK-NEXT: $x8 = ORRXrs $xzr, $x0, 0, implicit $w0
13+
; CHECK-NEXT: $x8 = ORRXrs $xzr, undef $x0, 0, implicit $w0
14+
; CHECK-NEXT: $w8 = ORRWrs $wzr, $w0, 0, implicit-def $x8
1415
; CHECK-NEXT: {{ $}}
1516
; CHECK-NEXT: bb.1:
1617
; CHECK-NEXT: liveins: $x8

0 commit comments

Comments
 (0)