[llvm] [RISCV] Make analyzeBranch bail for INLINEASM_BR (PR #203835)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 14 23:54:07 PDT 2026
https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/203835
When working on the CodeGen BranchFolding pass, I ran into a case where analyzeBranch on RISC-V was returning that a branch was analyzeable for an INLINEASM_BR instruction, which probably shouldn't be the case. This was because we were going through the no terminators path, even though we do have an (opaque) terminator instruction.
No tests because it didn't seem like there was a good way to test this.
>From a87a42e982a56ac1cf3847de5343a52ce6d45725 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Mon, 15 Jun 2026 06:49:41 +0000
Subject: [PATCH] [RISCV] Make analyzeBranch bail for INLINEASM_BR
When working on the CodeGen BranchFolding pass, I ran into a case where
analyzeBranch on RISC-V was returning that a branch was analyzeable for
an INLINEASM_BR instruction, which probably shouldn't be the case. This
was because we were going through the no terminators path, even though
we do have an (opaque) terminator instruction.
No tests because it didn't seem like there was a good way to test this.
---
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index b31a3a7760d3b..ad1cb29918a91 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -1372,8 +1372,13 @@ bool RISCVInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
TBB = FBB = nullptr;
Cond.clear();
- // If the block has no terminators, it just falls into the block after it.
MachineBasicBlock::iterator I = MBB.getLastNonDebugInstr();
+ // If we end up with a INLINEASM_BR instruction, the actual branch
+ // information is opaque and thus unanalyzeable.
+ if (I != MBB.end() && I->getOpcode() == TargetOpcode::INLINEASM_BR)
+ return true;
+
+ // If the block has no terminators, it just falls into the block after it.
if (I == MBB.end() || !isUnpredicatedTerminator(*I))
return false;
More information about the llvm-commits
mailing list