[llvm-branch-commits] [llvm] release/23.x: [AArch64] Don't rename fixed implicit uses when forming load/store pairs (#235446) (PR #237147)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 30 02:16:16 PDT 2026
https://github.com/llvmbot updated https://github.com/llvm/llvm-project/pull/237147
>From 561536e09a6937ea1437e9e71ea8bc7aeffef6be Mon Sep 17 00:00:00 2001
From: Guy David <guyda96 at gmail.com>
Date: Fri, 30 Oct 2026 11:04:11 +0200
Subject: [PATCH] [AArch64] Don't rename fixed implicit uses when forming
load/store pairs (#235446)
Fixes https://github.com/swiftlang/swift/issues/93360.
To pair two stores of the same register, the optimizer renames the first
store's register from its definition up to the store.
`canRenameMOP` accepted every implicit use as renamable, which is mostly
fine but not for implicit uses whose register is fixed.
I am investigating a follow up that would allow pairing, based on
renaming the second register, but I think this patch alone is worth
backporting.
Assisted-by: Opus 5.5
(cherry picked from commit e9996a2e210d021783d597d99ccd3199b0885d49)
---
.../AArch64/AArch64LoadStoreOptimizer.cpp | 6 ++
.../stp-opt-with-renaming-implicit-uses.mir | 56 +++++++++++++++++++
2 files changed, 62 insertions(+)
create mode 100644 llvm/test/CodeGen/AArch64/stp-opt-with-renaming-implicit-uses.mir
diff --git a/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp b/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
index bd0b603cfc06fd..27f9d14ba8ed00 100644
--- a/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
+++ b/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
@@ -1779,6 +1779,12 @@ 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.
+ 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))
+...
More information about the llvm-branch-commits
mailing list