Skip to content

Commit c7bdda8

Browse files
tarceriTimothy Arceri
authored andcommitted
nir: allow propagation of if evaluation for bcsel
Shader-db results Skylake: total instructions in shared programs: 13109035 -> 13109024 (<.01%) instructions in affected programs: 4777 -> 4766 (-0.23%) helped: 11 HURT: 0 total cycles in shared programs: 332090418 -> 332090443 (<.01%) cycles in affected programs: 19474 -> 19499 (0.13%) helped: 6 HURT: 4 Reviewed-by: Jason Ekstrand <[email protected]>
1 parent 677b496 commit c7bdda8

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/compiler/nir/nir_opt_if.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,15 @@ propagate_condition_eval(nir_builder *b, nir_if *nif, nir_src *use_src,
448448
if (!evaluate_if_condition(nif, b->cursor, &bool_value))
449449
return false;
450450

451-
nir_ssa_def *def[2] = {0};
451+
nir_ssa_def *def[4] = {0};
452452
for (unsigned i = 0; i < nir_op_infos[alu->op].num_inputs; i++) {
453453
if (alu->src[i].src.ssa == use_src->ssa) {
454454
def[i] = nir_imm_bool(b, bool_value);
455455
} else {
456456
def[i] = alu->src[i].src.ssa;
457457
}
458458
}
459-
nir_ssa_def *nalu = nir_build_alu(b, alu->op, def[0], def[1], NULL, NULL);
459+
nir_ssa_def *nalu = nir_build_alu(b, alu->op, def[0], def[1], def[2], def[3]);
460460

461461
/* Rewrite use to use new alu instruction */
462462
nir_src new_src = nir_src_for_ssa(nalu);
@@ -472,14 +472,21 @@ propagate_condition_eval(nir_builder *b, nir_if *nif, nir_src *use_src,
472472
static bool
473473
can_propagate_through_alu(nir_src *src)
474474
{
475-
if (src->parent_instr->type == nir_instr_type_alu &&
476-
(nir_instr_as_alu(src->parent_instr)->op == nir_op_ior ||
477-
nir_instr_as_alu(src->parent_instr)->op == nir_op_iand ||
478-
nir_instr_as_alu(src->parent_instr)->op == nir_op_inot ||
479-
nir_instr_as_alu(src->parent_instr)->op == nir_op_b2i))
480-
return true;
475+
if (src->parent_instr->type != nir_instr_type_alu)
476+
return false;
481477

482-
return false;
478+
nir_alu_instr *alu = nir_instr_as_alu(src->parent_instr);
479+
switch (alu->op) {
480+
case nir_op_ior:
481+
case nir_op_iand:
482+
case nir_op_inot:
483+
case nir_op_b2i:
484+
return true;
485+
case nir_op_bcsel:
486+
return src == &alu->src[0].src;
487+
default:
488+
return false;
489+
}
483490
}
484491

485492
static bool

0 commit comments

Comments
 (0)