broadcom/compiler: improve generation of if conditions
Where it is safe to do so, avoid the generation of code to convert a condition code into a boolean which is then tested to generate a condition code. This is only done in uniform ifs, and only for condition values that are SSA and only used once (in that if statement). shader-db relative to MR 7726: total instructions in shared programs: 8985667 -> 8974151 (-0.13%) instructions in affected programs: 390140 -> 378624 (-2.95%) helped: 810 HURT: 276 helped stats (abs) min: 1 max: 49 x̄: 17.77 x̃: 16 helped stats (rel) min: 0.10% max: 33.63% x̄: 7.97% x̃: 6.45% HURT stats (abs) min: 1 max: 46 x̄: 10.42 x̃: 10 HURT stats (rel) min: 0.16% max: 21.54% x̄: 2.26% x̃: 2.03% 95% mean confidence interval for instructions value: -11.46 -9.75 95% mean confidence interval for instructions %-change: -5.76% -4.97% Instructions are helped. Reviewed-by: Iago Toral Quiroga <itoral@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8709>
This commit is contained in:
parent
b60dfa2c09
commit
93f8f83a95
|
@ -2788,6 +2788,20 @@ ntq_activate_execute_for_block(struct v3d_compile *c)
|
|||
static void
|
||||
ntq_emit_uniform_if(struct v3d_compile *c, nir_if *if_stmt)
|
||||
{
|
||||
/* If the if-statement's condition is only used once, emit it right before
|
||||
* the if statement so as to use the resulting condition code directly.
|
||||
* DCE will take care of the other comparison later.
|
||||
*/
|
||||
bool condition_emitted = false;
|
||||
enum v3d_qpu_cond cond;
|
||||
if (if_stmt->condition.is_ssa && list_length(&if_stmt->condition.use_link) == 1) {
|
||||
nir_instr *comparison = if_stmt->condition.ssa->parent_instr;
|
||||
if (comparison->type == nir_instr_type_alu) {
|
||||
condition_emitted =
|
||||
ntq_emit_comparison(c, nir_instr_as_alu(comparison), &cond);
|
||||
}
|
||||
}
|
||||
|
||||
nir_block *nir_else_block = nir_if_first_else_block(if_stmt);
|
||||
bool empty_else_block =
|
||||
(nir_else_block == nir_if_last_else_block(if_stmt) &&
|
||||
|
@ -2801,8 +2815,11 @@ ntq_emit_uniform_if(struct v3d_compile *c, nir_if *if_stmt)
|
|||
else
|
||||
else_block = vir_new_block(c);
|
||||
|
||||
/* Set up the flags for the IF condition (taking the THEN branch). */
|
||||
enum v3d_qpu_cond cond = ntq_emit_bool_to_cond(c, if_stmt->condition);
|
||||
/* Set up the flags for the IF condition (taking the THEN branch),
|
||||
* if we haven't already done so.
|
||||
*/
|
||||
if (!condition_emitted)
|
||||
cond = ntq_emit_bool_to_cond(c, if_stmt->condition);
|
||||
|
||||
/* Jump to ELSE. */
|
||||
struct qinst *branch = vir_BRANCH(c, cond == V3D_QPU_COND_IFA ?
|
||||
|
|
Loading…
Reference in New Issue