[llvm] r355105 - Make MergeBlockIntoPredecessor conformant to the precondition of calling DTU.applyUpdates

Chijun Sima via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 28 08:47:18 PST 2019


Author: sima
Date: Thu Feb 28 08:47:18 2019
New Revision: 355105

URL: http://llvm.org/viewvc/llvm-project?rev=355105&view=rev
Log:
Make MergeBlockIntoPredecessor conformant to the precondition of calling DTU.applyUpdates

Summary:
It is mentioned in the document of DTU that "It is illegal to submit any update that has already been submitted, i.e., you are supposed not to insert an existent edge or delete a nonexistent edge." It is dangerous to violet this rule because DomTree and PostDomTree occasionally crash on this scenario.

This patch fixes `MergeBlockIntoPredecessor`, making it conformant to this precondition.

Reviewers: kuhar, brzycki, chandlerc

Reviewed By: brzycki

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D58444

Modified:
    llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp

Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=355105&r1=355104&r2=355105&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Thu Feb 28 08:47:18 2019
@@ -186,7 +186,9 @@ bool llvm::MergeBlockIntoPredecessor(Bas
     Updates.push_back({DominatorTree::Delete, PredBB, BB});
     for (auto I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
       Updates.push_back({DominatorTree::Delete, BB, *I});
-      Updates.push_back({DominatorTree::Insert, PredBB, *I});
+      // This successor of BB may already have PredBB as a predecessor.
+      if (llvm::find(successors(PredBB), *I) == succ_end(PredBB))
+        Updates.push_back({DominatorTree::Insert, PredBB, *I});
     }
   }
 




More information about the llvm-commits mailing list