[PATCH] D48369: [CodeGen] Make block removal order deterministic in CodeGenPrepare

David Stenberg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 2 07:28:41 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL336109: [CodeGen] Make block removal order deterministic in CodeGenPrepare (authored by dstenb, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48369?vs=153018&id=153710#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48369

Files:
  llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp


Index: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
@@ -462,7 +462,10 @@
 
   if (!DisableBranchOpts) {
     MadeChange = false;
-    SmallPtrSet<BasicBlock*, 8> WorkList;
+    // Use a set vector to get deterministic iteration order. The order the
+    // blocks are removed may affect whether or not PHI nodes in successors
+    // are removed.
+    SmallSetVector<BasicBlock*, 8> WorkList;
     for (BasicBlock &BB : F) {
       SmallVector<BasicBlock *, 2> Successors(succ_begin(&BB), succ_end(&BB));
       MadeChange |= ConstantFoldTerminator(&BB, true);
@@ -477,8 +480,7 @@
     // Delete the dead blocks and any of their dead successors.
     MadeChange |= !WorkList.empty();
     while (!WorkList.empty()) {
-      BasicBlock *BB = *WorkList.begin();
-      WorkList.erase(BB);
+      BasicBlock *BB = WorkList.pop_back_val();
       SmallVector<BasicBlock*, 2> Successors(succ_begin(BB), succ_end(BB));
 
       DeleteDeadBlock(BB);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48369.153710.patch
Type: text/x-patch
Size: 1100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180702/6fdb2fbc/attachment.bin>


More information about the llvm-commits mailing list