Skip to content

Commit 8dfe422

Browse files
committed
[AArch64] ORRWrs is copy instruction when there's no implicit def of the X register
1 parent cbaa787 commit 8dfe422

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9180,18 +9180,29 @@ void AArch64InstrInfo::buildClearRegister(Register Reg, MachineBasicBlock &MBB,
91809180

91819181
std::optional<DestSourcePair>
91829182
AArch64InstrInfo::isCopyInstrImpl(const MachineInstr &MI) const {
9183-
91849183
// AArch64::ORRWrs and AArch64::ORRXrs with WZR/XZR reg
91859184
// and zero immediate operands used as an alias for mov instruction.
9186-
if (MI.getOpcode() == AArch64::ORRWrs &&
9187-
MI.getOperand(1).getReg() == AArch64::WZR &&
9188-
MI.getOperand(3).getImm() == 0x0) {
9185+
bool OpIsORRWrs = MI.getOpcode() == AArch64::ORRWrs;
9186+
bool OpIsORRXrs = MI.getOpcode() == AArch64::ORRXrs;
9187+
if (!(OpIsORRWrs || OpIsORRXrs) || MI.getOperand(3).getImm() != 0x0)
9188+
return std::nullopt;
9189+
Register Reg1 = MI.getOperand(1).getReg();
9190+
9191+
if (OpIsORRWrs && Reg1 == AArch64::WZR) {
9192+
Register Reg0 = MI.getOperand(0).getReg();
9193+
if (Reg0.isPhysical()) {
9194+
const MachineFunction *MF = MI.getMF();
9195+
const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
9196+
for (const MachineOperand &MO : MI.implicit_operands())
9197+
if (MO.isDef() && MO.isImplicit() &&
9198+
TRI->isSubRegister(MO.getReg(), Reg0)) {
9199+
return std::nullopt;
9200+
}
9201+
}
91899202
return DestSourcePair{MI.getOperand(0), MI.getOperand(2)};
91909203
}
91919204

9192-
if (MI.getOpcode() == AArch64::ORRXrs &&
9193-
MI.getOperand(1).getReg() == AArch64::XZR &&
9194-
MI.getOperand(3).getImm() == 0x0) {
9205+
if (OpIsORRXrs && Reg1 == AArch64::XZR) {
91959206
return DestSourcePair{MI.getOperand(0), MI.getOperand(2)};
91969207
}
91979208

llvm/test/CodeGen/AArch64/machine-cp-sub-reg.mir

Lines changed: 2 additions & 1 deletion
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)