File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,8 @@ template <typename ContextT> class GenericCycleInfoCompute {
134
134
DFSInfo () = default ;
135
135
explicit DFSInfo (unsigned Start) : Start(Start) {}
136
136
137
+ explicit operator bool () const { return Start; }
138
+
137
139
// / Whether this node is an ancestor (or equal to) the node \p Other
138
140
// / in the DFS tree.
139
141
bool isAncestorOf (const DFSInfo &Other) const {
@@ -231,6 +233,8 @@ void GenericCycleInfoCompute<ContextT>::run(BlockT *EntryBlock) {
231
233
232
234
for (BlockT *Pred : predecessors (HeaderCandidate)) {
233
235
const DFSInfo PredDFSInfo = BlockDFSInfo.lookup (Pred);
236
+ // This automatically ignores unreachable predecessors since they have
237
+ // zeros in their DFSInfo.
234
238
if (CandidateInfo.isAncestorOf (PredDFSInfo))
235
239
Worklist.push_back (Pred);
236
240
}
@@ -257,6 +261,10 @@ void GenericCycleInfoCompute<ContextT>::run(BlockT *EntryBlock) {
257
261
const DFSInfo PredDFSInfo = BlockDFSInfo.lookup (Pred);
258
262
if (CandidateInfo.isAncestorOf (PredDFSInfo)) {
259
263
Worklist.push_back (Pred);
264
+ } else if (!PredDFSInfo) {
265
+ // Ignore an unreachable predecessor. It will will incorrectly cause
266
+ // Block to be treated as a cycle entry.
267
+ LLVM_DEBUG (errs () << " skipped unreachable predecessor.\n " );
260
268
} else {
261
269
IsEntry = true ;
262
270
}
Original file line number Diff line number Diff line change
1
+ ; RUN: opt < %s -disable-output -passes='print<cycles>' 2>&1 | FileCheck %s
2
+ ; CHECK-LABEL: CycleInfo for function: unreachable
3
+ ; CHECK: depth=1: entries(loop.body) loop.latch inner.block
4
+ define void @unreachable (i32 %n ) {
5
+ entry:
6
+ br label %loop.body
7
+
8
+ loop.body:
9
+ br label %inner.block
10
+
11
+ ; This branch should not cause %inner.block to appear as an entry.
12
+ unreachable .block:
13
+ br label %inner.block
14
+
15
+ inner.block:
16
+ br i1 undef , label %loop.exit , label %loop.latch
17
+
18
+ loop.latch:
19
+ br label %loop.body
20
+
21
+ loop.exit:
22
+ ret void
23
+ }
You can’t perform that action at this time.
0 commit comments