Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ir/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,6 @@ void Function::unroll(unsigned k) {
// computed bottom-up during the post-order traversal below
unordered_map<BasicBlock*, vector<BasicBlock*>> loop_nodes;

// grab all value users before duplication so the list is shorter
auto users = getUsers();
auto phi_preds = getPhiPredecessors(*this);

// traverse each loop tree in post-order
while (!worklist.empty()) {
auto [header, height, flag] = worklist.back();
Expand Down Expand Up @@ -644,6 +640,12 @@ void Function::unroll(unsigned k) {
}
}

// Grab value users before duplicating the current loop so the list stays
// shorter. This must be refreshed per loop because unrolling an inner loop
// can introduce phis that outer-loop exits now use.
auto users = getUsers();
auto phi_preds = getPhiPredecessors(*this);

// map: original BB -> {BB} U copies-of-BB
unordered_map<const BasicBlock*, vector<BasicBlock*>> bbmap;
for (auto *bb : loop_bbs) {
Expand Down Expand Up @@ -1236,5 +1238,4 @@ void LoopAnalysis::printDot(ostream &os) const {
os << "}\n";
}

}

}
27 changes: 27 additions & 0 deletions tests/alive-tv/loops/nested-exit-phi.srctgt.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; TEST-ARGS: -src-unroll=2 -tgt-unroll=2

define i32 @src() {
br label %1

1:
%2 = phi i32 [ 0, %0 ], [ 1, %6 ]
br label %3

3:
%4 = mul i32 %2, 1
br label %5

5:
br i1 false, label %3, label %6

6:
%7 = icmp slt i32 %2, 1
br i1 %7, label %1, label %8

8:
ret i32 %4
}

define i32 @tgt() {
ret i32 1
}
Loading