From a53d3ff0b3517bdcd56e2db12b39bc975922419e Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Mon, 24 Jul 2023 12:02:48 +0100 Subject: [PATCH] nir/tests: add nir_opt_dead_cf_test.jump_before_constant_if Signed-off-by: Rhys Perry Reviewed-by: Konstantin Seurer Part-of: --- src/compiler/nir/tests/dce_tests.cpp | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/compiler/nir/tests/dce_tests.cpp b/src/compiler/nir/tests/dce_tests.cpp index 42afcc01af5..373bfc19705 100644 --- a/src/compiler/nir/tests/dce_tests.cpp +++ b/src/compiler/nir/tests/dce_tests.cpp @@ -31,6 +31,14 @@ protected: } }; +class nir_opt_dead_cf_test : public nir_test { +protected: + nir_opt_dead_cf_test() + : nir_test::nir_test("nir_opt_dead_cf_test") + { + } +}; + nir_phi_instr *create_one_source_phi(nir_shader *shader, nir_block *pred, nir_ssa_def *def) { @@ -88,3 +96,44 @@ TEST_F(nir_opt_dce_test, return_before_loop) nir_validate_shader(b->shader, NULL); } + +TEST_F(nir_opt_dead_cf_test, jump_before_constant_if) +{ + /* + * Test that nir_opt_dead_cf removes everything after the jump, instead of trying and failing to + * stitch b0 and b3. + * + * block b0: // preds: + * 1 %0 = load_const (false) + * return + * // succs: b4 + * if %0 (false) { + * block b1: // preds: + * 32 %1 = load_const (0x00000001) + * 32 %2 = deref_var &out (shader_out int) + * @store_deref (%2, %1 (0x1)) (wrmask=x, access=0) + * // succs: b3 + * } else { + * block b2: // preds: , succs: b3 + * } + * block b3: // preds: b1 b2 + * 32 %3 = load_const (0x00000000) + * 32 %4 = deref_var &out (shader_out int) + * @store_deref (%4, %3 (0x0)) (wrmask=x, access=0) + * // succs: b4 + * block b4: + */ + nir_variable *var = nir_variable_create(b->shader, nir_var_shader_out, glsl_int_type(), "out"); + + nir_ssa_def *cond = nir_imm_false(b); + nir_jump(b, nir_jump_return); + nir_push_if(b, cond); + nir_store_var(b, var, nir_imm_int(b, 1), 0x1); + nir_pop_if(b, NULL); + + nir_store_var(b, var, nir_imm_int(b, 0), 0x1); + + ASSERT_TRUE(nir_opt_dead_cf(b->shader)); + + nir_validate_shader(b->shader, NULL); +}