From b2ce7da14986bb4d0835894744ac48614c4da9f6 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Fri, 30 Oct 2020 15:54:12 +0000 Subject: [PATCH] radv: do nir_lower_bit_size after algebraic optimizations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are too many algebraic optimizations to be certain that one of them couldn't create instructions which need lowering. It also creates better code for some reason. fossil-db (parallel-rdp, Navi): Totals from 217 (31.77% of 683) affected shaders: VGPRs: 7716 -> 7672 (-0.57%) CodeSize: 1516152 -> 1510688 (-0.36%); split: -0.38%, +0.02% MaxWaves: 3964 -> 3982 (+0.45%) Instrs: 269445 -> 268508 (-0.35%); split: -0.36%, +0.02% Cycles: 37963416 -> 37912592 (-0.13%); split: -0.15%, +0.01% Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Part-of: --- src/amd/vulkan/radv_pipeline.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c index 75858298a66..61ec8580c7f 100644 --- a/src/amd/vulkan/radv_pipeline.c +++ b/src/amd/vulkan/radv_pipeline.c @@ -3147,9 +3147,6 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline, if (!radv_use_llvm_for_stage(device, i)) nir_lower_int64(nir[i]); - if (nir_lower_bit_size(nir[i], lower_bit_size_callback, NULL)) - nir_copy_prop(nir[i]); /* allow nir_opt_idiv_const() to optimize lowered divisions */ - /* TODO: Implement nir_op_uadd_sat with LLVM. */ if (!radv_use_llvm_for_stage(device, i)) nir_opt_idiv_const(nir[i], 32); @@ -3181,6 +3178,12 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline, NIR_PASS_V(nir[i], nir_opt_cse); } + if (nir_lower_bit_size(nir[i], lower_bit_size_callback, NULL)) { + nir_lower_idiv(nir[i], nir_lower_idiv_precise); + nir_opt_constant_folding(nir[i]); + nir_opt_dce(nir[i]); + } + /* cleanup passes */ nir_lower_load_const_to_scalar(nir[i]); nir_move_options move_opts = (nir_move_options)(