Skip to content

Commit acd786d

Browse files
authored
Fix loop parent computation in DataFlow.Graph (#2522)
This fixes the parent-child relationship computation in `DataFlow.Graph` when there is a loop. This wasn't discovered until now because this is used in Souperify and Souperify only runs after Flatten pass, which produces redundant blocks between inside and outside of a loop.
1 parent 8dd1b2d commit acd786d

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

src/dataflow/graph.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> {
278278
return &bad;
279279
}
280280
Node* doVisitLoop(Loop* curr) {
281+
auto* oldParent = parent;
282+
expressionParentMap[curr] = oldParent;
283+
parent = curr;
281284
// As in Souper's LLVM extractor, we avoid loop phis, as we don't want
282285
// our traces to represent a value that differs across loop iterations.
283286
// For example,

test/passes/souperify.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
; function: if-loop-test
3+
4+
; start LHS (in if-loop-test)
5+
%0 = sub 0:i32, 0:i32
6+
%1 = ne 0:i32, 0:i32
7+
pc %1 1:i1
8+
infer %0
9+
10+
(module
11+
(type $FUNCSIG$v (func))
12+
(func $if-loop-test (; 0 ;) (type $FUNCSIG$v)
13+
(local $0 i32)
14+
(if
15+
(i32.const 0)
16+
(loop $label$0
17+
(local.set $0
18+
(i32.sub
19+
(i32.const 0)
20+
(i32.const 0)
21+
)
22+
)
23+
)
24+
)
25+
)
26+
)

test/passes/souperify.wast

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(module
2+
;; This tests if we can create dataflow graph correctly in the presence of
3+
;; loops.
4+
(func $if-loop-test (local $0 i32)
5+
(if
6+
(i32.const 0)
7+
(loop $label$0
8+
(local.set $0
9+
(i32.sub
10+
(i32.const 0)
11+
(i32.const 0)
12+
)
13+
)
14+
)
15+
)
16+
)
17+
)

0 commit comments

Comments
 (0)