[llvm] Fix the inaccurate profile data check (PR #189331)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 30 00:34:58 PDT 2026


https://github.com/WangJee created https://github.com/llvm/llvm-project/pull/189331

The error is caused by the fact that when acquiring the profile data, the instruction at offset is PseudoCALL, but when performing profile verification, PseudoCALL is converted to AUIPC and JALR instructions, and the offset obtained is JALR; therefore, the profile data is considered invalid.

>From 1ab8f114684d6c3b515e69bcc61aa627d0541b42 Mon Sep 17 00:00:00 2001
From: "wangjue.wangjue" <wangjue.wangjue at alibaba-inc.com>
Date: Mon, 30 Mar 2026 07:31:11 +0000
Subject: [PATCH] Fix the inaccurate profile data check

---
 bolt/lib/Core/BinaryFunction.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index c5aefe685de34..0de2d80161cd6 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -4745,10 +4745,18 @@ MCInst *BinaryFunction::getInstructionAtOffset(uint64_t Offset) {
     if (!BB)
       return nullptr;
 
+    MCInst preInst = nullptr;
     for (MCInst &Inst : *BB) {
       constexpr uint32_t InvalidOffset = std::numeric_limits<uint32_t>::max();
       if (Offset == BC.MIB->getOffsetWithDefault(Inst, InvalidOffset))
         return &Inst;
+      // If it's a RISCV PseudoCALL - fix it
+      if (preInst &&
+          Offset == BC.MIB->getOffsetWithDefault(Inst, InvalidOffset) - 4) {
+        if (BC.MIB->isRISCVCall(preInst, Inst))
+          return &Inst;
+      }
+      preInst = Inst;
     }
 
     if (MCInst *LastInstr = BB->getLastNonPseudoInstr()) {



More information about the llvm-commits mailing list