[llvm-branch-commits] [llvm] release/23.x: [AArch64] Don't rename fixed implicit uses when forming load/store pairs (#235446) (PR #237172)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 30 03:55:31 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Guy David (guy-david)
<details>
<summary>Changes</summary>
Backport e9996a2e210d021783d597d99ccd3199b0885d49.
The only change is getting `MI` from `MOP.getParent()` because 23.x doesn't have https://github.com/llvm/llvm-project/pull/219471.
---
Full diff: https://github.com/llvm/llvm-project/pull/237172.diff
2 Files Affected:
- (modified) llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp (+7)
- (added) llvm/test/CodeGen/AArch64/stp-opt-with-renaming-implicit-uses.mir (+56)
``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp b/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
index bd0b603cfc06fd..4b54d1d9dd00a8 100644
--- a/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
+++ b/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
@@ -1779,6 +1779,13 @@ static bool canRenameMOP(const MachineOperand &MOP,
return TRI->isSuperOrSubRegisterEq(
MOP.getParent()->getOperand(0).getReg(), MOP.getReg());
}
+
+ // Implicit uses of calls and instruction description are fixed and cannot
+ // be renamed.
+ const MachineInstr &MI = *MOP.getParent();
+ if (MOP.isImplicit() &&
+ (MI.isCall() || MI.getDesc().hasImplicitUseOfPhysReg(MOP.getReg())))
+ return false;
}
return MOP.isImplicit() ||
(MOP.isRenamable() && !MOP.isEarlyClobber() && !MOP.isTied());
diff --git a/llvm/test/CodeGen/AArch64/stp-opt-with-renaming-implicit-uses.mir b/llvm/test/CodeGen/AArch64/stp-opt-with-renaming-implicit-uses.mir
new file mode 100644
index 00000000000000..b9a49d1a49515c
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/stp-opt-with-renaming-implicit-uses.mir
@@ -0,0 +1,56 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -mtriple=aarch64 -run-pass=aarch64-ldst-opt -verify-machineinstrs -o - %s | FileCheck %s
+
+---
+name: call_implicit_use
+tracksRegLiveness: true
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: call_implicit_use
+ ; CHECK: renamable $x20 = MOVZXi 1, 0
+ ; CHECK-NEXT: BL &callee, csr_aarch64_rt_mostregs, implicit $x20
+ ; CHECK-NEXT: STRXui killed renamable $x20, $sp, 0 :: (store (s64))
+ ; CHECK-NEXT: renamable $x20 = MOVZXi 2, 0
+ ; CHECK-NEXT: STRXui killed renamable $x20, $sp, 1 :: (store (s64))
+ renamable $x20 = MOVZXi 1, 0
+ BL &callee, csr_aarch64_rt_mostregs, implicit $x20
+ STRXui killed renamable $x20, $sp, 0 :: (store (s64))
+ renamable $x20 = MOVZXi 2, 0
+ STRXui killed renamable $x20, $sp, 1 :: (store (s64))
+...
+---
+name: call_no_implicit_use
+tracksRegLiveness: true
+body: |
+ bb.0:
+ ; CHECK-LABEL: name: call_no_implicit_use
+ ; CHECK: $x9 = MOVZXi 1, 0
+ ; CHECK-NEXT: BL &callee, csr_aarch64_rt_mostregs
+ ; CHECK-NEXT: renamable $x20 = MOVZXi 2, 0
+ ; CHECK-NEXT: STPXi killed $x9, killed renamable $x20, $sp, 0 :: (store (s64))
+ renamable $x20 = MOVZXi 1, 0
+ BL &callee, csr_aarch64_rt_mostregs
+ STRXui killed renamable $x20, $sp, 0 :: (store (s64))
+ renamable $x20 = MOVZXi 2, 0
+ STRXui killed renamable $x20, $sp, 1 :: (store (s64))
+...
+---
+name: hwasan_implicit_use
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $x0
+ ; CHECK-LABEL: name: hwasan_implicit_use
+ ; CHECK: liveins: $x0
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: renamable $x20 = MOVZXi 1, 0
+ ; CHECK-NEXT: HWASAN_CHECK_MEMACCESS_SHORTGRANULES $x0, 0, implicit $x20, implicit-def $x16, implicit-def $x17, implicit-def $lr, implicit-def $nzcv
+ ; CHECK-NEXT: STRXui killed renamable $x20, $sp, 0 :: (store (s64))
+ ; CHECK-NEXT: renamable $x20 = MOVZXi 2, 0
+ ; CHECK-NEXT: STRXui killed renamable $x20, $sp, 1 :: (store (s64))
+ renamable $x20 = MOVZXi 1, 0
+ HWASAN_CHECK_MEMACCESS_SHORTGRANULES $x0, 0, implicit $x20, implicit-def $x16, implicit-def $x17, implicit-def $lr, implicit-def $nzcv
+ STRXui killed renamable $x20, $sp, 0 :: (store (s64))
+ renamable $x20 = MOVZXi 2, 0
+ STRXui killed renamable $x20, $sp, 1 :: (store (s64))
+...
``````````
</details>
https://github.com/llvm/llvm-project/pull/237172
More information about the llvm-branch-commits
mailing list