llvm.org GIT mirror llvm / 762b38d
[LegacyPM] Fix PR37888 by teaching the legacy loop pass manager how to clear out deleted loops from the current queue beyond just the current loop. This is important because SimpleLoopUnswitch will now enqueue the same loop to be re-processed. When it does this with the legacy PM, we don't have a way of canceling the rest of the pipeline and so we can end up deleting the loop before we reprocess it. =/ This change also makes it easy to support deleting other loops in the queue to process, although I don't have any use cases for that. Differential Revision: https://reviews.llvm.org/D48470 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335317 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 1 year, 3 months ago
2 changed file(s) with 48 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
141141 void LPPassManager::markLoopAsDeleted(Loop &L) {
142142 assert((&L == CurrentLoop || CurrentLoop->contains(&L)) &&
143143 "Must not delete loop outside the current loop tree!");
144 if (&L == CurrentLoop)
144 // If this loop appears elsewhere within the queue, we also need to remove it
145 // there. However, we have to be careful to not remove the back of the queue
146 // as that is assumed to match the current loop.
147 assert(LQ.back() == CurrentLoop && "Loop queue back isn't the current loop!");
148 LQ.erase(std::remove(LQ.begin(), LQ.end(), &L), LQ.end());
149
150 if (&L == CurrentLoop) {
145151 CurrentLoopDeleted = true;
152 // Add this loop back onto the back of the queue to preserve our invariants.
153 LQ.push_back(&L);
154 }
146155 }
147156
148157 /// run - Execute all of the passes scheduled for execution. Keep track of
0 ; RUN: opt -simple-loop-unswitch -loop-deletion -S < %s | FileCheck %s
1 ;
2 ; Check that when we do unswitching where we re-enqueue the loop to be processed
3 ; again, but manage to delete the loop before ever getting to iterate on it, it
4 ; doesn't crash the legacy pass manager.
5
6 target triple = "x86_64-unknown-linux-gnu"
7
8 define void @pr37888() {
9 ; CHECK-LABEL: define void @pr37888()
10 entry:
11 %tobool = icmp ne i16 undef, 0
12 br label %for.body
13 ; CHECK: %[[TOBOOL:.*]] = icmp ne
14 ; CHECK-NEXT: br i1 %[[TOBOOL]], label %if.then, label %[[ENTRY_SPLIT:.*]]
15 ;
16 ; CHECK: [[ENTRY_SPLIT]]:
17 ; CHECK-NEXT: br label %for.end
18
19 for.body:
20 br i1 %tobool, label %if.then, label %if.end
21
22 if.then:
23 unreachable
24 ; CHECK: if.then:
25 ; CHECK-NEXT: unreachable
26
27 if.end:
28 br label %for.inc
29
30 for.inc:
31 br i1 undef, label %for.body, label %for.end
32
33 for.end:
34 ret void
35 ; CHECK: for.end:
36 ; CHECK-NEXT: ret void
37 }