[llvm] [RISCV] Correct Branch Range (PR #142705)

Sam Elliott via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 3 17:37:03 PDT 2025


https://github.com/lenary created https://github.com/llvm/llvm-project/pull/142705

This aligns the code with the other cases, which take into account the min/max range of `isShiftedInt<N, 1>`. Given IALIGN is always 16 or 32 (bits), this should not make a difference to anything valid.

>From 66349e279eb284332c9267b2a12333f562951974 Mon Sep 17 00:00:00 2001
From: Sam Elliott <quic_aelliott at quicinc.com>
Date: Tue, 3 Jun 2025 17:33:46 -0700
Subject: [PATCH] [RISCV] Correct Branch Range

This aligns the code with the other cases, which take into account the
min/max range of `isShiftedInt<N, 1>`. Given IALIGN is always 16 or 32
(bits), this should not make a difference to anything valid.
---
 llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 963501db118e7..cd527f188a284 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -133,8 +133,8 @@ bool RISCVAsmBackend::fixupNeedsRelaxationAdvanced(const MCFixup &Fixup,
   case RISCV::fixup_riscv_branch:
   case RISCV::fixup_riscv_qc_e_branch:
     // For conditional branch instructions the immediate must be
-    // in the range [-4096, 4095].
-    return !isInt<13>(Offset);
+    // in the range [-4096, 4094].
+    return Offset > 4094 || Offset < -4096;
   }
 }
 



More information about the llvm-commits mailing list