llvm.org GIT mirror llvm / cefa3d6
[MemorySSA] Use SetVector to avoid nondeterminism. Summary: Use a SetVector for DeadBlockSet. Resolves PR42574. Reviewers: george.burgess.iv, uabelho, dblaikie Subscribers: jlebar, Prazek, mgrang, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64601 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365970 91177308-0d34-0410-b5e6-96231b3b80d8 Alina Sbirlea a month ago
7 changed file(s) with 133 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
3030 #ifndef LLVM_ANALYSIS_MEMORYSSAUPDATER_H
3131 #define LLVM_ANALYSIS_MEMORYSSAUPDATER_H
3232
33 #include "llvm/ADT/SetVector.h"
3334 #include "llvm/ADT/SmallPtrSet.h"
3435 #include "llvm/ADT/SmallSet.h"
3536 #include "llvm/ADT/SmallVector.h"
242243 /// Deleted blocks still have successor info, but their predecessor edges and
243244 /// Phi nodes may already be updated. Instructions in DeadBlocks should be
244245 /// deleted after this call.
245 void removeBlocks(const SmallPtrSetImpl> &DeadBlocks);
246 void removeBlocks(const SmallSetVector> &DeadBlocks);
246247
247248 /// Instruction I will be changed to an unreachable. Remove all accesses in
248249 /// I's block that follow I (inclusive), and update the Phis in the blocks'
12461246 }
12471247
12481248 void MemorySSAUpdater::removeBlocks(
1249 const SmallPtrSetImpl> &DeadBlocks) {
1249 const SmallSetVector> &DeadBlocks) {
12501250 // First delete all uses of BB in MemoryPhis.
12511251 for (BasicBlock *BB : DeadBlocks) {
12521252 Instruction *TI = BB->getTerminator();
427427 /// relevant updates to DT and LI.
428428 void deleteDeadLoopBlocks() {
429429 if (MSSAU) {
430 SmallPtrSet DeadLoopBlocksSet(DeadLoopBlocks.begin(),
431 DeadLoopBlocks.end());
430 SmallSetVector DeadLoopBlocksSet(DeadLoopBlocks.begin(),
431 DeadLoopBlocks.end());
432432 MSSAU->removeBlocks(DeadLoopBlocksSet);
433433 }
434434
14621462
14631463 // Remove all MemorySSA in the dead blocks
14641464 if (MSSAU) {
1465 SmallPtrSet DeadBlockSet(DeadBlocks.begin(),
1466 DeadBlocks.end());
1465 SmallSetVector DeadBlockSet(DeadBlocks.begin(),
1466 DeadBlocks.end());
14671467 MSSAU->removeBlocks(DeadBlockSet);
14681468 }
14691469
14811481 MemorySSAUpdater *MSSAU) {
14821482 // Find all the dead blocks tied to this loop, and remove them from their
14831483 // successors.
1484 SmallPtrSet> DeadBlockSet;
1484 SmallSetVector> DeadBlockSet;
14851485
14861486 // Start with loop/exit blocks and get a transitive closure of reachable dead
14871487 // blocks.
22372237 assert(Reachable.size() < F.size());
22382238 NumRemoved += F.size()-Reachable.size();
22392239
2240 SmallPtrSet> DeadBlockSet;
2240 SmallSetVector> DeadBlockSet;
22412241 for (Function::iterator I = ++F.begin(), E = F.end(); I != E; ++I) {
22422242 auto *BB = &*I;
22432243 if (Reachable.count(BB))
680680 }
681681 DT->eraseNode(ExitingBlock);
682682 if (MSSAU) {
683 SmallPtrSet ExitBlockSet{ExitingBlock};
683 SmallSetVector ExitBlockSet;
684 ExitBlockSet.insert(ExitingBlock);
684685 MSSAU->removeBlocks(ExitBlockSet);
685686 }
686687
0 ; RUN: opt -simplifycfg -enable-mssa-loop-dependency -S --preserve-ll-uselistorder %s | FileCheck %s
1 ; REQUIRES: x86-registered-target
2 ; CHECK-LABEL: @n
3 ; CHECK: uselistorder i16 0, { 3, 2, 4, 1, 5, 0, 6 }
4
5 ; Note: test was added in an effort to ensure determinism when updating memoryssa. See PR42574.
6 ; If the uselistorder check becomes no longer relevant, the test can be disabled or removed.
7
8 %rec9 = type { i16, i32, i32 }
9
10 @a = global [1 x [1 x %rec9]] zeroinitializer
11
12 define i16 @n() {
13 br label %..split_crit_edge
14
15 ..split_crit_edge: ; preds = %0
16 br label %.split
17
18 bb4.us4: ; preds = %bb2.split.us32, %bb6.us28
19 %i.4.01.us5 = phi i16 [ %_tmp49.us30, %bb6.us28 ]
20 br label %g.exit4.us21
21
22 bb1.i.us14: ; preds = %bb4.us4
23 br label %g.exit4.us21
24
25 g.exit4.us21: ; preds = %bb1.i.us14, %g.exit4.critedge.us9
26 %i.4.02.us22 = phi i16 [ %i.4.01.us5, %bb4.us4 ], [ %i.4.01.us5, %bb1.i.us14 ]
27 br label %bb6.us28
28
29 bb5.us26: ; preds = %g.exit4.us21
30 br label %bb6.us28
31
32 bb6.us28: ; preds = %bb5.us26, %g.exit4.us21
33 %i.4.03.us29 = phi i16 [ %i.4.02.us22, %bb5.us26 ], [ %i.4.02.us22, %g.exit4.us21 ]
34 %_tmp49.us30 = add nuw nsw i16 %i.4.03.us29, 1
35 br label %bb4.us4
36
37 bb4.us.us: ; preds = %bb2.split.us.us, %bb6.us.us
38 %i.4.01.us.us = phi i16 [ %_tmp49.us.us, %bb6.us.us ]
39 br label %bb1.i.us.us
40
41 bb1.i.us.us: ; preds = %bb4.us.us
42 br label %g.exit4.us.us
43
44 g.exit4.us.us: ; preds = %bb1.i.us.us, %g.exit4.critedge.us.us
45 %i.4.02.us.us = phi i16 [ %i.4.01.us.us, %bb1.i.us.us ]
46 br label %bb5.us.us
47
48 bb5.us.us: ; preds = %g.exit4.us.us
49 br label %bb6.us.us
50
51 bb6.us.us: ; preds = %bb5.us.us, %g.exit4.us.us
52 %i.4.03.us.us = phi i16 [ %i.4.02.us.us, %bb5.us.us ]
53 %_tmp49.us.us = add nuw nsw i16 %i.4.03.us.us, 1
54 br label %bb4.us.us
55
56
57 .split: ; preds = %..split_crit_edge
58 br label %bb2
59
60 bb2: ; preds = %.split, %bb7
61 %h.3.0 = phi i16 [ undef, %.split ], [ %_tmp53, %bb7 ]
62 br label %bb2.bb2.split_crit_edge
63
64 bb2.bb2.split_crit_edge: ; preds = %bb2
65 br label %bb2.split
66
67 bb2.split.us: ; preds = %bb2
68 br label %bb4.us
69
70 bb4.us: ; preds = %bb6.us, %bb2.split.us
71 %i.4.01.us = phi i16 [ 0, %bb2.split.us ]
72 br label %bb1.i.us
73
74 g.exit4.critedge.us: ; preds = %bb4.us
75 br label %g.exit4.us
76
77 bb1.i.us: ; preds = %bb4.us
78 br label %g.exit4.us
79
80 g.exit4.us: ; preds = %bb1.i.us, %g.exit4.critedge.us
81 %i.4.02.us = phi i16 [ %i.4.01.us, %g.exit4.critedge.us ], [ %i.4.01.us, %bb1.i.us ]
82 br label %bb5.us
83
84 bb5.us: ; preds = %g.exit4.us
85 br label %bb7
86
87 bb2.split: ; preds = %bb2.bb2.split_crit_edge
88 br label %bb4
89
90 bb4: ; preds = %bb2.split, %bb6
91 %i.4.01 = phi i16 [ 0, %bb2.split ]
92 %_tmp16 = getelementptr [1 x [1 x %rec9]], [1 x [1 x %rec9]]* @a, i16 0, i16 %h.3.0, i16 %i.4.01, i32 0
93 %_tmp17 = load i16, i16* %_tmp16, align 1
94 br label %g.exit4.critedge
95
96 bb1.i: ; preds = %bb4
97 br label %g.exit4
98
99 g.exit4.critedge: ; preds = %bb4
100 %_tmp28.c = getelementptr [1 x [1 x %rec9]], [1 x [1 x %rec9]]* @a, i16 0, i16 %h.3.0, i16 %i.4.01, i32 1
101 %_tmp29.c = load i32, i32* %_tmp28.c, align 1
102 %_tmp30.c = trunc i32 %_tmp29.c to i16
103 br label %g.exit4
104
105 g.exit4: ; preds = %g.exit4.critedge, %bb1.i
106 %i.4.02 = phi i16 [ %i.4.01, %g.exit4.critedge ], [ %i.4.01, %bb1.i ]
107 %_tmp41 = getelementptr [1 x [1 x %rec9]], [1 x [1 x %rec9]]* @a, i16 0, i16 %h.3.0, i16 %i.4.02, i32 2
108 br label %bb6
109
110 bb5: ; preds = %g.exit4
111 br label %bb6
112
113 bb6: ; preds = %bb5, %g.exit4
114 %i.4.03 = phi i16 [ %i.4.02, %bb5 ], [ %i.4.02, %g.exit4 ]
115 %_tmp49 = add nuw nsw i16 %i.4.03, 1
116 br label %bb7
117
118 bb7: ; preds = %bb7.us-lcssa.us, %bb7.us-lcssa
119 %_tmp53 = add nsw i16 %h.3.0, 1
120 br label %bb2
121 }