@@ -1511,10 +1511,20 @@ function finish_current_bb!(compact::IncrementalCompact, active_bb::Int,
1511
1511
return skipped
1512
1512
end
1513
1513
1514
- function attach_after_stmt_after (compact:: IncrementalCompact , idx:: Int )
1515
- compact. new_nodes_idx > length (compact. perm) && return false
1516
- entry = compact. ir. new_nodes. info[compact. perm[compact. new_nodes_idx]]
1517
- return entry. pos == idx && entry. attach_after
1514
+ """
1515
+ stmts_awaiting_insertion(compact::IncrementalCompact, idx::Int)
1516
+
1517
+ Returns true if there are new/pending instructions enqueued for insertion into
1518
+ `compact` on any instruction in the range `1:idx`. Otherwise, returns false.
1519
+ """
1520
+ function stmts_awaiting_insertion (compact:: IncrementalCompact , idx:: Int )
1521
+
1522
+ new_node_waiting = compact. new_nodes_idx <= length (compact. perm) &&
1523
+ compact. ir. new_nodes. info[compact. perm[compact. new_nodes_idx]]. pos <= idx
1524
+ pending_node_waiting = ! isempty (compact. pending_perm) &&
1525
+ compact. pending_nodes. info[compact. pending_perm[1 ]]. pos <= idx
1526
+
1527
+ return new_node_waiting || pending_node_waiting
1518
1528
end
1519
1529
1520
1530
function process_newnode! (compact:: IncrementalCompact , new_idx:: Int , new_node_entry:: Instruction , new_node_info:: NewNodeInfo , idx:: Int , active_bb:: Int , do_rename_ssa:: Bool )
@@ -1526,7 +1536,7 @@ function process_newnode!(compact::IncrementalCompact, new_idx::Int, new_node_en
1526
1536
compact. result_idx = result_idx
1527
1537
# If this instruction has reverse affinity and we were at the end of a basic block,
1528
1538
# finish it now.
1529
- if new_node_info. attach_after && idx == last (bb. stmts)+ 1 && ! attach_after_stmt_after (compact, idx- 1 )
1539
+ if new_node_info. attach_after && idx == last (bb. stmts)+ 1 && ! stmts_awaiting_insertion (compact, idx- 1 )
1530
1540
active_bb += 1
1531
1541
finish_current_bb! (compact, active_bb, old_result_idx)
1532
1542
end
@@ -1656,7 +1666,7 @@ function iterate_compact(compact::IncrementalCompact)
1656
1666
compact. result[old_result_idx] = compact. ir. stmts[idx]
1657
1667
result_idx = process_node! (compact, old_result_idx, compact. ir. stmts[idx], idx, idx, active_bb, true )
1658
1668
compact. result_idx = result_idx
1659
- if idx == last (bb. stmts) && ! attach_after_stmt_after (compact, idx)
1669
+ if idx == last (bb. stmts) && ! stmts_awaiting_insertion (compact, idx)
1660
1670
finish_current_bb! (compact, active_bb, old_result_idx)
1661
1671
active_bb += 1
1662
1672
end
0 commit comments