From f50c6dfc4421fbd8c3963f5acbd886430795934a Mon Sep 17 00:00:00 2001 From: Amara Emerson Date: Tue, 16 Jul 2019 15:23:10 +0000 Subject: [PATCH] [ADCE] Fix non-deterministic behaviour due to iterating over a pointer set. Original patch by Yann Laigle-Chapuy Differential Revision: https://reviews.llvm.org/D64785 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366215 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/ADCE.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index 8dcf6393f46..7f7460c5746 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/PostOrderIterator.h" +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" @@ -135,7 +136,7 @@ class AggressiveDeadCodeElimination { SmallPtrSet AliveScopes; /// Set of blocks with not known to have live terminators. - SmallPtrSet BlocksWithDeadTerminators; + SmallSetVector BlocksWithDeadTerminators; /// The set of blocks which we have determined whose control /// dependence sources must be live and which have not had @@ -389,7 +390,7 @@ void AggressiveDeadCodeElimination::markLive(Instruction *I) { // Mark the containing block live auto &BBInfo = *Info.Block; if (BBInfo.Terminator == I) { - BlocksWithDeadTerminators.erase(BBInfo.BB); + BlocksWithDeadTerminators.remove(BBInfo.BB); // For live terminators, mark destination blocks // live to preserve this control flow edges. if (!BBInfo.UnconditionalBranch) @@ -478,10 +479,14 @@ void AggressiveDeadCodeElimination::markLiveBranchesFromControlDependences() { // which currently have dead terminators that are control // dependence sources of a block which is in NewLiveBlocks. + const SmallPtrSet BWDT{ + BlocksWithDeadTerminators.begin(), + BlocksWithDeadTerminators.end() + }; SmallVector IDFBlocks; ReverseIDFCalculator IDFs(PDT); IDFs.setDefiningBlocks(NewLiveBlocks); - IDFs.setLiveInBlocks(BlocksWithDeadTerminators); + IDFs.setLiveInBlocks(BWDT); IDFs.calculate(IDFBlocks); NewLiveBlocks.clear(); -- 2.49.0