[llvm] Sparc: Mark GETPCX scratch %o7 def dead (PR #227676)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 04:59:36 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/227676

The GETPCX expansion uses %o7 only inside the emitted sequence, so the
implicit def is dead. Set the flag when the pseudo is built instead of
leaving it for later recovery.

Co-authored-by: Claude Opus 5 <noreply at anthropic.com>

>From 2b45add61fc453d105e7b18828c3e19d1d753986 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 29 Sep 2026 01:20:44 +0200
Subject: [PATCH] Sparc: Mark GETPCX scratch %o7 def dead

The GETPCX expansion uses %o7 only inside the emitted sequence, so the
implicit def is dead. Set the flag when the pseudo is built instead of
leaving it for later recovery.

Co-authored-by: Claude Opus 5 <noreply at anthropic.com>
---
 llvm/lib/Target/Sparc/SparcInstrInfo.cpp  |  3 ++-
 llvm/test/CodeGen/SPARC/getpcx-dead-o7.ll | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/SPARC/getpcx-dead-o7.ll

diff --git a/llvm/lib/Target/Sparc/SparcInstrInfo.cpp b/llvm/lib/Target/Sparc/SparcInstrInfo.cpp
index 3f6023b8c0706..0a7ce19bf4f51 100644
--- a/llvm/lib/Target/Sparc/SparcInstrInfo.cpp
+++ b/llvm/lib/Target/Sparc/SparcInstrInfo.cpp
@@ -656,7 +656,8 @@ Register SparcInstrInfo::getGlobalBaseReg(MachineFunction *MF) const {
 
   DebugLoc dl;
 
-  BuildMI(FirstMBB, MBBI, dl, get(SP::GETPCX), GlobalBaseReg);
+  BuildMI(FirstMBB, MBBI, dl, get(SP::GETPCX), GlobalBaseReg)
+      .setOperandDead(1); // implicit-def $o7
   SparcFI->setGlobalBaseReg(GlobalBaseReg);
   return GlobalBaseReg;
 }
diff --git a/llvm/test/CodeGen/SPARC/getpcx-dead-o7.ll b/llvm/test/CodeGen/SPARC/getpcx-dead-o7.ll
new file mode 100644
index 0000000000000..37d839b4a242d
--- /dev/null
+++ b/llvm/test/CodeGen/SPARC/getpcx-dead-o7.ll
@@ -0,0 +1,18 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=sparc -relocation-model=pic -stop-after=finalize-isel -o - %s | FileCheck %s
+
+ at g = external global i32
+
+define i32 @f() {
+  ; CHECK-LABEL: name: f
+  ; CHECK: bb.0 (%ir-block.0):
+  ; CHECK-NEXT:   [[GETPCX:%[0-9]+]]:intregs = GETPCX implicit-def dead $o7
+  ; CHECK-NEXT:   [[SETHIi:%[0-9]+]]:intregs = SETHIi target-flags(<unknown>) @g
+  ; CHECK-NEXT:   [[ADDri:%[0-9]+]]:intregs = ADDri killed [[SETHIi]], target-flags(<unknown>) @g
+  ; CHECK-NEXT:   [[LDrr:%[0-9]+]]:intregs = LDrr [[GETPCX]], killed [[ADDri]] :: (load (s32) from got)
+  ; CHECK-NEXT:   [[LDrr1:%[0-9]+]]:intregs = LDrr killed [[LDrr]], $g0 :: (dereferenceable load (s32) from @g)
+  ; CHECK-NEXT:   $i0 = COPY [[LDrr1]]
+  ; CHECK-NEXT:   RETL 8, implicit $i0
+  %v = load i32, ptr @g
+  ret i32 %v
+}



More information about the llvm-commits mailing list