@@ -1511,10 +1511,20 @@ function finish_current_bb!(compact::IncrementalCompact, active_bb::Int,
15111511 return skipped
15121512end
15131513
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
15181528end
15191529
15201530function 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
15261536 compact. result_idx = result_idx
15271537 # If this instruction has reverse affinity and we were at the end of a basic block,
15281538 # 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 )
15301540 active_bb += 1
15311541 finish_current_bb! (compact, active_bb, old_result_idx)
15321542 end
@@ -1656,7 +1666,7 @@ function iterate_compact(compact::IncrementalCompact)
16561666 compact. result[old_result_idx] = compact. ir. stmts[idx]
16571667 result_idx = process_node! (compact, old_result_idx, compact. ir. stmts[idx], idx, idx, active_bb, true )
16581668 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)
16601670 finish_current_bb! (compact, active_bb, old_result_idx)
16611671 active_bb += 1
16621672 end
0 commit comments