[Mesa-dev] [PATCH 04/12] nir: Use the flrp lowering pass instead of nir_opt_algebraic
Ian Romanick
idr at freedesktop.org
Sat Aug 25 05:52:09 UTC 2018
From: Ian Romanick <ian.d.romanick at intel.com>
I tried to be very careful while updating all the various drivers, but I
don't have any of that hardware for testing. :( I have CC'ed everyone
responsible for drivers that sets lower_flrp32 or lower_flrp64.
i965 is the only platform that sets always_precise = true, and it is
only set true for fragment shaders. Gen4 and Gen5 both set lower_flrp32
only for vertex shaders. For fragment shaders, nir_op_flrp is lowered
during code generation as a(1-c)+bc. On all other platforms 64-bit
nir_op_flrp and on Gen11 32-bit nir_op_flrp are lowered using the old
nir_opt_algebraic method.
No changes on any other Intel platforms.
Iron Lake
total instructions in shared programs: 7778140 -> 7777710 (<.01%)
instructions in affected programs: 32146 -> 31716 (-1.34%)
helped: 146
HURT: 0
helped stats (abs) min: 2 max: 4 x̄: 2.95 x̃: 2
helped stats (rel) min: 0.54% max: 2.86% x̄: 1.53% x̃: 1.07%
95% mean confidence interval for instructions value: -3.11 -2.78
95% mean confidence interval for instructions %-change: -1.66% -1.40%
Instructions are helped.
total cycles in shared programs: 177866442 -> 177865148 (<.01%)
cycles in affected programs: 1147918 -> 1146624 (-0.11%)
helped: 158
HURT: 0
helped stats (abs) min: 2 max: 16 x̄: 8.19 x̃: 9
helped stats (rel) min: 0.04% max: 0.86% x̄: 0.15% x̃: 0.13%
95% mean confidence interval for cycles value: -8.86 -7.52
95% mean confidence interval for cycles %-change: -0.17% -0.13%
Cycles are helped.
GM45
total instructions in shared programs: 4798115 -> 4797685 (<.01%)
instructions in affected programs: 32146 -> 31716 (-1.34%)
helped: 146
HURT: 0
helped stats (abs) min: 2 max: 4 x̄: 2.95 x̃: 2
helped stats (rel) min: 0.54% max: 2.86% x̄: 1.53% x̃: 1.07%
95% mean confidence interval for instructions value: -3.11 -2.78
95% mean confidence interval for instructions %-change: -1.66% -1.40%
Instructions are helped.
total cycles in shared programs: 122042296 -> 122041002 (<.01%)
cycles in affected programs: 1147924 -> 1146630 (-0.11%)
helped: 158
HURT: 0
helped stats (abs) min: 2 max: 16 x̄: 8.19 x̃: 9
helped stats (rel) min: 0.04% max: 0.86% x̄: 0.15% x̃: 0.13%
95% mean confidence interval for cycles value: -8.86 -7.52
95% mean confidence interval for cycles %-change: -0.17% -0.13%
Cycles are helped.
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Cc: Marek Olšák <marek.olsak at amd.com>
Cc: Rob Clark <robdclark at gmail.com>
Cc: Eric Anholt <eric at anholt.net>
Cc: Dave Airlie <airlied at redhat.com>
Cc: Timothy Arceri <tarceri at itsqueeze.com>
---
src/amd/vulkan/radv_shader.c | 24 ++++++++++++++++++++++++
src/broadcom/compiler/nir_to_vir.c | 22 ++++++++++++++++++++++
src/compiler/nir/nir_opt_algebraic.py | 2 --
src/gallium/drivers/freedreno/ir3/ir3_nir.c | 17 +++++++++++++++++
src/gallium/drivers/radeonsi/si_shader_nir.c | 23 +++++++++++++++++++++++
src/gallium/drivers/vc4/vc4_program.c | 21 +++++++++++++++++++++
src/intel/compiler/brw_nir.c | 22 ++++++++++++++++++++++
src/mesa/state_tracker/st_glsl_to_nir.cpp | 23 +++++++++++++++++++++++
8 files changed, 152 insertions(+), 2 deletions(-)
diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c
index 207e5b050eb..bfccd84d677 100644
--- a/src/amd/vulkan/radv_shader.c
+++ b/src/amd/vulkan/radv_shader.c
@@ -122,6 +122,8 @@ void
radv_optimize_nir(struct nir_shader *shader, bool optimize_conservatively)
{
bool progress;
+ bool need_to_lower_flrp =
+ shader->options->lower_flrp32 || shader->options->lower_flrp64;
do {
progress = false;
@@ -146,6 +148,28 @@ radv_optimize_nir(struct nir_shader *shader, bool optimize_conservatively)
NIR_PASS(progress, shader, nir_opt_peephole_select, 8);
NIR_PASS(progress, shader, nir_opt_algebraic);
NIR_PASS(progress, shader, nir_opt_constant_folding);
+
+ if (need_to_lower_flrp) {
+ bool lower_flrp_progress;
+ NIR_PASS(lower_flrp_progress,
+ shader,
+ nir_lower_flrp,
+ shader->options->lower_flrp32,
+ shader->options->lower_flrp64,
+ false /* always_precise */,
+ shader->options->lower_ffma);
+ if (lower_flrp_progress) {
+ NIR_PASS(progress, shader,
+ nir_opt_constant_folding);
+ progress = true;
+ }
+
+ /* Nothing should rematerialize any flrps, so we only
+ * need to do this lowering once.
+ */
+ need_to_lower_flrp = false;
+ }
+
NIR_PASS(progress, shader, nir_opt_undef);
NIR_PASS(progress, shader, nir_opt_conditional_discard);
if (shader->options->max_unroll_iterations) {
diff --git a/src/broadcom/compiler/nir_to_vir.c b/src/broadcom/compiler/nir_to_vir.c
index 158c1c3e9f3..7d00b558cf5 100644
--- a/src/broadcom/compiler/nir_to_vir.c
+++ b/src/broadcom/compiler/nir_to_vir.c
@@ -1198,6 +1198,8 @@ void
v3d_optimize_nir(struct nir_shader *s)
{
bool progress;
+ bool need_lower_flrp =
+ s->options->lower_flrp32 || s->options->lower_flrp64;
do {
progress = false;
@@ -1213,6 +1215,26 @@ v3d_optimize_nir(struct nir_shader *s)
NIR_PASS(progress, s, nir_opt_peephole_select, 8);
NIR_PASS(progress, s, nir_opt_algebraic);
NIR_PASS(progress, s, nir_opt_constant_folding);
+
+ if (need_to_lower_flrp) {
+ bool lower_flrp_progress;
+
+ NIR_PASS(lower_flrp_progress, s, nir_lower_flrp,
+ s->options->lower_flrp32,
+ s->options->lower_flrp64,
+ false /* always_precise */,
+ s->options->lower_ffma);
+ if (lower_flrp_progress) {
+ NIR_PASS(progress, s, nir_opt_constant_folding);
+ progress = true;
+ }
+
+ /* Nothing should rematerialize any flrps, so we only
+ * need to do this lowering once.
+ */
+ need_to_lower_flrp = false;
+ }
+
NIR_PASS(progress, s, nir_opt_undef);
} while (progress);
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 2e7d9e8bbaf..1db6d7a2bfe 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -130,8 +130,6 @@ optimizations = [
(('~flrp', a, b, ('b2f', c)), ('bcsel', c, b, a), 'options->lower_flrp32'),
(('~flrp', a, 0.0, c), ('fadd', ('fmul', ('fneg', a), c), a)),
- (('flrp at 32', a, b, c), ('fadd', ('fmul', c, ('fsub', b, a)), a), 'options->lower_flrp32'),
- (('flrp at 64', a, b, c), ('fadd', ('fmul', c, ('fsub', b, a)), a), 'options->lower_flrp64'),
(('ffract', a), ('fsub', a, ('ffloor', a)), 'options->lower_ffract'),
(('~fadd', ('fmul', a, ('fadd', 1.0, ('fneg', ('b2f', c)))), ('fmul', b, ('b2f', c))), ('bcsel', c, b, a), 'options->lower_flrp32'),
(('~fadd at 32', ('fmul', a, ('fadd', 1.0, ('fneg', c ))), ('fmul', b, c )), ('flrp', a, b, c), '!options->lower_flrp32'),
diff --git a/src/gallium/drivers/freedreno/ir3/ir3_nir.c b/src/gallium/drivers/freedreno/ir3/ir3_nir.c
index db1d74fdee7..03756f0c0c1 100644
--- a/src/gallium/drivers/freedreno/ir3/ir3_nir.c
+++ b/src/gallium/drivers/freedreno/ir3/ir3_nir.c
@@ -111,6 +111,23 @@ ir3_optimize_loop(nir_shader *s)
progress |= OPT(s, nir_opt_intrinsics);
progress |= OPT(s, nir_opt_algebraic);
progress |= OPT(s, nir_opt_constant_folding);
+
+ if (need_to_lower_flrp) {
+ if (OPT(s, nir_lower_flrp,
+ s->options->lower_flrp32,
+ s->options->lower_flrp64,
+ false /* always_precise */,
+ s->options->lower_ffma)) {
+ OPT(s, nir_opt_constant_folding);
+ progress = true;
+ }
+
+ /* Nothing should rematerialize any flrps, so we only
+ * need to do this lowering once.
+ */
+ need_to_lower_flrp = false;
+ }
+
progress |= OPT(s, nir_opt_dead_cf);
if (OPT(s, nir_opt_trivial_continues)) {
progress |= true;
diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c
index 0aefca22385..f6f36945c86 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -798,6 +798,9 @@ si_lower_nir(struct si_shader_selector* sel)
NIR_PASS_V(sel->nir, nir_lower_load_const_to_scalar);
bool progress;
+ bool need_to_lower_flrp = sel->nir->options->lower_flrp32 ||
+ sel->nir->options->lower_flrp64;
+
do {
progress = false;
@@ -819,6 +822,26 @@ si_lower_nir(struct si_shader_selector* sel)
NIR_PASS(progress, sel->nir, nir_opt_algebraic);
NIR_PASS(progress, sel->nir, nir_opt_constant_folding);
+ if (need_to_lower_flrp) {
+ bool lower_flrp_progress;
+
+ NIR_PASS(lower_flrp_progress, sel->nir, nir_lower_flrp,
+ sel->nir->options->lower_flrp32,
+ sel->nir->options->lower_flrp64,
+ false /* always_precise */,
+ sel->nir->options->lower_ffma);
+ if (lower_flrp_progress) {
+ NIR_PASS(progress, sel->nir,
+ nir_opt_constant_folding);
+ progress = true;
+ }
+
+ /* Nothing should rematerialize any flrps, so we only
+ * need to do this lowering once.
+ */
+ need_to_lower_flrp = false;
+ }
+
NIR_PASS(progress, sel->nir, nir_opt_undef);
NIR_PASS(progress, sel->nir, nir_opt_conditional_discard);
if (sel->nir->options->max_unroll_iterations) {
diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c
index 1d767af1bdb..20e471f2c71 100644
--- a/src/gallium/drivers/vc4/vc4_program.c
+++ b/src/gallium/drivers/vc4/vc4_program.c
@@ -1568,6 +1568,8 @@ static void
vc4_optimize_nir(struct nir_shader *s)
{
bool progress;
+ bool need_to_lower_flrp =
+ s->options->lower_flrp32 || s->options->lower_flrp64;
do {
progress = false;
@@ -1583,6 +1585,25 @@ vc4_optimize_nir(struct nir_shader *s)
NIR_PASS(progress, s, nir_opt_peephole_select, 8);
NIR_PASS(progress, s, nir_opt_algebraic);
NIR_PASS(progress, s, nir_opt_constant_folding);
+ if (need_to_lower_flrp) {
+ bool lower_flrp_progress;
+
+ NIR_PASS(lower_flrp_progress, s, nir_lower_flrp,
+ s->options->lower_flrp32,
+ s->options->lower_flrp64,
+ false /* always_precise */,
+ s->options->lower_ffma);
+ if (lower_flrp_progress) {
+ NIR_PASS(progress, s, nir_opt_constant_folding);
+ progress = true;
+ }
+
+ /* Nothing should rematerialize any flrps, so we only
+ * need to do this lowering once.
+ */
+ need_to_lower_flrp = false;
+ }
+
NIR_PASS(progress, s, nir_opt_undef);
NIR_PASS(progress, s, nir_opt_loop_unroll,
nir_var_shader_in |
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index ef5034d1e1e..bd08e1e1c65 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -539,6 +539,9 @@ brw_nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
brw_nir_no_indirect_mask(compiler, nir->info.stage);
bool progress;
+ bool need_to_lower_flrp =
+ nir->options->lower_flrp32 || nir->options->lower_flrp64;
+
do {
progress = false;
OPT(nir_split_array_vars, nir_var_local);
@@ -570,6 +573,25 @@ brw_nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
OPT(nir_opt_intrinsics);
OPT(nir_opt_algebraic);
OPT(nir_opt_constant_folding);
+
+ if (need_to_lower_flrp) {
+ /* To match the old behavior, set always_precise only for scalar
+ * shader stages.
+ */
+ if (OPT(nir_lower_flrp,
+ nir->options->lower_flrp32,
+ nir->options->lower_flrp64,
+ is_scalar /* always_precise */,
+ compiler->devinfo->gen >= 6)) {
+ OPT(nir_opt_constant_folding);
+ }
+
+ /* Nothing should rematerialize any flrps, so we only need to do this
+ * lowering once.
+ */
+ need_to_lower_flrp = false;
+ }
+
OPT(nir_opt_dead_cf);
if (OPT(nir_opt_trivial_continues)) {
/* If nir_opt_trivial_continues makes progress, then we need to clean
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index ae2c49960c9..2d6b2d2055f 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -321,6 +321,9 @@ void
st_nir_opts(nir_shader *nir, bool scalar)
{
bool progress;
+ bool need_to_lower_flrp =
+ nir->options->lower_flrp32 || nir->options->lower_flrp64;
+
do {
progress = false;
@@ -349,6 +352,26 @@ st_nir_opts(nir_shader *nir, bool scalar)
NIR_PASS(progress, nir, nir_opt_algebraic);
NIR_PASS(progress, nir, nir_opt_constant_folding);
+ if (need_to_lower_flrp) {
+ bool lower_flrp_progress;
+
+ NIR_PASS(lower_flrp_progress, nir, nir_lower_flrp,
+ nir->options->lower_flrp32,
+ nir->options->lower_flrp64,
+ false /* always_precise */,
+ nir->options->lower_ffma);
+ if (lower_flrp_progress) {
+ NIR_PASS(progress, nir,
+ nir_opt_constant_folding);
+ progress = true;
+ }
+
+ /* Nothing should rematerialize any flrps, so we only need to do this
+ * lowering once.
+ */
+ need_to_lower_flrp = false;
+ }
+
NIR_PASS(progress, nir, nir_opt_undef);
NIR_PASS(progress, nir, nir_opt_conditional_discard);
if (nir->options->max_unroll_iterations) {
--
2.14.4
More information about the mesa-dev
mailing list