[llvm] Mips: Mark the assembler temporary def dead in FastISel branches (PR #227689)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 30 05:50:31 PDT 2026


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

The conditional branch emitted by FastISel reserves $at for long branch
expansion, which only uses it as a scratch.

Co-Authored-By: Claude Opus 5 <noreply at anthropic.com>

>From dd811ec95604278f5e614224f3bcc5e13dbf2301 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 29 Sep 2026 02:23:41 +0200
Subject: [PATCH] Mips: Mark the assembler temporary def dead in FastISel
 branches

The conditional branch emitted by FastISel reserves $at for long branch
expansion, which only uses it as a scratch.

Co-Authored-By: Claude Opus 5 <noreply at anthropic.com>
---
 llvm/lib/Target/Mips/MipsFastISel.cpp         |  3 +-
 .../CodeGen/Mips/Fast-ISel/branch-dead-at.ll  | 31 +++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/Mips/Fast-ISel/branch-dead-at.ll

diff --git a/llvm/lib/Target/Mips/MipsFastISel.cpp b/llvm/lib/Target/Mips/MipsFastISel.cpp
index 7d1f024002eaf..c25f1d71090a7 100644
--- a/llvm/lib/Target/Mips/MipsFastISel.cpp
+++ b/llvm/lib/Target/Mips/MipsFastISel.cpp
@@ -983,7 +983,8 @@ bool MipsFastISel::selectBranch(const Instruction *I) {
 
   BuildMI(*BrBB, FuncInfo.InsertPt, MIMD, TII.get(Mips::BGTZ))
       .addReg(ZExtCondReg)
-      .addMBB(TBB);
+      .addMBB(TBB)
+      .setOperandDead(2); // implicit-def $at
   finishCondBranch(BI->getParent(), TBB, FBB);
   return true;
 }
diff --git a/llvm/test/CodeGen/Mips/Fast-ISel/branch-dead-at.ll b/llvm/test/CodeGen/Mips/Fast-ISel/branch-dead-at.ll
new file mode 100644
index 0000000000000..5f1f63b205a58
--- /dev/null
+++ b/llvm/test/CodeGen/Mips/Fast-ISel/branch-dead-at.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=mipsel-elf -relocation-model=pic -O0 -fast-isel=true -mcpu=mips32r2 \
+; RUN:     -stop-after=finalize-isel < %s | FileCheck %s
+
+; The assembler temporary clobbered by long branch expansion is dead.
+
+define void @cond_br(i1 %c) {
+  ; CHECK-LABEL: name: cond_br
+  ; CHECK: bb.0 (%ir-block.0):
+  ; CHECK-NEXT:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
+  ; CHECK-NEXT:   liveins: $a0
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gpr32 = COPY $a0
+  ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:gpr32 = COPY [[COPY]]
+  ; CHECK-NEXT:   [[ANDi:%[0-9]+]]:gpr32 = ANDi [[COPY1]], 1
+  ; CHECK-NEXT:   BGTZ [[ANDi]], %bb.1, implicit-def dead $at
+  ; CHECK-NEXT:   B %bb.2, implicit-def $at
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.1 (%ir-block.1):
+  ; CHECK-NEXT:   RetRA
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.2 (%ir-block.2):
+  ; CHECK-NEXT:   RetRA
+  br i1 %c, label %1, label %2
+
+1:
+  ret void
+
+2:
+  ret void
+}



More information about the llvm-commits mailing list