[llvm] 3ca2a5f - [LivePhysRegs][AArch64] Remove XZR from live registers (#176324)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 20 01:20:27 PST 2026


Author: Benjamin Lerman
Date: 2026-01-20T09:20:22Z
New Revision: 3ca2a5fc0b84762f0e7d8a0e613fd69f7e344219

URL: https://github.com/llvm/llvm-project/commit/3ca2a5fc0b84762f0e7d8a0e613fd69f7e344219
DIFF: https://github.com/llvm/llvm-project/commit/3ca2a5fc0b84762f0e7d8a0e613fd69f7e344219.diff

LOG: [LivePhysRegs][AArch64] Remove XZR from live registers (#176324)

XZR is always a zero, and cannot be clobbered.

Co-authored-by: Benjamin Lerman <qsr at google.com>

Added: 
    llvm/test/CodeGen/AArch64/no-xzr-liveins.mir

Modified: 
    llvm/include/llvm/CodeGen/LivePhysRegs.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/LivePhysRegs.h b/llvm/include/llvm/CodeGen/LivePhysRegs.h
index a76b7f95d9b93..6a9949ddfde1b 100644
--- a/llvm/include/llvm/CodeGen/LivePhysRegs.h
+++ b/llvm/include/llvm/CodeGen/LivePhysRegs.h
@@ -83,6 +83,9 @@ class LivePhysRegs {
   void addReg(MCRegister Reg) {
     assert(TRI && "LivePhysRegs is not initialized.");
     assert(Reg < TRI->getNumRegs() && "Expected a physical register.");
+    // Constant registers are never considered live.
+    if (TRI->isConstantPhysReg(Reg))
+      return;
     for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg))
       LiveRegs.insert(SubReg);
   }

diff  --git a/llvm/test/CodeGen/AArch64/no-xzr-liveins.mir b/llvm/test/CodeGen/AArch64/no-xzr-liveins.mir
new file mode 100644
index 0000000000000..ef774b7de23d1
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/no-xzr-liveins.mir
@@ -0,0 +1,30 @@
+# RUN: llc -mtriple=aarch64-unknown-fuchsia -run-pass=prologepilog %s -o - | FileCheck %s
+
+# This test ensures that constant registers like XZR are not considered live
+# even if they are in the liveins list. This prevents the stack probe from
+# incorrectly thinking it needs to preserve XZR if it's used as a temporary
+# register.
+
+--- |
+  define void @func() #0 {
+    ret void
+  }
+  attributes #0 = { "probe-stack"="inline-asm" "stack-probe-size"="4096" }
+...
+---
+name:            func
+tracksRegLiveness: true
+frameInfo:
+  stackSize:       4096
+  maxAlignment:    8
+  localFrameSize:  4096
+stack:
+  - { id: 0, size: 4096, alignment: 8 }
+  - { id: 1, type: variable-sized }
+body:             |
+  bb.0:
+    liveins: $xzr
+    ; CHECK-LABEL: name: func
+    ; CHECK: $xzr = frame-setup LDRXui $sp, 0
+    $x0 = COPY $xzr
+    RET_ReallyLR


        


More information about the llvm-commits mailing list