Skip to content

[RISCV] Correct Branch Range #142705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025

Conversation

lenary
Copy link
Member

@lenary lenary commented Jun 4, 2025

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.

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.
@lenary lenary requested a review from topperc June 4, 2025 00:36
@llvmbot
Copy link
Member

llvmbot commented Jun 4, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Sam Elliott (lenary)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/142705.diff

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp (+2-2)
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;
   }
 }
 

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lenary lenary merged commit 0248725 into llvm:main Jun 4, 2025
13 checks passed
@lenary lenary deleted the pr/riscv-branch-relax-fix-branch-range branch June 4, 2025 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants