summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2019-05-20 16:21:58 -0700
committerIan Romanick <ian.d.romanick@intel.com>2019-05-31 08:47:04 -0700
commit9f2000db5bacb16f4355ed00a8d65b71c1f71611 (patch)
treecf3de76054dc64f1f0ab220ccda6eddebc10c3f1
parent65df6122da9d171bc44f9ca969825478543b5384 (diff)
nir: Rematerialize comparisons for nir_intrinsic_discard_if tooexperiment/rematerialize-compares
Shader-db results for this series rebased on top of MR !935: Ice Lake total instructions in shared programs: 17179795 -> 17179776 (<.01%) instructions in affected programs: 10310 -> 10291 (-0.18%) helped: 19 HURT: 0 helped stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1 helped stats (rel) min: 0.08% max: 0.49% x̄: 0.28% x̃: 0.30% 95% mean confidence interval for instructions value: -1.00 -1.00 95% mean confidence interval for instructions %-change: -0.36% -0.21% Instructions are helped. total cycles in shared programs: 361083242 -> 361084861 (<.01%) cycles in affected programs: 595261 -> 596880 (0.27%) helped: 12 HURT: 7 helped stats (abs) min: 2 max: 211 x̄: 53.58 x̃: 6 helped stats (rel) min: 0.03% max: 0.89% x̄: 0.26% x̃: 0.06% HURT stats (abs) min: 1 max: 1882 x̄: 323.14 x̃: 48 HURT stats (rel) min: 0.01% max: 11.34% x̄: 1.86% x̃: 0.06% 95% mean confidence interval for cycles value: -128.77 299.19 95% mean confidence interval for cycles %-change: -0.76% 1.80% Inconclusive result (value mean confidence interval includes 0). LOST: 0 GAINED: 1
-rw-r--r--src/compiler/nir/nir_opt_rematerialize_compares.c61
1 files changed, 40 insertions, 21 deletions
diff --git a/src/compiler/nir/nir_opt_rematerialize_compares.c b/src/compiler/nir/nir_opt_rematerialize_compares.c
index 806dbd2f29a..16702fb23e6 100644
--- a/src/compiler/nir/nir_opt_rematerialize_compares.c
+++ b/src/compiler/nir/nir_opt_rematerialize_compares.c
@@ -58,25 +58,32 @@ is_two_src_comparison(const nir_alu_instr *instr)
}
static bool
-all_uses_are_bcsel(const nir_alu_instr *instr)
+all_uses_are_bcsel_or_discard(const nir_alu_instr *instr)
{
if (!instr->dest.dest.is_ssa)
return false;
nir_foreach_use(use, &instr->dest.dest.ssa) {
- if (use->parent_instr->type != nir_instr_type_alu)
- return false;
-
- nir_alu_instr *const alu = nir_instr_as_alu(use->parent_instr);
- if (alu->op != nir_op_bcsel &&
- alu->op != nir_op_b32csel)
- return false;
-
- /* Not only must the result be used by a bcsel, but it must be used as
- * the first source (the condition).
- */
- if (alu->src[0].src.ssa != &instr->dest.dest.ssa)
+ if (use->parent_instr->type == nir_instr_type_alu) {
+ nir_alu_instr *const alu = nir_instr_as_alu(use->parent_instr);
+ if (alu->op != nir_op_bcsel &&
+ alu->op != nir_op_b32csel)
+ return false;
+
+ /* Not only must the result be used by a bcsel, but it must be used as
+ * the first source (the condition).
+ */
+ if (alu->src[0].src.ssa != &instr->dest.dest.ssa)
+ return false;
+ } else if (use->parent_instr->type == nir_instr_type_intrinsic) {
+ nir_intrinsic_instr *const intrin =
+ nir_instr_as_intrinsic(use->parent_instr);
+
+ if (intrin->intrinsic != nir_intrinsic_discard_if)
+ return false;
+ } else {
return false;
+ }
}
return true;
@@ -96,7 +103,7 @@ nir_opt_rematerialize_compares_impl(nir_shader *shader, nir_function_impl *impl)
if (!is_two_src_comparison(alu))
continue;
- if (!all_uses_are_bcsel(alu))
+ if (!all_uses_are_bcsel_or_discard(alu))
continue;
/* At this point it is known that alu is a comparison instruction
@@ -122,14 +129,26 @@ nir_opt_rematerialize_compares_impl(nir_shader *shader, nir_function_impl *impl)
nir_instr_insert_before(use_instr, &clone->instr);
- nir_alu_instr *const use_alu = nir_instr_as_alu(use_instr);
- for (unsigned i = 0; i < nir_op_infos[use_alu->op].num_inputs; i++) {
- if (use_alu->src[i].src.ssa == &alu->dest.dest.ssa) {
- nir_instr_rewrite_src(&use_alu->instr,
- &use_alu->src[i].src,
- nir_src_for_ssa(&clone->dest.dest.ssa));
- progress = true;
+ if (use_instr->type == nir_instr_type_alu) {
+ nir_alu_instr *const use_alu = nir_instr_as_alu(use_instr);
+ for (unsigned i = 0; i < nir_op_infos[use_alu->op].num_inputs; i++) {
+ if (use_alu->src[i].src.ssa == &alu->dest.dest.ssa) {
+ nir_instr_rewrite_src(&use_alu->instr,
+ &use_alu->src[i].src,
+ nir_src_for_ssa(&clone->dest.dest.ssa));
+ progress = true;
+ }
}
+ } else {
+ assert(use_instr->type == nir_instr_type_intrinsic);
+
+ nir_intrinsic_instr *const intrin =
+ nir_instr_as_intrinsic(use_instr);
+
+ nir_instr_rewrite_src(&intrin->instr,
+ &intrin->src[0],
+ nir_src_for_ssa(&clone->dest.dest.ssa));
+ progress = true;
}
}