Skip to content

[AArch64] Correctly detect X reg from w reg in isCopyImpl #137348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2025

Conversation

davemgreen
Copy link
Collaborator

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.

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 llvm#129889.
@llvmbot
Copy link
Member

llvmbot commented Apr 25, 2025

@llvm/pr-subscribers-backend-aarch64

Author: David Green (davemgreen)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/137348.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64InstrInfo.cpp (+1-2)
  • (modified) llvm/test/CodeGen/AArch64/copyprop.mir (+13)
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 8e9ac82b5acd6..1a13adc300d2b 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -10053,8 +10053,7 @@ AArch64InstrInfo::isCopyInstrImpl(const MachineInstr &MI) const {
       (!MI.getOperand(0).getReg().isVirtual() ||
        MI.getOperand(0).getSubReg() == 0) &&
       (!MI.getOperand(0).getReg().isPhysical() ||
-       MI.findRegisterDefOperandIdx(MI.getOperand(0).getReg() - AArch64::W0 +
-                                        AArch64::X0,
+       MI.findRegisterDefOperandIdx(getXRegFromWReg(MI.getOperand(0).getReg()),
                                     /*TRI=*/nullptr) == -1))
     return DestSourcePair{MI.getOperand(0), MI.getOperand(2)};
 
diff --git a/llvm/test/CodeGen/AArch64/copyprop.mir b/llvm/test/CodeGen/AArch64/copyprop.mir
index 2454509d80862..ea68c43f3eee8 100644
--- a/llvm/test/CodeGen/AArch64/copyprop.mir
+++ b/llvm/test/CodeGen/AArch64/copyprop.mir
@@ -113,3 +113,16 @@ body: |
     $w9 = ORRWrs $wzr, $wzr, 0
     STRBBui killed renamable $w9, killed renamable $x8, 36
 ...
+---
+# CHECK-LABEL: name: make_sure_w29_and_fp_isnt_removed
+# CHECK: $w29 = ORRWrs $wzr, $w29, 0, implicit $fp, implicit-def $fp
+name:            make_sure_w29_and_fp_isnt_removed
+tracksRegLiveness: true
+frameInfo:
+  maxCallFrameSize: 32
+body: |
+  bb.0:
+    liveins: $x8, $fp
+    $w29 = ORRWrs $wzr, $w29, 0, implicit $fp, implicit-def $fp
+    renamable $q0 = LDRQroX killed renamable $x8, $fp, 0, 1
+...

Copy link
Collaborator

@ostannard ostannard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davemgreen davemgreen merged commit 76545d7 into llvm:main Apr 26, 2025
13 checks passed
@davemgreen davemgreen deleted the gh-a64-fixcopyw29fp branch April 26, 2025 10:09
jyli0116 pushed a commit to jyli0116/llvm-project that referenced this pull request Apr 28, 2025
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 llvm#129889.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
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 llvm#129889.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
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 llvm#129889.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
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 llvm#129889.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
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 llvm#129889.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants