Module: Mesa
Branch: main
Commit: 3040aa2e264bd1351a14eb385486e0677e5e0a20
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=3040aa2e264bd1351a14eb385486e0677e5e0a20

Author: Marek Olšák <[email protected]>
Date:   Sat Jul  8 22:25:19 2023 -0400

ac/llvm: don't convert undef to 0 because nir_opt_undef does it now

TOTALS FROM AFFECTED SHADERS (29663/58918)
  Code Size: 39163724 -> 37842360 (-3.37 %) bytes
  Max Waves: 394813 -> 396334 (0.39 %)
  Outputs: 84616 -> 84616 (0.00 %)
  Patch Outputs: 0 -> 0 (0.00 %)

Reviewed-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24059>

---

 src/amd/llvm/ac_nir_to_llvm.c                 | 37 +++++----------------------
 src/amd/llvm/ac_shader_abi.h                  |  3 ---
 src/gallium/drivers/radeonsi/si_shader_llvm.c |  1 -
 3 files changed, 6 insertions(+), 35 deletions(-)

diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c
index d857d4a85d3..44028d37e71 100644
--- a/src/amd/llvm/ac_nir_to_llvm.c
+++ b/src/amd/llvm/ac_nir_to_llvm.c
@@ -4129,44 +4129,19 @@ static void phi_post_pass(struct ac_nir_context *ctx)
    }
 }
 
-static bool is_def_used_in_an_export(const nir_def *def)
-{
-   nir_foreach_use (use_src, def) {
-      if (use_src->parent_instr->type == nir_instr_type_intrinsic) {
-         nir_intrinsic_instr *instr = 
nir_instr_as_intrinsic(use_src->parent_instr);
-         if (instr->intrinsic == nir_intrinsic_store_deref)
-            return true;
-      } else if (use_src->parent_instr->type == nir_instr_type_alu) {
-         nir_alu_instr *instr = nir_instr_as_alu(use_src->parent_instr);
-         if (instr->op == nir_op_vec4 && 
is_def_used_in_an_export(&instr->def)) {
-            return true;
-         }
-      }
-   }
-   return false;
-}
-
 static void visit_ssa_undef(struct ac_nir_context *ctx, const nir_undef_instr 
*instr)
 {
    unsigned num_components = instr->def.num_components;
    LLVMTypeRef type = LLVMIntTypeInContext(ctx->ac.context, 
instr->def.bit_size);
 
-   if (!ctx->abi->convert_undef_to_zero || 
is_def_used_in_an_export(&instr->def)) {
-      LLVMValueRef undef;
+   LLVMValueRef undef;
 
-      if (num_components == 1)
-         undef = LLVMGetUndef(type);
-      else {
-         undef = LLVMGetUndef(LLVMVectorType(type, num_components));
-      }
-      ctx->ssa_defs[instr->def.index] = undef;
-   } else {
-      LLVMValueRef zero = LLVMConstInt(type, 0, false);
-      if (num_components > 1) {
-         zero = ac_build_gather_values_extended(&ctx->ac, &zero, 
num_components, 0, false);
-      }
-      ctx->ssa_defs[instr->def.index] = zero;
+   if (num_components == 1)
+      undef = LLVMGetUndef(type);
+   else {
+      undef = LLVMGetUndef(LLVMVectorType(type, num_components));
    }
+   ctx->ssa_defs[instr->def.index] = undef;
 }
 
 static bool visit_jump(struct ac_llvm_context *ctx, const nir_jump_instr 
*instr)
diff --git a/src/amd/llvm/ac_shader_abi.h b/src/amd/llvm/ac_shader_abi.h
index d505482b77f..4dee4ad2813 100644
--- a/src/amd/llvm/ac_shader_abi.h
+++ b/src/amd/llvm/ac_shader_abi.h
@@ -79,9 +79,6 @@ struct ac_shader_abi {
    /* Check for Inf interpolation coeff */
    bool kill_ps_if_inf_interp;
 
-   /* Whether undef values must be converted to zero */
-   bool convert_undef_to_zero;
-
    /* Clamp div by 0 (so it won't produce NaN) */
    bool clamp_div_by_zero;
 
diff --git a/src/gallium/drivers/radeonsi/si_shader_llvm.c 
b/src/gallium/drivers/radeonsi/si_shader_llvm.c
index 7e496a81605..83a106cfb9f 100644
--- a/src/gallium/drivers/radeonsi/si_shader_llvm.c
+++ b/src/gallium/drivers/radeonsi/si_shader_llvm.c
@@ -741,7 +741,6 @@ static bool si_llvm_translate_nir(struct si_shader_context 
*ctx, struct si_shade
 
    ctx->abi.clamp_shadow_reference = true;
    ctx->abi.robust_buffer_access = true;
-   ctx->abi.convert_undef_to_zero = true;
    ctx->abi.load_grid_size_from_user_sgpr = true;
    ctx->abi.clamp_div_by_zero = ctx->screen->options.clamp_div_by_zero ||
                                 info->options & SI_PROFILE_CLAMP_DIV_BY_ZERO;

Reply via email to