From 8410b4cdd626d1bd14dcc4dd5b454a5aad76d603 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Mon, 2 Sep 2024 16:25:19 +0100 Subject: [PATCH] nir/tests: add some loop peeling tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rhys Perry Reviewed-by: Daniel Schürmann Part-of: --- src/compiler/nir/tests/opt_loop_tests.cpp | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/compiler/nir/tests/opt_loop_tests.cpp b/src/compiler/nir/tests/opt_loop_tests.cpp index e797adee176..8f894ebd86e 100644 --- a/src/compiler/nir/tests/opt_loop_tests.cpp +++ b/src/compiler/nir/tests/opt_loop_tests.cpp @@ -239,3 +239,49 @@ TEST_F(nir_opt_loop_test, opt_loop_merge_terminators_skip_merge_if_phis_nested_l nir_validate_shader(b->shader, NULL); } + +TEST_F(nir_opt_loop_test, opt_loop_peel_initial_break_ends_with_jump) +{ + nir_loop *loop = nir_push_loop(b); + + /* the break we want to move down: */ + nir_break_if(b, nir_imm_true(b)); + + /* do_work_2: */ + nir_push_if(b, nir_imm_true(b)); + nir_jump(b, nir_jump_continue); + nir_pop_if(b, NULL); + nir_jump(b, nir_jump_return); + + nir_pop_loop(b, loop); + + ASSERT_FALSE(nir_opt_loop(b->shader)); + + nir_validate_shader(b->shader, NULL); +} + +TEST_F(nir_opt_loop_test, opt_loop_peel_initial_break_nontrivial_break) +{ + nir_loop *loop = nir_push_loop(b); + + nir_push_if(b, nir_imm_true(b)); + + nir_push_if(b, nir_imm_true(b)); + nir_push_if(b, nir_imm_true(b)); + nir_jump(b, nir_jump_break); + nir_pop_if(b, NULL); + nir_pop_if(b, NULL); + nir_nop(b); + + nir_jump(b, nir_jump_break); + nir_pop_if(b, NULL); + + /* do_work_2: */ + nir_nop(b); + + nir_pop_loop(b, loop); + + ASSERT_FALSE(nir_opt_loop(b->shader)); + + nir_validate_shader(b->shader, NULL); +}