Module: Mesa
Branch: staging/22.2
Commit: 32ac1133d0e617458aa0bf6e19baff6e253496fa
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=32ac1133d0e617458aa0bf6e19baff6e253496fa

Author: Pierre-Eric Pelloux-Prayer <[email protected]>
Date:   Mon Aug  8 17:12:14 2022 +0200

nir: add a nir_opt_if_options enum

And don't enable nir_opt_if_optimize_phi_true_false on radeonsi with
LLVM 14 because it crashes Blender.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6976
Cc: mesa-stable
Reviewed-by: Marek Olšák <[email protected]>
Acked-by: Emma Anholt <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17949>
(cherry picked from commit 70891edd9728e7dd73115171fdb03622ce6450ba)

---

 .pick_status.json                                  |  2 +-
 src/amd/vulkan/radv_shader.c                       |  3 ++-
 src/broadcom/vulkan/v3dv_pipeline.c                |  2 +-
 src/compiler/clc/clc.c                             |  2 +-
 src/compiler/glsl/gl_nir_linker.c                  |  2 +-
 src/compiler/nir/nir.h                             |  7 ++++++-
 src/compiler/nir/nir_lower_shader_calls.c          |  2 +-
 src/compiler/nir/nir_opt_if.c                      | 17 +++++++++--------
 src/compiler/nir/tests/opt_if_tests.cpp            |  6 +++---
 src/freedreno/ir3/ir3_nir.c                        |  2 +-
 src/gallium/auxiliary/nir/nir_to_tgsi.c            |  2 +-
 src/gallium/auxiliary/nir/tgsi_to_nir.c            |  2 +-
 src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c |  2 +-
 src/gallium/drivers/freedreno/a2xx/ir2_nir.c       |  2 +-
 src/gallium/drivers/i915/i915_screen.c             |  2 +-
 src/gallium/drivers/r600/sfn/sfn_nir.cpp           |  2 +-
 src/gallium/drivers/radeonsi/si_shader_nir.c       |  5 ++++-
 src/gallium/frontends/lavapipe/lvp_pipeline.c      |  2 +-
 src/intel/compiler/brw_nir.c                       |  2 +-
 src/microsoft/clc/clc_compiler.c                   |  2 +-
 src/microsoft/compiler/nir_to_dxil.c               |  2 +-
 21 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 45b855ded53..18bc2012244 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -4,7 +4,7 @@
         "description": "nir: add a nir_opt_if_options enum",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c
index 961c44a6fc2..52d53e7b1fb 100644
--- a/src/amd/vulkan/radv_shader.c
+++ b/src/amd/vulkan/radv_shader.c
@@ -197,7 +197,8 @@ radv_optimize_nir(struct nir_shader *shader, bool 
optimize_conservatively, bool
          NIR_PASS(progress, shader, nir_opt_remove_phis);
          NIR_PASS(progress, shader, nir_opt_dce);
       }
-      NIR_PASS(progress, shader, nir_opt_if, true);
+      NIR_PASS(progress, shader, nir_opt_if,
+               nir_opt_if_aggressive_last_continue | 
nir_opt_if_optimize_phi_true_false);
       NIR_PASS(progress, shader, nir_opt_dead_cf);
       NIR_PASS(progress, shader, nir_opt_cse);
       NIR_PASS(progress, shader, nir_opt_peephole_select, 8, true, true);
diff --git a/src/broadcom/vulkan/v3dv_pipeline.c 
b/src/broadcom/vulkan/v3dv_pipeline.c
index c5c84e15512..f2cf9d5bd4e 100644
--- a/src/broadcom/vulkan/v3dv_pipeline.c
+++ b/src/broadcom/vulkan/v3dv_pipeline.c
@@ -325,7 +325,7 @@ nir_optimize(nir_shader *nir, bool allow_copies)
 
       OPT(nir_opt_remove_phis);
       OPT(nir_opt_gcm, false);
-      OPT(nir_opt_if, false);
+      OPT(nir_opt_if, nir_opt_if_optimize_phi_true_false);
       OPT(nir_opt_undef);
       OPT(nir_lower_pack);
 
diff --git a/src/compiler/clc/clc.c b/src/compiler/clc/clc.c
index 3d4e9ca857d..efb06de1a0e 100644
--- a/src/compiler/clc/clc.c
+++ b/src/compiler/clc/clc.c
@@ -100,7 +100,7 @@ clc_libclc_optimize(nir_shader *s)
       NIR_PASS(progress, s, nir_copy_prop);
       NIR_PASS(progress, s, nir_opt_remove_phis);
       NIR_PASS(progress, s, nir_opt_dce);
-      NIR_PASS(progress, s, nir_opt_if, true);
+      NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | 
nir_opt_if_optimize_phi_true_false);
       NIR_PASS(progress, s, nir_opt_dead_cf);
       NIR_PASS(progress, s, nir_opt_cse);
       NIR_PASS(progress, s, nir_opt_peephole_select, 8, true, true);
diff --git a/src/compiler/glsl/gl_nir_linker.c 
b/src/compiler/glsl/gl_nir_linker.c
index 356563a78d9..22dbbf2dde9 100644
--- a/src/compiler/glsl/gl_nir_linker.c
+++ b/src/compiler/glsl/gl_nir_linker.c
@@ -75,7 +75,7 @@ gl_nir_opts(nir_shader *nir)
          NIR_PASS(progress, nir, nir_copy_prop);
          NIR_PASS(progress, nir, nir_opt_dce);
       }
-      NIR_PASS(progress, nir, nir_opt_if, false);
+      NIR_PASS(progress, nir, nir_opt_if, 0);
       NIR_PASS(progress, nir, nir_opt_dead_cf);
       NIR_PASS(progress, nir, nir_opt_cse);
       NIR_PASS(progress, nir, nir_opt_peephole_select, 8, true, true);
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index ebc92b474c3..2b28809b30a 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -5500,7 +5500,12 @@ bool nir_opt_gcm(nir_shader *shader, bool value_number);
 
 bool nir_opt_idiv_const(nir_shader *shader, unsigned min_bit_size);
 
-bool nir_opt_if(nir_shader *shader, bool aggressive_last_continue);
+typedef enum {
+   nir_opt_if_aggressive_last_continue = (1 << 0),
+   nir_opt_if_optimize_phi_true_false = (1 << 1),
+} nir_opt_if_options;
+
+bool nir_opt_if(nir_shader *shader, nir_opt_if_options options);
 
 bool nir_opt_intrinsics(nir_shader *shader);
 
diff --git a/src/compiler/nir/nir_lower_shader_calls.c 
b/src/compiler/nir/nir_lower_shader_calls.c
index d6d16a56e34..d68a4396929 100644
--- a/src/compiler/nir/nir_lower_shader_calls.c
+++ b/src/compiler/nir/nir_lower_shader_calls.c
@@ -1214,7 +1214,7 @@ nir_lower_shader_calls(nir_shader *shader,
       replace_resume_with_halt(resume_shaders[i], resume_instr);
       nir_opt_remove_phis(resume_shaders[i]);
       /* Remove the dummy blocks added by flatten_resume_if_ladder() */
-      nir_opt_if(resume_shaders[i], false);
+      nir_opt_if(resume_shaders[i], nir_opt_if_optimize_phi_true_false);
    }
 
    *resume_shaders_out = resume_shaders;
diff --git a/src/compiler/nir/nir_opt_if.c b/src/compiler/nir/nir_opt_if.c
index 0d1a5155138..ea1486b9e11 100644
--- a/src/compiler/nir/nir_opt_if.c
+++ b/src/compiler/nir/nir_opt_if.c
@@ -1597,7 +1597,7 @@ opt_if_merge(nir_if *nif)
 
 static bool
 opt_if_cf_list(nir_builder *b, struct exec_list *cf_list,
-               bool aggressive_last_continue)
+               nir_opt_if_options options)
 {
    bool progress = false;
    foreach_list_typed(nir_cf_node, cf_node, node, cf_list) {
@@ -1608,23 +1608,24 @@ opt_if_cf_list(nir_builder *b, struct exec_list 
*cf_list,
       case nir_cf_node_if: {
          nir_if *nif = nir_cf_node_as_if(cf_node);
          progress |= opt_if_cf_list(b, &nif->then_list,
-                                    aggressive_last_continue);
+                                    options);
          progress |= opt_if_cf_list(b, &nif->else_list,
-                                    aggressive_last_continue);
+                                    options);
          progress |= opt_if_loop_terminator(nif);
          progress |= opt_if_merge(nif);
          progress |= opt_if_simplification(b, nif);
-         progress |= opt_if_phi_is_condition(b, nif);
+         if (options & nir_opt_if_optimize_phi_true_false)
+            progress |= opt_if_phi_is_condition(b, nif);
          break;
       }
 
       case nir_cf_node_loop: {
          nir_loop *loop = nir_cf_node_as_loop(cf_node);
          progress |= opt_if_cf_list(b, &loop->body,
-                                    aggressive_last_continue);
+                                    options);
          progress |= opt_simplify_bcsel_of_phi(b, loop);
          progress |= opt_if_loop_last_continue(loop,
-                                               aggressive_last_continue);
+                                               options & 
nir_opt_if_aggressive_last_continue);
          break;
       }
 
@@ -1717,7 +1718,7 @@ opt_if_safe_cf_list(nir_builder *b, struct exec_list 
*cf_list)
 }
 
 bool
-nir_opt_if(nir_shader *shader, bool aggressive_last_continue)
+nir_opt_if(nir_shader *shader, nir_opt_if_options options)
 {
    bool progress = false;
 
@@ -1736,7 +1737,7 @@ nir_opt_if(nir_shader *shader, bool 
aggressive_last_continue)
 
       bool preserve = true;
 
-      if (opt_if_cf_list(&b, &function->impl->body, aggressive_last_continue)) 
{
+      if (opt_if_cf_list(&b, &function->impl->body, options)) {
          preserve = false;
          progress = true;
       }
diff --git a/src/compiler/nir/tests/opt_if_tests.cpp 
b/src/compiler/nir/tests/opt_if_tests.cpp
index e636a33d63d..7757248d1dc 100644
--- a/src/compiler/nir/tests/opt_if_tests.cpp
+++ b/src/compiler/nir/tests/opt_if_tests.cpp
@@ -79,7 +79,7 @@ TEST_F(nir_opt_if_test, opt_if_simplification)
 
    nir_pop_if(&bld, NULL);
 
-   ASSERT_TRUE(nir_opt_if(bld.shader, false));
+   ASSERT_TRUE(nir_opt_if(bld.shader, nir_opt_if_optimize_phi_true_false));
 
    nir_validate_shader(bld.shader, NULL);
 
@@ -130,7 +130,7 @@ TEST_F(nir_opt_if_test, 
opt_if_simplification_single_source_phi_after_if)
 
    nir_builder_instr_insert(&bld, &phi->instr);
 
-   ASSERT_TRUE(nir_opt_if(bld.shader, false));
+   ASSERT_TRUE(nir_opt_if(bld.shader, nir_opt_if_optimize_phi_true_false));
 
    nir_validate_shader(bld.shader, NULL);
 
@@ -169,7 +169,7 @@ TEST_F(nir_opt_if_test, opt_if_alu_of_phi_progress)
 
    int progress_count = 0;
    for (int i = 0; i < 10; i++) {
-      progress = nir_opt_if(bld.shader, false);
+      progress = nir_opt_if(bld.shader, nir_opt_if_optimize_phi_true_false);
       if (progress)
          progress_count++;
       else
diff --git a/src/freedreno/ir3/ir3_nir.c b/src/freedreno/ir3/ir3_nir.c
index 98d516fd266..1d6ed662156 100644
--- a/src/freedreno/ir3/ir3_nir.c
+++ b/src/freedreno/ir3/ir3_nir.c
@@ -169,7 +169,7 @@ ir3_optimize_loop(struct ir3_compiler *compiler, nir_shader 
*s)
          OPT(s, nir_copy_prop);
          OPT(s, nir_opt_dce);
       }
-      progress |= OPT(s, nir_opt_if, false);
+      progress |= OPT(s, nir_opt_if, nir_opt_if_optimize_phi_true_false);
       progress |= OPT(s, nir_opt_loop_unroll);
       progress |= OPT(s, nir_lower_64bit_phis);
       progress |= OPT(s, nir_opt_remove_phis);
diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.c 
b/src/gallium/auxiliary/nir/nir_to_tgsi.c
index 2cfc4ebf035..eb45c390160 100644
--- a/src/gallium/auxiliary/nir/nir_to_tgsi.c
+++ b/src/gallium/auxiliary/nir/nir_to_tgsi.c
@@ -3182,7 +3182,7 @@ ntt_optimize_nir(struct nir_shader *s, struct pipe_screen 
*screen)
       NIR_PASS(progress, s, nir_opt_copy_prop_vars);
       NIR_PASS(progress, s, nir_opt_dead_write_vars);
 
-      NIR_PASS(progress, s, nir_opt_if, true);
+      NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | 
nir_opt_if_optimize_phi_true_false);
       NIR_PASS(progress, s, nir_opt_peephole_select,
                control_flow_depth == 0 ? ~0 : 8, true, true);
       NIR_PASS(progress, s, nir_opt_algebraic);
diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c 
b/src/gallium/auxiliary/nir/tgsi_to_nir.c
index 9a281c40587..363387cccdc 100644
--- a/src/gallium/auxiliary/nir/tgsi_to_nir.c
+++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c
@@ -2474,7 +2474,7 @@ ttn_optimize_nir(nir_shader *nir)
          NIR_PASS(progress, nir, nir_copy_prop);
          NIR_PASS(progress, nir, nir_opt_dce);
       }
-      NIR_PASS(progress, nir, nir_opt_if, false);
+      NIR_PASS(progress, nir, nir_opt_if, nir_opt_if_optimize_phi_true_false);
       NIR_PASS(progress, nir, nir_opt_dead_cf);
       NIR_PASS(progress, nir, nir_opt_cse);
       NIR_PASS(progress, nir, nir_opt_peephole_select, 8, true, true);
diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c 
b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c
index ef8baf3f75c..acd341da983 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c
@@ -167,7 +167,7 @@ etna_optimize_loop(nir_shader *s)
          OPT(s, nir_opt_dce);
       }
       progress |= OPT(s, nir_opt_loop_unroll);
-      progress |= OPT(s, nir_opt_if, false);
+      progress |= OPT(s, nir_opt_if, nir_opt_if_optimize_phi_true_false);
       progress |= OPT(s, nir_opt_remove_phis);
       progress |= OPT(s, nir_opt_undef);
    }
diff --git a/src/gallium/drivers/freedreno/a2xx/ir2_nir.c 
b/src/gallium/drivers/freedreno/a2xx/ir2_nir.c
index a36c1e4b777..0218975625d 100644
--- a/src/gallium/drivers/freedreno/a2xx/ir2_nir.c
+++ b/src/gallium/drivers/freedreno/a2xx/ir2_nir.c
@@ -96,7 +96,7 @@ ir2_optimize_loop(nir_shader *s)
          OPT(s, nir_opt_dce);
       }
       progress |= OPT(s, nir_opt_loop_unroll);
-      progress |= OPT(s, nir_opt_if, false);
+      progress |= OPT(s, nir_opt_if, nir_opt_if_optimize_phi_true_false);
       progress |= OPT(s, nir_opt_remove_phis);
       progress |= OPT(s, nir_opt_undef);
 
diff --git a/src/gallium/drivers/i915/i915_screen.c 
b/src/gallium/drivers/i915/i915_screen.c
index 06a48259122..2b12968fe2f 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -202,7 +202,7 @@ i915_optimize_nir(struct nir_shader *s)
       NIR_PASS(progress, s, nir_opt_dead_cf);
       NIR_PASS(progress, s, nir_opt_cse);
       NIR_PASS(progress, s, nir_opt_find_array_copies);
-      NIR_PASS(progress, s, nir_opt_if, true);
+      NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | 
nir_opt_if_optimize_phi_true_false);
       NIR_PASS(progress, s, nir_opt_peephole_select, ~0 /* flatten all IFs. */,
                true, true);
       NIR_PASS(progress, s, nir_opt_algebraic);
diff --git a/src/gallium/drivers/r600/sfn/sfn_nir.cpp 
b/src/gallium/drivers/r600/sfn/sfn_nir.cpp
index 9d8af3bafea..5609c03f290 100644
--- a/src/gallium/drivers/r600/sfn/sfn_nir.cpp
+++ b/src/gallium/drivers/r600/sfn/sfn_nir.cpp
@@ -560,7 +560,7 @@ optimize_once(nir_shader *shader)
            NIR_PASS(progress, shader, nir_opt_dce);
    }
 
-   NIR_PASS(progress, shader, nir_opt_if, false);
+   NIR_PASS(progress, shader, nir_opt_if, nir_opt_if_optimize_phi_true_false);
    NIR_PASS(progress, shader, nir_opt_dead_cf);
    NIR_PASS(progress, shader, nir_opt_cse);
    NIR_PASS(progress, shader, nir_opt_peephole_select, 200, true, true);
diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c 
b/src/gallium/drivers/radeonsi/si_shader_nir.c
index 896cfef56b9..3ca2bf8adda 100644
--- a/src/gallium/drivers/radeonsi/si_shader_nir.c
+++ b/src/gallium/drivers/radeonsi/si_shader_nir.c
@@ -80,7 +80,10 @@ void si_nir_opts(struct si_screen *sscreen, struct 
nir_shader *nir, bool first)
       NIR_PASS(progress, nir, nir_copy_prop);
       NIR_PASS(progress, nir, nir_opt_remove_phis);
       NIR_PASS(progress, nir, nir_opt_dce);
-      NIR_PASS(lower_phis_to_scalar, nir, nir_opt_if, true);
+      /* nir_opt_if_optimize_phi_true_false is disabled on LLVM14 (#6976) */
+      NIR_PASS(lower_phis_to_scalar, nir, nir_opt_if,
+         nir_opt_if_aggressive_last_continue |
+            (LLVM_VERSION_MAJOR == 14 ? 0 : 
nir_opt_if_optimize_phi_true_false));
       NIR_PASS(progress, nir, nir_opt_dead_cf);
 
       if (lower_alu_to_scalar)
diff --git a/src/gallium/frontends/lavapipe/lvp_pipeline.c 
b/src/gallium/frontends/lavapipe/lvp_pipeline.c
index 4c4e410df11..cf523f2f81a 100644
--- a/src/gallium/frontends/lavapipe/lvp_pipeline.c
+++ b/src/gallium/frontends/lavapipe/lvp_pipeline.c
@@ -355,7 +355,7 @@ optimize(nir_shader *nir)
          NIR_PASS(progress, nir, nir_opt_dce);
          NIR_PASS(progress, nir, nir_opt_remove_phis);
       }
-      NIR_PASS(progress, nir, nir_opt_if, true);
+      NIR_PASS(progress, nir, nir_opt_if, nir_opt_if_aggressive_last_continue 
| nir_opt_if_optimize_phi_true_false);
       NIR_PASS(progress, nir, nir_opt_dead_cf);
       NIR_PASS(progress, nir, nir_opt_conditional_discard);
       NIR_PASS(progress, nir, nir_opt_remove_phis);
diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c
index 659d10c4f00..9516e5c5102 100644
--- a/src/intel/compiler/brw_nir.c
+++ b/src/intel/compiler/brw_nir.c
@@ -625,7 +625,7 @@ brw_nir_optimize(nir_shader *nir, const struct brw_compiler 
*compiler,
          OPT(nir_copy_prop);
          OPT(nir_opt_dce);
       }
-      OPT(nir_opt_if, false);
+      OPT(nir_opt_if, nir_opt_if_optimize_phi_true_false);
       OPT(nir_opt_conditional_discard);
       if (nir->options->max_unroll_iterations != 0) {
          OPT(nir_opt_loop_unroll);
diff --git a/src/microsoft/clc/clc_compiler.c b/src/microsoft/clc/clc_compiler.c
index dc8f31234de..71df73628f9 100644
--- a/src/microsoft/clc/clc_compiler.c
+++ b/src/microsoft/clc/clc_compiler.c
@@ -856,7 +856,7 @@ clc_spirv_to_dxil(struct clc_libclc *lib,
          NIR_PASS(progress, nir, nir_lower_var_copies);
          NIR_PASS(progress, nir, nir_lower_vars_to_ssa);
          NIR_PASS(progress, nir, nir_opt_algebraic);
-         NIR_PASS(progress, nir, nir_opt_if, true);
+         NIR_PASS(progress, nir, nir_opt_if, 
nir_opt_if_aggressive_last_continue | nir_opt_if_optimize_phi_true_false);
          NIR_PASS(progress, nir, nir_opt_dead_cf);
          NIR_PASS(progress, nir, nir_opt_remove_phis);
          NIR_PASS(progress, nir, nir_opt_peephole_select, 8, true, true);
diff --git a/src/microsoft/compiler/nir_to_dxil.c 
b/src/microsoft/compiler/nir_to_dxil.c
index 78434441b10..5561c872709 100644
--- a/src/microsoft/compiler/nir_to_dxil.c
+++ b/src/microsoft/compiler/nir_to_dxil.c
@@ -5600,7 +5600,7 @@ optimize_nir(struct nir_shader *s, const struct 
nir_to_dxil_options *opts)
          NIR_PASS(progress, s, dxil_nir_lower_16bit_conv);
       NIR_PASS(progress, s, nir_opt_remove_phis);
       NIR_PASS(progress, s, nir_opt_dce);
-      NIR_PASS(progress, s, nir_opt_if, true);
+      NIR_PASS(progress, s, nir_opt_if, nir_opt_if_aggressive_last_continue | 
nir_opt_if_optimize_phi_true_false);
       NIR_PASS(progress, s, nir_opt_dead_cf);
       NIR_PASS(progress, s, nir_opt_cse);
       NIR_PASS(progress, s, nir_opt_peephole_select, 8, true, true);

Reply via email to