Skip to content

Commit 76545d7

Browse files
authored
[AArch64] Correctly detect X reg from W reg in isCopyImpl (#137348)
The MachineCopyPropagation pass was incorrectly removing copy (ORRWrs) instruction that appeared to be a nop. The instruction should not have been marked as a copy though, the code was incorrectly assuming that w29 - w0 + x0 == x29, but as x29 is fp it was out of order with the other registers. Fixes an issue reported on #129889.
1 parent 5d91d12 commit 76545d7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10053,8 +10053,7 @@ AArch64InstrInfo::isCopyInstrImpl(const MachineInstr &MI) const {
1005310053
(!MI.getOperand(0).getReg().isVirtual() ||
1005410054
MI.getOperand(0).getSubReg() == 0) &&
1005510055
(!MI.getOperand(0).getReg().isPhysical() ||
10056-
MI.findRegisterDefOperandIdx(MI.getOperand(0).getReg() - AArch64::W0 +
10057-
AArch64::X0,
10056+
MI.findRegisterDefOperandIdx(getXRegFromWReg(MI.getOperand(0).getReg()),
1005810057
/*TRI=*/nullptr) == -1))
1005910058
return DestSourcePair{MI.getOperand(0), MI.getOperand(2)};
1006010059

llvm/test/CodeGen/AArch64/copyprop.mir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,16 @@ body: |
113113
$w9 = ORRWrs $wzr, $wzr, 0
114114
STRBBui killed renamable $w9, killed renamable $x8, 36
115115
...
116+
---
117+
# CHECK-LABEL: name: make_sure_w29_and_fp_isnt_removed
118+
# CHECK: $w29 = ORRWrs $wzr, $w29, 0, implicit $fp, implicit-def $fp
119+
name: make_sure_w29_and_fp_isnt_removed
120+
tracksRegLiveness: true
121+
frameInfo:
122+
maxCallFrameSize: 32
123+
body: |
124+
bb.0:
125+
liveins: $x8, $fp
126+
$w29 = ORRWrs $wzr, $w29, 0, implicit $fp, implicit-def $fp
127+
renamable $q0 = LDRQroX killed renamable $x8, $fp, 0, 1
128+
...

0 commit comments

Comments
 (0)