Skip to content

Conversation

ParkHanbum
Copy link
Contributor

Critical edges with an IndirectBr terminator cannot be split.
Add a check it to prevent assertion failures.

Fixes : #150229

@llvmbot
Copy link
Member

llvmbot commented Jul 29, 2025

@llvm/pr-subscribers-llvm-transforms

Author: hanbeom (ParkHanbum)

Changes

Critical edges with an IndirectBr terminator cannot be split.
Add a check it to prevent assertion failures.

Fixes : #150229


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

2 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+3-1)
  • (modified) llvm/test/Transforms/GVN/cond_br.ll (+19)
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index f6bf09d09433d..196f68e2d06d8 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -3297,8 +3297,10 @@ void GVNPass::addDeadBlock(BasicBlock *BB) {
       if (!DeadBlocks.count(P))
         continue;
 
+      auto PredTerminator = P->getTerminator();
       if (is_contained(successors(P), B) &&
-          isCriticalEdge(P->getTerminator(), B)) {
+          !isa<IndirectBrInst>(PredTerminator) &&
+          isCriticalEdge(PredTerminator, B)) {
         if (BasicBlock *S = splitCriticalEdges(P, B))
           DeadBlocks.insert(P = S);
       }
diff --git a/llvm/test/Transforms/GVN/cond_br.ll b/llvm/test/Transforms/GVN/cond_br.ll
index 19166d17a8320..fb84b626c7455 100644
--- a/llvm/test/Transforms/GVN/cond_br.ll
+++ b/llvm/test/Transforms/GVN/cond_br.ll
@@ -53,3 +53,22 @@ if.end:                                           ; preds = %if.else, %if.then
 }
 
 declare void @bar(i32)
+
+define void @indirectbr_could_not_split() {
+; CHECK-LABEL: define void @indirectbr_could_not_split() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    br i1 false, label %[[IBR:.*]], label %[[EXIT:.*]]
+; CHECK:       [[IBR]]:
+; CHECK-NEXT:    indirectbr ptr null, [label %[[EXIT]], label %exit]
+; CHECK:       [[EXIT]]:
+; CHECK-NEXT:    ret void
+;
+entry:
+  br i1 false, label %ibr, label %exit
+
+ibr:
+  indirectbr ptr null, [label %exit, label %exit]
+
+exit:
+  ret void
+}

@nikic nikic self-requested a review July 29, 2025 20:15
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

This works, but I wonder whether it would be better to change SplitKnownCriticalEdge to convert the assertion into an if? SplitKnownCriticalEdge already has a bunch of other bailouts (e.g. for EH pads), so I'm not sure it makes sense to make this one thing an assert and force the caller to check it.

@ParkHanbum
Copy link
Contributor Author

@nikic at least no problem was found in the testcases when I modified SplitKnownCriticalEdge as you said. could I change it?

@nikic
Copy link
Contributor

nikic commented Jul 30, 2025

@nikic at least no problem was found in the testcases when I modified SplitKnownCriticalEdge as you said. could I change it?

Yes, I think that would be best.

Critical edges with an IndirectBr terminator cannot be split.
We have already handled it with Assertion, but change it to checking
whether block has IndirectBr terminator.

Fixes : llvm#150229
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@marcauberer marcauberer left a comment

Choose a reason for hiding this comment

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

thanks!

@nikic nikic merged commit a750fcb into llvm:main Aug 11, 2025
9 checks passed
@nikic nikic added this to the LLVM 21.x Release milestone Aug 11, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Aug 11, 2025
@nikic
Copy link
Contributor

nikic commented Aug 11, 2025

/cherry-pick a750fcb

@llvmbot
Copy link
Member

llvmbot commented Aug 11, 2025

/pull-request #152965

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Aug 11, 2025
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 11, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/25185

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll' FAILED ********************
Exit Code: 2

Command Output (stderr):
--
/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli -jit-kind=orc-lazy -compile-threads=2 -thread-entry hello /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll # RUN: at line 1
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli -jit-kind=orc-lazy -compile-threads=2 -thread-entry hello /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
 #0 0x0000000103bc9244 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100f05244)
 #1 0x0000000103bc6ff4 llvm::sys::RunSignalHandlers() (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100f02ff4)
 #2 0x0000000103bc9d44 SignalHandler(int, __siginfo*, void*) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100f05d44)
 #3 0x0000000184877584 (/usr/lib/system/libsystem_platform.dylib+0x18047b584)
 #4 0x000000018484621c (/usr/lib/system/libsystem_pthread.dylib+0x18044a21c)
 #5 0x000000018476cad0 (/usr/lib/libc++.1.dylib+0x180370ad0)
 #6 0x0000000103750820 void llvm::detail::UniqueFunctionBase<void, llvm::Expected<llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef>>>>::CallImpl<llvm::orc::Platform::lookupInitSymbols(llvm::orc::ExecutionSession&, llvm::DenseMap<llvm::orc::JITDylib*, llvm::orc::SymbolLookupSet, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::orc::SymbolLookupSet>> const&)::$_45>(void*, llvm::Expected<llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef>>>&) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100a8c820)
 #7 0x000000010374c454 llvm::orc::AsynchronousSymbolQuery::handleComplete(llvm::orc::ExecutionSession&)::RunQueryCompleteTask::run() (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100a88454)
 #8 0x0000000103814310 void* std::__1::__thread_proxy[abi:un170006]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, llvm::orc::DynamicThreadPoolTaskDispatcher::dispatch(std::__1::unique_ptr<llvm::orc::Task, std::__1::default_delete<llvm::orc::Task>>)::$_0>>(void*) (/Users/buildbot/buildbot-root/aarch64-darwin/build/bin/lli+0x100b50310)
 #9 0x0000000184846f94 (/usr/lib/system/libsystem_pthread.dylib+0x18044af94)
#10 0x0000000184841d34 (/usr/lib/system/libsystem_pthread.dylib+0x180445d34)
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll

--

********************


tru pushed a commit to llvmbot/llvm-project that referenced this pull request Aug 11, 2025
Critical edges with an IndirectBr terminator cannot be split.
Add a check it to prevent assertion failures.

Fixes: llvm#150229
(cherry picked from commit a750fcb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

[GVN] hits assertion "Cannot split critical edge from IndirectBrInst" in llvm::SplitKnownCriticalEdge
5 participants