1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

[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

llvm-svn: 366215
This commit is contained in:
Amara Emerson 2019-07-16 15:23:10 +00:00
parent f1904bd7ad
commit 2402efd785

View File

@ -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<const Metadata *, 32> AliveScopes;
/// Set of blocks with not known to have live terminators.
SmallPtrSet<BasicBlock *, 16> BlocksWithDeadTerminators;
SmallSetVector<BasicBlock *, 16> 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<BasicBlock *, 16> BWDT{
BlocksWithDeadTerminators.begin(),
BlocksWithDeadTerminators.end()
};
SmallVector<BasicBlock *, 32> IDFBlocks;
ReverseIDFCalculator IDFs(PDT);
IDFs.setDefiningBlocks(NewLiveBlocks);
IDFs.setLiveInBlocks(BlocksWithDeadTerminators);
IDFs.setLiveInBlocks(BWDT);
IDFs.calculate(IDFBlocks);
NewLiveBlocks.clear();