[llvm] Hexagon: Don't duplicate the PC def when converting a return to L4_return (PR #225059)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 21 03:56:28 PDT 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/225059
When replacing a PS_jmpret return with L4_return in the epilogue, the code built
L4_return which automatically inserted pc and r29 implicit-defs. This then copied
the original return's implicit operands, duplicating the overlapped pc operand
(which also would have inconsistent dead flags). Also update a few mir test inputs
which demonstrate the duplicated operand pattern.
This avoids a future verifier check failure.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
>From a734ad908e616dd5d41682e9697812581386b761 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 18 Sep 2026 21:54:33 +0200
Subject: [PATCH] Hexagon: Don't duplicate the PC def when converting a return
to L4_return
When replacing a PS_jmpret return with L4_return in the epilogue, the code built
L4_return which automatically inserted pc and r29 implicit-defs. This then copied
the original return's implicit operands, duplicating the overlapped pc operand
(which also would have inconsistent dead flags). Also update a few mir test inputs
which demonstrate the duplicated operand pattern.
This avoids a future verifier check failure.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
---
llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp | 11 ++++++-----
llvm/test/CodeGen/Hexagon/copy-to-combine-const64.mir | 2 +-
.../CodeGen/MIR/Hexagon/bundled-call-site-info.mir | 2 +-
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
index efb70cf54d378..13a6fd6a9f68b 100644
--- a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp
@@ -1005,11 +1005,12 @@ void HexagonFrameLowering::insertEpilogueInBlock(MachineBasicBlock &MBB) const {
return;
}
unsigned NewOpc = Hexagon::L4_return;
- MachineInstr *NewI = BuildMI(MBB, RetI, dl, HII.get(NewOpc))
- .addDef(Hexagon::D15)
- .addReg(Hexagon::R30);
- // Transfer the function live-out registers.
- NewI->copyImplicitOps(MF, *RetI);
+ MachineInstrBuilder NewI = BuildMI(MBB, RetI, dl, HII.get(NewOpc))
+ .addDef(Hexagon::D15)
+ .addReg(Hexagon::R30);
+ // Avoid duplicating the pc implicit-def.
+ for (const MachineOperand &MO : drop_begin(RetI->implicit_operands()))
+ NewI.add(MO);
MBB.erase(RetI);
} else {
// L2_deallocframe instruction after it.
diff --git a/llvm/test/CodeGen/Hexagon/copy-to-combine-const64.mir b/llvm/test/CodeGen/Hexagon/copy-to-combine-const64.mir
index ec2a55bb5ff9d..14c219bec35b9 100644
--- a/llvm/test/CodeGen/Hexagon/copy-to-combine-const64.mir
+++ b/llvm/test/CodeGen/Hexagon/copy-to-combine-const64.mir
@@ -25,5 +25,5 @@ body: |
$r1 = A2_tfrsi 32768
$r2 = A2_tfrsi 1
J2_call @f1, hexagoncsr, implicit-def dead $pc, implicit-def dead $r31, implicit $r29, implicit killed $r0, implicit killed $r1, implicit killed $r2, implicit-def $r29
- $d15 = L4_return $r30, implicit-def $pc, implicit-def $r29, implicit $framekey, implicit-def dead $pc
+ $d15 = L4_return $r30, implicit-def $pc, implicit-def $r29, implicit $framekey
...
diff --git a/llvm/test/CodeGen/MIR/Hexagon/bundled-call-site-info.mir b/llvm/test/CodeGen/MIR/Hexagon/bundled-call-site-info.mir
index cdcfdae270341..3c018713913a9 100644
--- a/llvm/test/CodeGen/MIR/Hexagon/bundled-call-site-info.mir
+++ b/llvm/test/CodeGen/MIR/Hexagon/bundled-call-site-info.mir
@@ -43,7 +43,7 @@ body: |
}
BUNDLE implicit-def dead $r0, implicit-def $d15, implicit-def $r30, implicit-def $r31, implicit-def $pc, implicit-def $r29, implicit killed $r30, implicit killed $framekey {
$r0 = A2_tfrsi 0
- $d15 = L4_return killed $r30, implicit-def $pc, implicit-def $r29, implicit killed $framekey, implicit-def dead $pc, implicit internal killed $r0
+ $d15 = L4_return killed $r30, implicit-def $pc, implicit-def $r29, implicit killed $framekey, implicit internal killed $r0
}
...
More information about the llvm-commits
mailing list