[llvm] [RISCV] Make analyzeBranch bail for INLINEASM_BR (PR #203835)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 14 23:54:57 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/203835.diff
1 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfo.cpp (+6-1)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/203835
More information about the llvm-commits
mailing list