[llvm] [BasicBlockUtils] Fix SplitBlockPredecessors incorrect dominator insert (PR #107190)

Joshua Cao via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 8 18:03:17 PDT 2024


================
@@ -1160,7 +1160,10 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
       // Split block expects NewBB to have a non-empty set of predecessors.
       SmallVector<DominatorTree::UpdateType, 8> Updates;
       SmallPtrSet<BasicBlock *, 8> UniquePreds;
-      Updates.push_back({DominatorTree::Insert, NewBB, OldBB});
+      if (OldBB->getSinglePredecessor()) {
+        assert(OldBB->getSinglePredecessor() == NewBB);
+        Updates.push_back({DominatorTree::Insert, NewBB, OldBB});
+      }
----------------
caojoshua wrote:

OK yeah this isn't right. The issue is actually [in LICM](https://github.com/llvm/llvm-project/blob/3d7af093f3d7b5c025e727277b9cc2b899c2d84e/llvm/lib/Transforms/Scalar/LICM.cpp#L570). If I modify it to iterate over BBs instead of DomTreeNodes, it works as intended. I think the DomTreeNodes are getting modified at some point while modifying the DomTree. The if statement somehow avoids the issue.

I'm having trouble creating a smaller reproducer. But the full issue is in https://buildkite.com/llvm-project/github-pull-requests/builds/88168#01911957-5a9a-4e62-bda6-b2f031368134 (from https://github.com/llvm/llvm-project/pull/97196)

https://github.com/llvm/llvm-project/pull/107190


More information about the llvm-commits mailing list