nir: evaluate if condition uses inside the if branches
Since we know what side of the branch we ended up on we can just replace the use with a constant. All the spill changes in shader-db are from Dolphin uber shaders, despite some small regressions the change is clearly positive. V2: insert new constant after any phis in the use->parent_instr->type == nir_instr_type_phi path. v3: - use nir_after_block_before_jump() for inserting const - check dominance of phi uses correctly v4: - create some helpers as suggested by Jason. v5 (Jason Ekstrand): - Use LIST_ENTRY to get the phi src shader-db results IVB: total instructions in shared programs: 9999201 -> 9993483 (-0.06%) instructions in affected programs: 163235 -> 157517 (-3.50%) helped: 132 HURT: 2 total cycles in shared programs: 231670754 -> 219476091 (-5.26%) cycles in affected programs: 143424120 -> 131229457 (-8.50%) helped: 115 HURT: 24 total spills in shared programs: 4383 -> 4370 (-0.30%) spills in affected programs: 1656 -> 1643 (-0.79%) helped: 9 HURT: 18 total fills in shared programs: 4610 -> 4581 (-0.63%) fills in affected programs: 374 -> 345 (-7.75%) helped: 6 HURT: 0 Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
@@ -2353,6 +2353,36 @@ nir_after_block_before_jump(nir_block *block)
|
||||
}
|
||||
}
|
||||
|
||||
static inline nir_cursor
|
||||
nir_before_src(nir_src *src, bool is_if_condition)
|
||||
{
|
||||
if (is_if_condition) {
|
||||
nir_block *prev_block =
|
||||
nir_cf_node_as_block(nir_cf_node_prev(&src->parent_if->cf_node));
|
||||
assert(!nir_block_ends_in_jump(prev_block));
|
||||
return nir_after_block(prev_block);
|
||||
} else if (src->parent_instr->type == nir_instr_type_phi) {
|
||||
#ifndef NDEBUG
|
||||
nir_phi_instr *cond_phi = nir_instr_as_phi(src->parent_instr);
|
||||
bool found = false;
|
||||
nir_foreach_phi_src(phi_src, cond_phi) {
|
||||
if (phi_src->src.ssa == src->ssa) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(found);
|
||||
#endif
|
||||
/* The LIST_ENTRY macro is a generic container-of macro, it just happens
|
||||
* to have a more specific name.
|
||||
*/
|
||||
nir_phi_src *phi_src = LIST_ENTRY(nir_phi_src, src, src);
|
||||
return nir_after_block_before_jump(phi_src->pred);
|
||||
} else {
|
||||
return nir_before_instr(src->parent_instr);
|
||||
}
|
||||
}
|
||||
|
||||
static inline nir_cursor
|
||||
nir_before_cf_node(nir_cf_node *node)
|
||||
{
|
||||
|
Reference in New Issue
Block a user