diff --git a/src/amd/compiler/aco_lower_to_cssa.cpp b/src/amd/compiler/aco_lower_to_cssa.cpp index c4eb542f03c..65fcdac40b9 100644 --- a/src/amd/compiler/aco_lower_to_cssa.cpp +++ b/src/amd/compiler/aco_lower_to_cssa.cpp @@ -56,9 +56,12 @@ struct merge_node { uint32_t index = -1u; /* index into the vector of merge sets */ uint32_t defined_at = -1u; /* defining block */ - /* we also remember two dominating defs with the same value: */ + /* We also remember two closest equal intersecting ancestors. Because they intersect with this + * merge node, they must dominate it (intersection isn't possible otherwise) and have the same + * value (or else they would not be allowed to be in the same merge set). + */ Temp equal_anc_in = Temp(); /* within the same merge set */ - Temp equal_anc_out = Temp(); /* from a different set */ + Temp equal_anc_out = Temp(); /* from the other set we're currently trying to merge with */ }; struct cssa_ctx { @@ -243,7 +246,7 @@ intersects(cssa_ctx& ctx, Temp var, Temp parent) /* check interference between var and parent: * i.e. they have different values and intersect. - * If parent and var share the same value, also updates the equal ancestor. */ + * If parent and var intersect and share the same value, also updates the equal ancestor. */ inline bool interference(cssa_ctx& ctx, Temp var, Temp parent) { @@ -252,12 +255,13 @@ interference(cssa_ctx& ctx, Temp var, Temp parent) node_var.equal_anc_out = Temp(); if (node_var.index == ctx.merge_node_table[parent.id()].index) { - /* check/update in other set */ + /* Check/update in other set. equal_anc_out is only present if it intersects with 'parent', + * but that's fine since it has to for it to intersect with 'var'. */ parent = ctx.merge_node_table[parent.id()].equal_anc_out; } Temp tmp = parent; - /* check if var intersects with parent or any equal-valued ancestor */ + /* Check if 'var' intersects with 'parent' or any ancestors which might intersect too. */ while (tmp != Temp() && !intersects(ctx, var, tmp)) { merge_node& node_tmp = ctx.merge_node_table[tmp.id()]; tmp = node_tmp.equal_anc_in; @@ -267,7 +271,7 @@ interference(cssa_ctx& ctx, Temp var, Temp parent) if (tmp == Temp()) return false; - /* var and parent, same value, but in different sets */ + /* var and parent, same value and intersect, but in different sets */ if (node_var.value == ctx.merge_node_table[parent.id()].value) { node_var.equal_anc_out = tmp; return false; @@ -320,7 +324,7 @@ try_merge_merge_set(cssa_ctx& ctx, Temp dst, merge_set& set_b) for (Temp t : union_set) { merge_node& node = ctx.merge_node_table[t.id()]; /* update the equal ancestors: - * i.e. the 'closest' dominating def with the same value */ + * i.e. the 'closest' dominating def which intersects */ Temp in = node.equal_anc_in; Temp out = node.equal_anc_out; if (in == Temp() || (out != Temp() && defined_after(ctx, out, in)))