From e54d29e881d2f5bce62d58b55d9e417c945558ae Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Wed, 9 Jan 2019 14:16:35 -0800 Subject: [PATCH] intel/compiler: Try nir_opt_if once before nir_opt_peephole_select MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The four helped sharders are two pair of SIMD8/SIMD16 fragment shaders in Bioshock Infinite. In all cases the shaders are helped because some comparisons are moved closer to the if-statements that use the condition, and the extra comparison to regenerat the flag is no longer necessary. This should also fix the loop-unrolling regression in every SPIR-V shader generated by glslang. All Gen7+ platforms had similar results. (Skylake shown) total instructions in shared programs: 15047460 -> 15047452 (<.01%) instructions in affected programs: 820 -> 812 (-0.98%) helped: 4 HURT: 0 helped stats (abs) min: 2 max: 2 x̄: 2.00 x̃: 2 helped stats (rel) min: 0.98% max: 0.98% x̄: 0.98% x̃: 0.98% 95% mean confidence interval for instructions value: -2.00 -2.00 95% mean confidence interval for instructions %-change: -0.98% -0.98% Instructions are helped. total cycles in shared programs: 369988163 -> 369988143 (<.01%) cycles in affected programs: 7970 -> 7950 (-0.25%) helped: 4 HURT: 0 helped stats (abs) min: 2 max: 8 x̄: 5.00 x̃: 5 helped stats (rel) min: 0.11% max: 0.36% x̄: 0.24% x̃: 0.24% 95% mean confidence interval for cycles value: -10.51 0.51 95% mean confidence interval for cycles %-change: -0.46% -0.01% Inconclusive result (value mean confidence interval includes 0). Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=109216 Fixes: 8fb8ebfbb05 ("intel/compiler: More peephole select") --- src/intel/compiler/brw_nir.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c index 77c6c4e0e5a..6ba59932b0f 100644 --- a/src/intel/compiler/brw_nir.c +++ b/src/intel/compiler/brw_nir.c @@ -569,6 +569,16 @@ brw_nir_optimize(nir_shader *nir, const struct brw_compiler *compiler, OPT(nir_opt_dce); OPT(nir_opt_cse); + /* Try nir_opt_if once before doing nir_opt_peephole_select. glslang + * generates for-loops with a pattern that nir_opt_peephole_select will + * convert to a nir_op_bcsel. However, this prevents nir_opt_if + * (opt_peel_loop_initial_if specifically) from moving the code to the + * end of the loop and eliminating the if-statement). This prevents the + * loop analysis code from detecting the induction variable, and the + * loop is therefore not unrolled. + */ + OPT(nir_opt_if); + /* Passing 0 to the peephole select pass causes it to convert * if-statements that contain only move instructions in the branches * regardless of the count. -- 2.14.5