Bug type: crash
Component: BreakCriticalEdges
Bug location: llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp: llvm::SplitKnownCriticalEdge
Issue title: [GVN] hits assertion "Cannot split critical edge from IndirectBrInst" in llvm::SplitKnownCriticalEdge
Labels: crash
llvm:GVN
Reported by: tetzank

The gvn pass cannot handle the indirectbr instruction with more than one destination. It hits an assertion in llvm::SplitKnownCriticalEdge trying to add a "dead" block after the indirectbr.
The newgvn pass works fine.

Reproducer:
```llvm
define void @foo(i1 %cmp) {
first:
  br i1 %cmp, label %exit, label %second

second:
  br i1 %cmp, label %ibr, label %exit ; cmp must be false to reach this, branch to ibr never taken

ibr: ; this block is dead
  indirectbr ptr blockaddress(@foo, %exit), [label %exit, label %exit] ; double label required, works with just one

exit:
  ret void
}
```

`opt --passes=gvn -S minimal.ll`

Related Bug: https://github.com/llvm/llvm-project/issues/49237

Comments: author: tetzank
body: Even smaller reproducer:
```llvm
define void @foo() {
entry:
  br i1 false, label %ibr, label %exit

ibr: ; this block is dead
  indirectbr ptr null, [label %exit, label %exit]

exit:
  ret void
}
```
author: hstk30-hw
body: Is the same issue with https://github.com/llvm/llvm-project/issues/147869? 
@jacobly0 @nikic 
author: ParkHanbum
body: @hstk30-hw I think it's a different issue, this issue arises in the process of separating critical edges. but it can be fix as same way. IMO
author: ParkHanbum
body: @nikic @dtcxzyw Now that I'm a committer, I can assign this issue to myself, but this is my first time, so I'm asking. Can I assign this issue to myself?
author: nikic
body: @ParkHanbum Feel free to assign.

Critical edges on indirectbr cannot be split, so we need to bail out in this case.

Fix patch:
commit a750fcb52bbf0ec0dc2022f73b1d48a4d43d8a07
Author: hanbeom <kese111@gmail.com>
Date:   Mon Aug 11 16:25:52 2025 +0900

    [GVN] Check IndirectBr in Predecessor Terminators (#151188)
    
    Critical edges with an IndirectBr terminator cannot be split.
    Add a check it to prevent assertion failures.
    
    Fixes: #150229

diff --git a/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp b/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
index ddd203f3acf7..42b1fdf17f38 100644
--- a/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
+++ b/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
@@ -111,15 +111,14 @@ BasicBlock *
 llvm::SplitKnownCriticalEdge(Instruction *TI, unsigned SuccNum,
                              const CriticalEdgeSplittingOptions &Options,
                              const Twine &BBName) {
-  assert(!isa<IndirectBrInst>(TI) &&
-         "Cannot split critical edge from IndirectBrInst");
-
   BasicBlock *TIBB = TI->getParent();
   BasicBlock *DestBB = TI->getSuccessor(SuccNum);
 
-  // Splitting the critical edge to a pad block is non-trivial. Don't do
-  // it in this generic function.
-  if (DestBB->isEHPad()) return nullptr;
+  // Splitting the critical edge to a pad block is non-trivial.
+  // And we cannot split block with IndirectBr as a terminator.
+  // Don't do it in this generic function.
+  if (DestBB->isEHPad() || isa<IndirectBrInst>(TI))
+    return nullptr;
 
   if (Options.IgnoreUnreachableDests &&
       isa<UnreachableInst>(DestBB->getFirstNonPHIOrDbgOrLifetime()))


Regression tests:
file: llvm/test/Transforms/GVN/cond_br.ll
commands: opt -passes=gvn -S < %s
tests: test_name: indirectbr_could_not_split
test_body: define void @indirectbr_could_not_split() {
entry:
  br i1 false, label %ibr, label %exit

ibr:                                              ; preds = %entry
  indirectbr ptr null, [label %exit, label %exit]

exit:                                             ; preds = %ibr, %ibr, %entry
  ret void
}