Commit 0b7f3f47 authored by Timothy Arceri's avatar Timothy Arceri

wip safe late

parent b96807c2
......@@ -328,6 +328,7 @@ radv_shader_compile_to_nir(struct radv_device *device,
do {
progress = false;
NIR_PASS(progress, nir, nir_opt_algebraic_before_ffma);
NIR_PASS(progress, nir, nir_opt_algebraic_late_safe);
} while (progress);
/* Indirect lowering must be called after the radv_optimize_nir() loop
......
......@@ -2906,6 +2906,7 @@ bool nir_lower_ssa_defs_to_regs_block(nir_block *block);
bool nir_opt_algebraic(nir_shader *shader);
bool nir_opt_algebraic_before_ffma(nir_shader *shader);
bool nir_opt_algebraic_late_safe(nir_shader *shader);
bool nir_opt_algebraic_late(nir_shader *shader);
bool nir_opt_constant_folding(nir_shader *shader);
......
......@@ -764,6 +764,19 @@ before_ffma_optimizations = [
(('~fadd', a, ('fadd', ('fneg', a), b)), b),
]
# This section contains "late" optimizations that should be run after the
# regular optimizations have finished. Optimizations should go here if
# they help code generation but do not necessarily produce code that is
# more easily optimizable.
safe_late_optimizations = [
(('b2f(is_used_more_than_once)', ('inot', a)), ('bcsel', a, 0.0, 1.0)),
(('fneg(is_used_more_than_once)', ('b2f', ('inot', a))), ('bcsel', a, -0.0, -1.0)),
# we do these late so that we don't get in the way of creating ffmas
(('fmin', ('fadd(is_used_once)', '#c', a), ('fadd(is_used_once)', '#c', b)), ('fadd', c, ('fmin', a, b))),
(('fmax', ('fadd(is_used_once)', '#c', a), ('fadd(is_used_once)', '#c', b)), ('fadd', c, ('fmax', a, b))),
]
# This section contains "late" optimizations that should be run after the
# regular optimizations have finished. Optimizations should go here if
# they help code generation but do not necessarily produce code that is
......@@ -799,5 +812,7 @@ late_optimizations = [
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render())
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic_before_ffma",
before_ffma_optimizations).render())
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic_late_safe",
safe_late_optimizations).render())
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic_late",
late_optimizations).render())
......@@ -832,6 +832,45 @@ si_lower_nir(struct si_shader_selector* sel)
NIR_PASS(progress, sel->nir, nir_opt_loop_unroll, 0);
}
} while (progress);
/* This unfortunately named pass contains optimisations that conflict
* with the regular nir_opt_algebraic() pass and therefore should be
* called after the state trackers opt loops have been run, but before
* the late opt loop in the driver.
*/
do {
progress = false;
NIR_PASS(progress, sel->nir, nir_opt_algebraic_before_ffma);
NIR_PASS(progress, sel->nir, nir_opt_algebraic_late_safe);
} while (progress);
do {
progress = false;
/* (Constant) copy propagation is needed for txf with offsets. */
NIR_PASS(progress, sel->nir, nir_copy_prop);
NIR_PASS(progress, sel->nir, nir_opt_remove_phis);
NIR_PASS(progress, sel->nir, nir_opt_dce);
if (nir_opt_trivial_continues(sel->nir)) {
progress = true;
NIR_PASS(progress, sel->nir, nir_copy_prop);
NIR_PASS(progress, sel->nir, nir_opt_dce);
}
NIR_PASS(progress, sel->nir, nir_opt_if);
NIR_PASS(progress, sel->nir, nir_opt_dead_cf);
NIR_PASS(progress, sel->nir, nir_opt_cse);
NIR_PASS(progress, sel->nir, nir_opt_peephole_select, 8);
/* Needed for algebraic lowering */
NIR_PASS(progress, sel->nir, nir_opt_algebraic);
NIR_PASS(progress, sel->nir, nir_opt_constant_folding);
NIR_PASS(progress, sel->nir, nir_opt_undef);
NIR_PASS(progress, sel->nir, nir_opt_conditional_discard);
if (sel->nir->options->max_unroll_iterations) {
NIR_PASS(progress, sel->nir, nir_opt_loop_unroll, 0);
}
} while (progress);
}
static void declare_nir_input_vs(struct si_shader_context *ctx,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment