Skip to content

[BasicBlockUtils] Fix dominator tree update for entry block in splitBlockBefore()#178895

Merged
Enna1 merged 5 commits intollvm:mainfrom
Enna1:splitBlockBefore-DomTreeUpdater
Feb 3, 2026
Merged

[BasicBlockUtils] Fix dominator tree update for entry block in splitBlockBefore()#178895
Enna1 merged 5 commits intollvm:mainfrom
Enna1:splitBlockBefore-DomTreeUpdater

Conversation

@Enna1
Copy link
Contributor

@Enna1 Enna1 commented Jan 30, 2026

06dfbb5 fixed dominator update for entry block in SplitBlockPredecessors(), this patch fixes dominator tree update for entry block in splitBlockBefore() with UpdateAnalysisInformation().

Enna1 added 2 commits January 30, 2026 22:17
…lockBefore()

Domoninator update for entry block in `SplitBlockPredecessors()` was fixed by
06dfbb5 , this patch fixes dominator
tree update for entry block in `splitBlockBefore()` with
`UpdateAnalysisInformation()`.
@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2026

@llvm/pr-subscribers-llvm-transforms

Author: Mingjie Xu (Enna1)

Changes

06dfbb5 fixed domoninator update for entry block in SplitBlockPredecessors(), this patch fixes dominator tree update for entry block in splitBlockBefore() with UpdateAnalysisInformation().


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

2 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/BasicBlockUtils.cpp (+21-45)
  • (modified) llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp (+25)
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index b0c04086f5e84..12206e14ca8fd 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1064,51 +1064,6 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt,
                         Before);
 }
 
-BasicBlock *llvm::splitBlockBefore(BasicBlock *Old, BasicBlock::iterator SplitPt,
-                                   DomTreeUpdater *DTU, LoopInfo *LI,
-                                   MemorySSAUpdater *MSSAU,
-                                   const Twine &BBName) {
-
-  BasicBlock::iterator SplitIt = SplitPt;
-  while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
-    ++SplitIt;
-  std::string Name = BBName.str();
-  BasicBlock *New = Old->splitBasicBlock(
-      SplitIt, Name.empty() ? Old->getName() + ".split" : Name,
-      /* Before=*/true);
-
-  // The new block lives in whichever loop the old one did. This preserves
-  // LCSSA as well, because we force the split point to be after any PHI nodes.
-  if (LI)
-    if (Loop *L = LI->getLoopFor(Old))
-      L->addBasicBlockToLoop(New, *LI);
-
-  if (DTU) {
-    SmallVector<DominatorTree::UpdateType, 8> DTUpdates;
-    // New dominates Old. The predecessor nodes of the Old node dominate
-    // New node.
-    SmallPtrSet<BasicBlock *, 8> UniquePredecessorsOfOld;
-    DTUpdates.push_back({DominatorTree::Insert, New, Old});
-    DTUpdates.reserve(DTUpdates.size() + 2 * pred_size(New));
-    for (BasicBlock *PredecessorOfOld : predecessors(New))
-      if (UniquePredecessorsOfOld.insert(PredecessorOfOld).second) {
-        DTUpdates.push_back({DominatorTree::Insert, PredecessorOfOld, New});
-        DTUpdates.push_back({DominatorTree::Delete, PredecessorOfOld, Old});
-      }
-
-    DTU->applyUpdates(DTUpdates);
-
-    // Move MemoryAccesses still tracked in Old, but part of New now.
-    // Update accesses in successor blocks accordingly.
-    if (MSSAU) {
-      MSSAU->applyUpdates(DTUpdates, DTU->getDomTree());
-      if (VerifyMemorySSA)
-        MSSAU->getMemorySSA()->verifyMemorySSA();
-    }
-  }
-  return New;
-}
-
 /// Update DominatorTree, LoopInfo, and LCCSA analysis information.
 /// Invalidates DFS Numbering when DTU or DT is provided.
 static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
@@ -1223,6 +1178,27 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
   }
 }
 
+BasicBlock *llvm::splitBlockBefore(BasicBlock *Old,
+                                   BasicBlock::iterator SplitPt,
+                                   DomTreeUpdater *DTU, LoopInfo *LI,
+                                   MemorySSAUpdater *MSSAU,
+                                   const Twine &BBName) {
+  BasicBlock::iterator SplitIt = SplitPt;
+  while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
+    ++SplitIt;
+  SmallVector<BasicBlock *, 4> Preds(predecessors(Old));
+  std::string Name = BBName.str();
+  BasicBlock *New = Old->splitBasicBlock(
+      SplitIt, Name.empty() ? Old->getName() + ".split" : Name,
+      /* Before=*/true);
+
+  bool HasLoopExit = false;
+  UpdateAnalysisInformation(Old, New, Preds, DTU, nullptr, LI, MSSAU, false,
+                            HasLoopExit);
+
+  return New;
+}
+
 /// Update the PHI nodes in OrigBB to include the values coming from NewBB.
 /// This also updates AliasAnalysis, if available.
 static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB,
diff --git a/llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp b/llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp
index 00d9e9ff81e05..d5b4f6b6d6593 100644
--- a/llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp
+++ b/llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp
@@ -378,6 +378,31 @@ define i32 @no_unreachable(i1 %cond) {
   EXPECT_TRUE(DT.verify());
 }
 
+TEST(BasicBlockUtils, splitBlockBefore) {
+  LLVMContext C;
+  std::unique_ptr<Module> M = parseIR(C, R"IR(
+define i32 @basic_func(i1 %cond) {
+entry:
+  br i1 %cond, label %bb0, label %bb1
+bb0:
+  br label %bb1
+bb1:
+  %phi = phi i32 [ 0, %entry ], [ 1, %bb0 ]
+  ret i32 %phi
+}
+)IR");
+  Function *F = M->getFunction("basic_func");
+  DominatorTree DT(*F);
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
+  BasicBlock *EntryBB = &F->getEntryBlock();
+  Instruction *TI = EntryBB->getTerminator();
+
+  // Make sure the dominator tree is properly updated if calling this on the
+  // entry block.
+  splitBlockBefore(EntryBB, TI, &DTU, nullptr, nullptr);
+  EXPECT_TRUE(DTU.getDomTree().verify());
+}
+
 TEST(BasicBlockUtils, SplitBlockPredecessors) {
   LLVMContext C;
   std::unique_ptr<Module> M = parseIR(C, R"IR(

@Enna1 Enna1 requested review from arsenm and nikic January 30, 2026 15:16
while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
++SplitIt;
SmallVector<BasicBlock *, 4> Preds(predecessors(Old));
std::string Name = BBName.str();
Copy link
Contributor

Choose a reason for hiding this comment

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

No intermediate std::string

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

Comment on lines 1190 to 1192
BasicBlock *New = Old->splitBasicBlock(
SplitIt, BBName.isTriviallyEmpty() ? Old->getName() + ".split" : BBName,
/* Before=*/true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
BasicBlock *New = Old->splitBasicBlock(
SplitIt, BBName.isTriviallyEmpty() ? Old->getName() + ".split" : BBName,
/* Before=*/true);
BasicBlock *New = Old->splitBasicBlockBefore(
SplitIt, BBName.isTriviallyEmpty() ? Old->getName() + ".split" : BBName);

@Enna1 Enna1 merged commit ad8d534 into llvm:main Feb 3, 2026
10 checks passed
@llvm-ci
Copy link

llvm-ci commented Feb 3, 2026

LLVM Buildbot has detected a new failure on builder flang-x86_64-windows running on minipc-ryzen-win while building llvm at step 8 "test-build-unified-tree-check-flang-rt".

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

Here is the relevant piece of the build log for the reference
Step 8 (test-build-unified-tree-check-flang-rt) failure: test (failure)
******************** TEST 'flang-rt-Unit :: Runtime/./RuntimeTests.exe/5/8' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:C:\buildbot\flang-x86_64-windows\build\runtimes\runtimes-bins\flang-rt\unittests\Runtime\.\RuntimeTests.exe-flang-rt-Unit-2436-5-8.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=8 GTEST_SHARD_INDEX=5 C:\buildbot\flang-x86_64-windows\build\runtimes\runtimes-bins\flang-rt\unittests\Runtime\.\RuntimeTests.exe
--

Script:
--
C:\buildbot\flang-x86_64-windows\build\runtimes\runtimes-bins\flang-rt\unittests\Runtime\.\RuntimeTests.exe --gtest_filter=Reductions.InfSums
--
C:/buildbot/flang-x86_64-windows/llvm-project/flang-rt/unittests/Runtime/Reduction.cpp(681): error: Expected equality of these values:
  t1
    Which is: -nan
  inf
-nan


C:/buildbot/flang-x86_64-windows/llvm-project/flang-rt/unittests/Runtime/Reduction.cpp:681
Expected equality of these values:
  t1
    Which is: -nan
  inf
-nan



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


@llvm-ci
Copy link

llvm-ci commented Feb 3, 2026

LLVM Buildbot has detected a new failure on builder clang-riscv-gauntlet running on rise-worker-1 while building llvm at step 4 "annotate".

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

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: '../llvm-zorg/zorg/buildbot/builders/annotated/rise-riscv-gauntlet-build.sh --jobs=32' (failure)
...
[4975/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20120919-1
[4976/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20140212-1
[4977/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20140622-1
[4978/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20120817-1
[4979/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20141022-1
[4980/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20140425-1
[4981/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20170111-1
[4982/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20140828-1
[4983/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20141107-1
[4984/6080] Building CXX object SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o
FAILED: [code=1] SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o 
/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang++ --target=riscv32-linux-gnu --sysroot=/home/buildbot-worker/bbroot/clang-riscv-gauntlet/../rvsysroot32 -DNDEBUG  -march=rv32gcv -DSMALL_PROBLEM_SIZE    -O3 -DNDEBUG -std=gnu++14   -w -Werror=date-time -pthread -MD -MT SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o -MF SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o.d -o SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o -c /home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-test-suite/SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp
clang++: ../../llvm/lib/Transforms/Utils/BasicBlockUtils.cpp:1106: void UpdateAnalysisInformation(BasicBlock *, BasicBlock *, ArrayRef<BasicBlock *>, DomTreeUpdater *, DominatorTree *, LoopInfo *, MemorySSAUpdater *, bool, bool &): Assertion `DT && "DT should be available to update LoopInfo!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang++ --target=riscv32-linux-gnu --sysroot=/home/buildbot-worker/bbroot/clang-riscv-gauntlet/../rvsysroot32 -DNDEBUG -march=rv32gcv -DSMALL_PROBLEM_SIZE -O3 -DNDEBUG -std=gnu++14 -w -Werror=date-time -pthread -MD -MT SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o -MF SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o.d -o SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o -c /home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-test-suite/SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-test-suite/SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp'.
4.	Running pass 'CodeGen Prepare' on function '@_ZN9c_grammar10definitionIN5boost6spirit7scannerIPKcNS2_16scanner_policiesINS2_28skip_parser_iteration_policyI12skip_grammarNS2_16iteration_policyEEENS2_12match_policyENS2_13action_policyEEEEEEC2ERKS_'
 #0 0x0000563df5d46fa6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5040fa6)
 #1 0x0000563df5d444e5 llvm::sys::RunSignalHandlers() (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x503e4e5)
 #2 0x0000563df5ca295d CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f5a3803e4d0 (/usr/lib/libc.so.6+0x3e4d0)
 #4 0x00007f5a3809890c (/usr/lib/libc.so.6+0x9890c)
 #5 0x00007f5a3803e3a0 raise (/usr/lib/libc.so.6+0x3e3a0)
 #6 0x00007f5a3802557a abort (/usr/lib/libc.so.6+0x2557a)
 #7 0x00007f5a380254e3 __assert_perror_fail (/usr/lib/libc.so.6+0x254e3)
 #8 0x0000563df5d8fde1 UpdateAnalysisInformation(llvm::BasicBlock*, llvm::BasicBlock*, llvm::ArrayRef<llvm::BasicBlock*>, llvm::DomTreeUpdater*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, bool, bool&) BasicBlockUtils.cpp:0:0
 #9 0x0000563df5d8f3bb llvm::splitBlockBefore(llvm::BasicBlock*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, false>, llvm::DomTreeUpdater*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, llvm::Twine const&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x50893bb)
#10 0x0000563df5d8cb08 llvm::SplitEdge(llvm::BasicBlock*, llvm::BasicBlock*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, llvm::Twine const&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5086b08)
#11 0x0000563df4ff5b59 (anonymous namespace)::CodeGenPrepare::splitLargeGEPOffsets()::$_1::operator()(long, llvm::Value*, llvm::GetElementPtrInst*) const CodeGenPrepare.cpp:0:0
#12 0x0000563df4fc0ec8 (anonymous namespace)::CodeGenPrepare::_run(llvm::Function&) CodeGenPrepare.cpp:0:0
#13 0x0000563df4fbb36c (anonymous namespace)::CodeGenPrepareLegacyPass::runOnFunction(llvm::Function&) CodeGenPrepare.cpp:0:0
#14 0x0000563df5796719 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x4a90719)
#15 0x0000563df579e942 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x4a98942)
#16 0x0000563df57971e7 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x4a911e7)
#17 0x0000563df654b1a5 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x58451a5)
#18 0x0000563df655fea4 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5859ea4)
#19 0x0000563df8277519 clang::ParseAST(clang::Sema&, bool, bool) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x7571519)
#20 0x0000563df6aee0f4 clang::FrontendAction::Execute() (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5de80f4)
#21 0x0000563df6a48ebd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5d42ebd)
#22 0x0000563df6bee472 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5ee8472)
#23 0x0000563df4626606 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x3920606)
#24 0x0000563df46222f5 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#25 0x0000563df4624998 int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::$_0>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#26 0x0000563df688e969 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) Job.cpp:0:0
#27 0x0000563df5ca263e llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x4f9c63e)
#28 0x0000563df688e154 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5b88154)
Step 23 (rv32gcv: llvm-test-suite build) failure: rv32gcv: llvm-test-suite build (failure)
...
[4975/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20120919-1
[4976/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20140212-1
[4977/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20140622-1
[4978/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20120817-1
[4979/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20141022-1
[4980/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20140425-1
[4981/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20170111-1
[4982/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20140828-1
[4983/6080] Linking C executable SingleSource/Regression/C/gcc-c-torture/execute/GCC-C-execute-20141107-1
[4984/6080] Building CXX object SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o
FAILED: [code=1] SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o 
/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang++ --target=riscv32-linux-gnu --sysroot=/home/buildbot-worker/bbroot/clang-riscv-gauntlet/../rvsysroot32 -DNDEBUG  -march=rv32gcv -DSMALL_PROBLEM_SIZE    -O3 -DNDEBUG -std=gnu++14   -w -Werror=date-time -pthread -MD -MT SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o -MF SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o.d -o SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o -c /home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-test-suite/SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp
clang++: ../../llvm/lib/Transforms/Utils/BasicBlockUtils.cpp:1106: void UpdateAnalysisInformation(BasicBlock *, BasicBlock *, ArrayRef<BasicBlock *>, DomTreeUpdater *, DominatorTree *, LoopInfo *, MemorySSAUpdater *, bool, bool &): Assertion `DT && "DT should be available to update LoopInfo!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang++ --target=riscv32-linux-gnu --sysroot=/home/buildbot-worker/bbroot/clang-riscv-gauntlet/../rvsysroot32 -DNDEBUG -march=rv32gcv -DSMALL_PROBLEM_SIZE -O3 -DNDEBUG -std=gnu++14 -w -Werror=date-time -pthread -MD -MT SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o -MF SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o.d -o SingleSource/Benchmarks/Misc-C++-EH/CMakeFiles/spirit.dir/spirit.cpp.o -c /home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-test-suite/SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-test-suite/SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp'.
4.	Running pass 'CodeGen Prepare' on function '@_ZN9c_grammar10definitionIN5boost6spirit7scannerIPKcNS2_16scanner_policiesINS2_28skip_parser_iteration_policyI12skip_grammarNS2_16iteration_policyEEENS2_12match_policyENS2_13action_policyEEEEEEC2ERKS_'
 #0 0x0000563df5d46fa6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5040fa6)
 #1 0x0000563df5d444e5 llvm::sys::RunSignalHandlers() (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x503e4e5)
 #2 0x0000563df5ca295d CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f5a3803e4d0 (/usr/lib/libc.so.6+0x3e4d0)
 #4 0x00007f5a3809890c (/usr/lib/libc.so.6+0x9890c)
 #5 0x00007f5a3803e3a0 raise (/usr/lib/libc.so.6+0x3e3a0)
 #6 0x00007f5a3802557a abort (/usr/lib/libc.so.6+0x2557a)
 #7 0x00007f5a380254e3 __assert_perror_fail (/usr/lib/libc.so.6+0x254e3)
 #8 0x0000563df5d8fde1 UpdateAnalysisInformation(llvm::BasicBlock*, llvm::BasicBlock*, llvm::ArrayRef<llvm::BasicBlock*>, llvm::DomTreeUpdater*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, bool, bool&) BasicBlockUtils.cpp:0:0
 #9 0x0000563df5d8f3bb llvm::splitBlockBefore(llvm::BasicBlock*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, false>, llvm::DomTreeUpdater*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, llvm::Twine const&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x50893bb)
#10 0x0000563df5d8cb08 llvm::SplitEdge(llvm::BasicBlock*, llvm::BasicBlock*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, llvm::Twine const&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5086b08)
#11 0x0000563df4ff5b59 (anonymous namespace)::CodeGenPrepare::splitLargeGEPOffsets()::$_1::operator()(long, llvm::Value*, llvm::GetElementPtrInst*) const CodeGenPrepare.cpp:0:0
#12 0x0000563df4fc0ec8 (anonymous namespace)::CodeGenPrepare::_run(llvm::Function&) CodeGenPrepare.cpp:0:0
#13 0x0000563df4fbb36c (anonymous namespace)::CodeGenPrepareLegacyPass::runOnFunction(llvm::Function&) CodeGenPrepare.cpp:0:0
#14 0x0000563df5796719 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x4a90719)
#15 0x0000563df579e942 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x4a98942)
#16 0x0000563df57971e7 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x4a911e7)
#17 0x0000563df654b1a5 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x58451a5)
#18 0x0000563df655fea4 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5859ea4)
#19 0x0000563df8277519 clang::ParseAST(clang::Sema&, bool, bool) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x7571519)
#20 0x0000563df6aee0f4 clang::FrontendAction::Execute() (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5de80f4)
#21 0x0000563df6a48ebd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5d42ebd)
#22 0x0000563df6bee472 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5ee8472)
#23 0x0000563df4626606 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x3920606)
#24 0x0000563df46222f5 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#25 0x0000563df4624998 int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::$_0>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#26 0x0000563df688e969 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) Job.cpp:0:0
#27 0x0000563df5ca263e llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x4f9c63e)
#28 0x0000563df688e154 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/buildbot-worker/bbroot/clang-riscv-gauntlet/llvm-project/build/stage1/bin/clang+++0x5b88154)

Enna1 added a commit to Enna1/llvm-project that referenced this pull request Feb 3, 2026
Enna1 added a commit that referenced this pull request Feb 3, 2026
Enna1 added a commit that referenced this pull request Feb 3, 2026
nikic pushed a commit to nikic/llvm-project that referenced this pull request Feb 3, 2026
Enna1 added a commit that referenced this pull request Feb 3, 2026
…n splitBlockBefore() (#178895) (#179392)

#178895 caused a clang
crash(see https://lab.llvm.org/buildbot/#/builders/210/builds/8229),
reverted in 6d52d26.

The crash is assertion `DT && "DT should be available to update
LoopInfo!"' failed.

https://github.com/llvm/llvm-project/blob/ad8d5349d46734826aaeae4a2ebdc6f427a5bad8/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp#L1106

```
 #7 0x00007f5a380254e3 __assert_perror_fail (/usr/lib/libc.so.6+0x254e3)
 #8 0x0000563df5d8fde1 UpdateAnalysisInformation(llvm::BasicBlock*, llvm::BasicBlock*, llvm::ArrayRef<llvm::BasicBlock*>, llvm::DomTreeUpdater*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, bool, bool&) BasicBlockUtils.cpp:0:0
 #9 0x0000563df5d8f3bb llvm::splitBlockBefore(llvm::BasicBlock*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, false>, llvm::DomTreeUpdater*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, llvm::Twine const&)
#10 0x0000563df5d8cb08 llvm::SplitEdge(llvm::BasicBlock*, llvm::BasicBlock*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, llvm::Twine const&)
#11 0x0000563df4ff5b59 (anonymous namespace)::CodeGenPrepare::splitLargeGEPOffsets()::$_1::operator()(long, llvm::Value*, llvm::GetElementPtrInst*) const CodeGenPrepare.cpp:0:0
#12 0x0000563df4fc0ec8 (anonymous namespace)::CodeGenPrepare::_run(llvm::Function&) CodeGenPrepare.cpp:0:0
#13 0x0000563df4fbb36c (anonymous namespace)::CodeGenPrepareLegacyPass::runOnFunction(llvm::Function&) CodeGenPrepare.cpp:0:0
```

I think this happened when we get DominatorTree with `DT.get()` in
`splitLargeGEPOffsets()` but `DT.reset()` already setting it to nullptr
in
https://github.com/llvm/llvm-project/blob/ad8d5349d46734826aaeae4a2ebdc6f427a5bad8/llvm/lib/CodeGen/CodeGenPrepare.cpp#L660.
To fix this assertion failure, use `getDT()` for
`splitLargeGEPOffsets()` to build the DominatorTree if it is set to
nullptr by `DT.reset()`.

I don't have a RSIC-V environment, so no reproducer. Checked that the
crash is fixed by rerunning buildbot with this patch
https://lab.llvm.org/buildbot/#/builders/210/builds/8248
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 3, 2026
…try block in splitBlockBefore() (#178895) (#179392)

llvm/llvm-project#178895 caused a clang
crash(see https://lab.llvm.org/buildbot/#/builders/210/builds/8229),
reverted in 6d52d26.

The crash is assertion `DT && "DT should be available to update
LoopInfo!"' failed.

https://github.com/llvm/llvm-project/blob/ad8d5349d46734826aaeae4a2ebdc6f427a5bad8/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp#L1106

```
 #7 0x00007f5a380254e3 __assert_perror_fail (/usr/lib/libc.so.6+0x254e3)
 #8 0x0000563df5d8fde1 UpdateAnalysisInformation(llvm::BasicBlock*, llvm::BasicBlock*, llvm::ArrayRef<llvm::BasicBlock*>, llvm::DomTreeUpdater*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, bool, bool&) BasicBlockUtils.cpp:0:0
 #9 0x0000563df5d8f3bb llvm::splitBlockBefore(llvm::BasicBlock*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, false>, llvm::DomTreeUpdater*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, llvm::Twine const&)
#10 0x0000563df5d8cb08 llvm::SplitEdge(llvm::BasicBlock*, llvm::BasicBlock*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, llvm::Twine const&)
#11 0x0000563df4ff5b59 (anonymous namespace)::CodeGenPrepare::splitLargeGEPOffsets()::$_1::operator()(long, llvm::Value*, llvm::GetElementPtrInst*) const CodeGenPrepare.cpp:0:0
#12 0x0000563df4fc0ec8 (anonymous namespace)::CodeGenPrepare::_run(llvm::Function&) CodeGenPrepare.cpp:0:0
#13 0x0000563df4fbb36c (anonymous namespace)::CodeGenPrepareLegacyPass::runOnFunction(llvm::Function&) CodeGenPrepare.cpp:0:0
```

I think this happened when we get DominatorTree with `DT.get()` in
`splitLargeGEPOffsets()` but `DT.reset()` already setting it to nullptr
in
https://github.com/llvm/llvm-project/blob/ad8d5349d46734826aaeae4a2ebdc6f427a5bad8/llvm/lib/CodeGen/CodeGenPrepare.cpp#L660.
To fix this assertion failure, use `getDT()` for
`splitLargeGEPOffsets()` to build the DominatorTree if it is set to
nullptr by `DT.reset()`.

I don't have a RSIC-V environment, so no reproducer. Checked that the
crash is fixed by rerunning buildbot with this patch
https://lab.llvm.org/buildbot/#/builders/210/builds/8248
moar55 pushed a commit to moar55/llvm-project that referenced this pull request Feb 3, 2026
…lockBefore() (llvm#178895)

06dfbb5 fixed dominator update for
entry block in `SplitBlockPredecessors()`, this patch fixes dominator
tree update for entry block in `splitBlockBefore()` with
`UpdateAnalysisInformation()`.
moar55 pushed a commit to moar55/llvm-project that referenced this pull request Feb 3, 2026
moar55 pushed a commit to moar55/llvm-project that referenced this pull request Feb 3, 2026
…n splitBlockBefore() (llvm#178895) (llvm#179392)

llvm#178895 caused a clang
crash(see https://lab.llvm.org/buildbot/#/builders/210/builds/8229),
reverted in 6d52d26.

The crash is assertion `DT && "DT should be available to update
LoopInfo!"' failed.

https://github.com/llvm/llvm-project/blob/ad8d5349d46734826aaeae4a2ebdc6f427a5bad8/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp#L1106

```
 llvm#7 0x00007f5a380254e3 __assert_perror_fail (/usr/lib/libc.so.6+0x254e3)
 llvm#8 0x0000563df5d8fde1 UpdateAnalysisInformation(llvm::BasicBlock*, llvm::BasicBlock*, llvm::ArrayRef<llvm::BasicBlock*>, llvm::DomTreeUpdater*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, bool, bool&) BasicBlockUtils.cpp:0:0
 llvm#9 0x0000563df5d8f3bb llvm::splitBlockBefore(llvm::BasicBlock*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, false>, llvm::DomTreeUpdater*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, llvm::Twine const&)
llvm#10 0x0000563df5d8cb08 llvm::SplitEdge(llvm::BasicBlock*, llvm::BasicBlock*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, llvm::Twine const&)
llvm#11 0x0000563df4ff5b59 (anonymous namespace)::CodeGenPrepare::splitLargeGEPOffsets()::$_1::operator()(long, llvm::Value*, llvm::GetElementPtrInst*) const CodeGenPrepare.cpp:0:0
llvm#12 0x0000563df4fc0ec8 (anonymous namespace)::CodeGenPrepare::_run(llvm::Function&) CodeGenPrepare.cpp:0:0
llvm#13 0x0000563df4fbb36c (anonymous namespace)::CodeGenPrepareLegacyPass::runOnFunction(llvm::Function&) CodeGenPrepare.cpp:0:0
```

I think this happened when we get DominatorTree with `DT.get()` in
`splitLargeGEPOffsets()` but `DT.reset()` already setting it to nullptr
in
https://github.com/llvm/llvm-project/blob/ad8d5349d46734826aaeae4a2ebdc6f427a5bad8/llvm/lib/CodeGen/CodeGenPrepare.cpp#L660.
To fix this assertion failure, use `getDT()` for
`splitLargeGEPOffsets()` to build the DominatorTree if it is set to
nullptr by `DT.reset()`.

I don't have a RSIC-V environment, so no reproducer. Checked that the
crash is fixed by rerunning buildbot with this patch
https://lab.llvm.org/buildbot/#/builders/210/builds/8248
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.

5 participants