Skip to content

Commit 53c9d58

Browse files
committedMay 14, 2019
[LICM] Allow AliasSetMap to contain top-level loops.
When an outer loop gets deleted by a different pass, before LICM visits it, we cannot clean up its sub-loops in AliasSetMap, because at the point we receive the deleteAnalysisLoop callback for the outer loop, the loop object is already invalid and we cannot access its sub-loops any longer. Reviewers: asbirlea, sanjoy, chandlerc Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D61904 llvm-svn: 360704
1 parent 030b17d commit 53c9d58

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
 

‎llvm/lib/Transforms/Scalar/LICM.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,16 @@ struct LegacyLICMPass : public LoopPass {
244244
using llvm::Pass::doFinalization;
245245

246246
bool doFinalization() override {
247-
assert(LICM.getLoopToAliasSetMap().empty() &&
247+
auto &AliasSetMap = LICM.getLoopToAliasSetMap();
248+
// All loops in the AliasSetMap should be cleaned up already. The only case
249+
// where we fail to do so is if an outer loop gets deleted before LICM
250+
// visits it.
251+
assert(all_of(AliasSetMap,
252+
[](LoopInvariantCodeMotion::ASTrackerMapTy::value_type &KV) {
253+
return !KV.first->getParentLoop();
254+
}) &&
248255
"Didn't free loop alias sets");
256+
AliasSetMap.clear();
249257
return false;
250258
}
251259

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; RUN: opt %s -S -loop-unroll -licm | FileCheck %s
2+
3+
; Check that we can deal with loops where a parent loop gets deleted before it
4+
; is visited by LICM.
5+
define void @test() {
6+
; CHECK-LABEL: define void @test() {
7+
; CHECK-LABEL: entry:
8+
; CHECK-NEXT: br label %for.body43
9+
10+
; CHECK-LABEL: for.body43: ; preds = %entry
11+
; CHECK-NEXT: br label %if.else75
12+
13+
; CHECK-LABEL: if.else75: ; preds = %for.body43
14+
; CHECK-NEXT: br label %for.body467
15+
16+
; CHECK-LABEL: for.body467: ; preds = %for.body467.for.body467_crit_edge, %if.else75
17+
; CHECK-NEXT: br label %for.body467.for.body467_crit_edge
18+
19+
; CHECK-LABEL: for.body467.for.body467_crit_edge: ; preds = %for.body467
20+
; CHECK-NEXT: br i1 false, label %for.end539, label %for.body467
21+
22+
; CHECK-LABEL: for.end539: ; preds = %for.body467.for.body467_crit_edge
23+
; CHECK-NEXT: ret void
24+
;
25+
26+
entry:
27+
br label %for.body43
28+
29+
for.body43: ; preds = %for.end539, %entry
30+
br label %if.else75
31+
32+
if.else75: ; preds = %for.body43
33+
br label %for.body467
34+
35+
for.body467: ; preds = %for.body467.for.body467_crit_edge, %if.else75
36+
br label %for.body467.for.body467_crit_edge
37+
38+
for.body467.for.body467_crit_edge: ; preds = %for.body467
39+
br i1 false, label %for.end539, label %for.body467
40+
41+
for.end539: ; preds = %for.body467
42+
br i1 undef, label %for.body43, label %for.end547
43+
44+
for.end547: ; preds = %for.body43
45+
ret void
46+
}

0 commit comments

Comments
 (0)
Please sign in to comment.