[llvm] [BOLT][RISCV] Remove redundant AUIPCs when rewriting call pairs (PR #221965)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 04:37:26 PDT 2026
https://github.com/Thrrreeee created https://github.com/llvm/llvm-project/pull/221965
`FixRISCVCallsPass` leaves a `Noop` behind when converting an AUIPC/JALR pair into a call or tail-call pseudo. Add the `NOP` annotation so the existing RemoveNops pass can remove it, avoiding an unnecessary instruction in the output.
>From f02148f8c47ae23a34f0c902b93a12daee12aafc Mon Sep 17 00:00:00 2001
From: shijinrui <shijinrui at bytedance.com>
Date: Tue, 8 Sep 2026 19:36:16 +0800
Subject: [PATCH] [BOLT][RISCV] Remove redundant AUIPCs when rewriting call
pairs
---
bolt/lib/Passes/FixRISCVCallsPass.cpp | 2 ++
bolt/test/RISCV/call-link-register.s | 2 --
bolt/test/RISCV/relax.s | 3 +--
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/bolt/lib/Passes/FixRISCVCallsPass.cpp b/bolt/lib/Passes/FixRISCVCallsPass.cpp
index 3b4a75c8403890..27351a5945c528 100644
--- a/bolt/lib/Passes/FixRISCVCallsPass.cpp
+++ b/bolt/lib/Passes/FixRISCVCallsPass.cpp
@@ -55,6 +55,8 @@ void FixRISCVCallsPass::runOnFunction(BinaryFunction &BF) {
auto L = BC.scopeLock();
MIB->createNoop(*II);
+ // Mark the replacement NOP for removal by the later RemoveNops pass.
+ MIB->addAnnotation(*II, "NOP", static_cast<uint32_t>(1));
if (MIB->isTailCall(*NextII))
MIB->createTailCall(*NextII, Target, Ctx);
diff --git a/bolt/test/RISCV/call-link-register.s b/bolt/test/RISCV/call-link-register.s
index 9e8a12634a1570..c93f8713d16ee9 100644
--- a/bolt/test/RISCV/call-link-register.s
+++ b/bolt/test/RISCV/call-link-register.s
@@ -9,14 +9,12 @@
_start:
// CHECK-LABEL: <_start>:
/// The auipc of the pair, replaced by a nop once the call is rewritten.
-// CHECK-NEXT: nop
// CHECK-NEXT: jal t0, 0x{{.*}} <f>
call t0, f
/// A jal in direct range is rewritten on its own, with no auipc to nop out.
// CHECK-NEXT: jal t0, 0x{{.*}} <f>
jal t0, f
/// A call that already links through ra keeps ra.
-// CHECK-NEXT: nop
// CHECK-NEXT: jal 0x{{.*}} <f>
call f
// CHECK-NEXT: jal 0x{{.*}} <f>
diff --git a/bolt/test/RISCV/relax.s b/bolt/test/RISCV/relax.s
index 41124751f38e87..4f02ea3a22a345 100644
--- a/bolt/test/RISCV/relax.s
+++ b/bolt/test/RISCV/relax.s
@@ -18,9 +18,8 @@
// OBJDUMP: 0000000000600000 <_start>:
// OBJDUMP-NEXT: jal 0x600040 <near_f>
-// OBJDUMP-NEXT: nop
// OBJDUMP-NEXT: auipc ra, 0x200
-// OBJDUMP-NEXT: jalr 0x78(ra)
+// OBJDUMP-NEXT: jalr 0x7c(ra)
// OBJDUMP-NEXT: j 0x600040 <near_f>
// OBJDUMP: 0000000000600040 <near_f>:
// OBJDUMP: 0000000000800080 <far_f>:
More information about the llvm-commits
mailing list