[Mesa-dev] [PATCH 4/4] i965/fs: Add unit tests for predicated break peephole.
Matt Turner
mattst88 at gmail.com
Wed Nov 5 16:13:59 PST 2014
---
src/mesa/drivers/dri/i965/Makefile.am | 8 +
.../drivers/dri/i965/test_fs_predicated_break.cpp | 292 +++++++++++++++++++++
2 files changed, 300 insertions(+)
create mode 100644 src/mesa/drivers/dri/i965/test_fs_predicated_break.cpp
diff --git a/src/mesa/drivers/dri/i965/Makefile.am b/src/mesa/drivers/dri/i965/Makefile.am
index 5809dc6..08eebc1 100644
--- a/src/mesa/drivers/dri/i965/Makefile.am
+++ b/src/mesa/drivers/dri/i965/Makefile.am
@@ -55,11 +55,19 @@ TEST_LIBS = \
TESTS = \
test_eu_compact \
+ test_fs_predicated_break \
test_vec4_copy_propagation \
test_vec4_register_coalesce
check_PROGRAMS = $(TESTS)
+test_fs_predicated_break_SOURCES = \
+ test_verify_cfg.cpp \
+ test_fs_predicated_break.cpp
+test_fs_predicated_break_LDADD = \
+ $(TEST_LIBS) \
+ $(top_builddir)/src/gtest/libgtest.la
+
test_vec4_register_coalesce_SOURCES = \
test_vec4_register_coalesce.cpp
test_vec4_register_coalesce_LDADD = \
diff --git a/src/mesa/drivers/dri/i965/test_fs_predicated_break.cpp b/src/mesa/drivers/dri/i965/test_fs_predicated_break.cpp
new file mode 100644
index 0000000..703abeb
--- /dev/null
+++ b/src/mesa/drivers/dri/i965/test_fs_predicated_break.cpp
@@ -0,0 +1,292 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <gtest/gtest.h>
+#include "test_verify_cfg.h"
+#include "brw_fs.h"
+#include "brw_cfg.h"
+#include "program/program.h"
+
+class predicated_break_test : public ::testing::Test {
+ virtual void SetUp();
+
+public:
+ struct brw_context *brw;
+ struct gl_context *ctx;
+ struct brw_wm_prog_data *prog_data;
+ struct gl_shader_program *shader_prog;
+ struct brw_fragment_program *fp;
+ fs_visitor *v;
+};
+
+class predicated_break_fs_visitor : public fs_visitor
+{
+public:
+ predicated_break_fs_visitor(struct brw_context *brw,
+ struct brw_wm_prog_data *prog_data,
+ struct gl_shader_program *shader_prog)
+ : fs_visitor(brw, NULL, NULL, prog_data, shader_prog, NULL, 8) {}
+};
+
+
+void predicated_break_test::SetUp()
+{
+ brw = (struct brw_context *)calloc(1, sizeof(*brw));
+ ctx = &brw->ctx;
+
+ fp = ralloc(NULL, struct brw_fragment_program);
+ prog_data = ralloc(NULL, struct brw_wm_prog_data);
+ shader_prog = ralloc(NULL, struct gl_shader_program);
+
+ v = new predicated_break_fs_visitor(brw, prog_data, shader_prog);
+
+ _mesa_init_fragment_program(ctx, &fp->program, GL_FRAGMENT_SHADER, 0);
+
+ brw->gen = 4;
+}
+
+static void
+predicate_break(fs_visitor *v)
+{
+ const bool print = false;
+
+ if (print) {
+ fprintf(stderr, "= Before =\n");
+ v->cfg->dump(v);
+ }
+
+ v->opt_peephole_predicated_break();
+
+ if (print) {
+ fprintf(stderr, "\n= After =\n");
+ v->cfg->dump(v);
+ }
+}
+
+/* Tests that the predicated break pass works when neither the IF or ENDIF
+ * instructions are the only instructions in their respective blocks:
+ */
+TEST_F(predicated_break_test, basic)
+{
+ v->emit(BRW_OPCODE_MOV);
+ v->emit(BRW_OPCODE_DO);
+ v->emit(BRW_OPCODE_MOV);
+ v->emit(BRW_OPCODE_IF)->predicate = BRW_PREDICATE_NORMAL;
+ v->emit(BRW_OPCODE_BREAK);
+ v->emit(BRW_OPCODE_ENDIF);
+ v->emit(BRW_OPCODE_MOV);
+ v->emit(BRW_OPCODE_WHILE);
+ v->emit(BRW_OPCODE_MOV);
+
+ /* = Before = = After =
+ *
+ * START B0 START B0
+ * 0: mov(8) 0: mov(8)
+ * END B0 ->B1 END B0 ->B1
+ * START B1 <-B0 <-B3 START B1 <-B0 <-B2
+ * 1: do(8) 1: do(8)
+ * 2: mov(8) 2: mov(8)
+ * 3: (+f0.0) if(8) 3: (+f0.0) break(8)
+ * END B1 ->B2 ->B3 END B1 ->B3 ->B2
+ * START B2 <-B1 START B2 <-B1
+ * 4: break(8) 4: mov(8)
+ * END B2 ->B4 5: while(8)
+ * START B3 <-B1 END B2 ->B1
+ * 5: endif(8) START B3 <-B1
+ * 6: mov(8) 6: mov(8)
+ * 7: while(8) END B3
+ * END B3 ->B1
+ * START B4 <-B2
+ * 8: mov(8)
+ * END B4
+ */
+
+ v->calculate_cfg();
+ EXPECT_EQ(5, v->cfg->num_blocks);
+ predicate_break(v);
+ EXPECT_EQ(4, v->cfg->num_blocks);
+ verify_cfg(v);
+}
+
+/* Tests that the predicated break pass works when the IF instruction is the
+ * only instruction in its block and we can merge the BREAK into the previous
+ * block.
+ */
+TEST_F(predicated_break_test, can_merge_with_earlier_block)
+{
+ v->emit(BRW_OPCODE_MOV);
+ v->emit(BRW_OPCODE_DO);
+ v->emit(BRW_OPCODE_IF)->predicate = BRW_PREDICATE_NORMAL;
+ v->emit(BRW_OPCODE_ENDIF);
+ v->emit(BRW_OPCODE_IF)->predicate = BRW_PREDICATE_NORMAL;
+ v->emit(BRW_OPCODE_BREAK);
+ v->emit(BRW_OPCODE_ENDIF);
+ v->emit(BRW_OPCODE_MOV);
+ v->emit(BRW_OPCODE_WHILE);
+ v->emit(BRW_OPCODE_MOV);
+
+ /* = Before = = After =
+ *
+ * START B0 START B0
+ * 0: mov(8) 0: mov(8)
+ * END B0 ->B1 END B0 ->B1
+ * START B1 <-B0 <-B4 START B1 <-B0 <-B3
+ * 1: do(8) 1: do(8)
+ * 2: (+f0.0) if(8) 2: (+f0.0) if(8)
+ * END B1 ->B2 ->B2 END B1 ->B2 ->B2
+ * START B2 <-B1 <-B1 START B2 <-B1 <-B1
+ * 3: endif(8) 3: endif(8)
+ * 4: (+f0.0) if(8) 4: (+f0.0) break(8)
+ * END B2 ->B3 ->B4 END B2 ->B4 ->B3
+ * START B3 <-B2 START B3 <-B2
+ * 5: break(8) 5: mov(8)
+ * END B3 ->B5 6: while(8)
+ * START B4 <-B2 END B3 ->B1
+ * 6: endif(8) START B4 <-B2
+ * 7: mov(8) 7: mov(8)
+ * 8: while(8) END B4
+ * END B4 ->B1
+ * START B5 <-B3
+ * 9: mov(8)
+ * END B5
+ */
+
+ v->calculate_cfg();
+ EXPECT_EQ(6, v->cfg->num_blocks);
+ predicate_break(v);
+ EXPECT_EQ(5, v->cfg->num_blocks);
+ verify_cfg(v);
+}
+
+/* Tests that the predicated break pass works when the IF instruction is the
+ * only instruction in its block and we cannot merge the BREAK into the
+ * previous block.
+ */
+TEST_F(predicated_break_test, cannot_merge_with_earlier_block)
+{
+ v->emit(BRW_OPCODE_MOV);
+ v->emit(BRW_OPCODE_DO);
+ v->emit(v->IF(BRW_PREDICATE_NORMAL));
+ v->emit(v->IF(BRW_PREDICATE_NORMAL));
+ v->emit(BRW_OPCODE_BREAK);
+ v->emit(BRW_OPCODE_ENDIF);
+ v->emit(BRW_OPCODE_ENDIF);
+ v->emit(BRW_OPCODE_MOV);
+ v->emit(BRW_OPCODE_WHILE);
+ v->emit(BRW_OPCODE_MOV);
+
+ /* = Before = = After =
+ * START B0 START B0
+ * 0: mov(8) 0: mov(8)
+ * END B0 ->B1 END B0 ->B1
+ * START B1 <-B0 <-B5 START B1 <-B0 <-B3
+ * 1: do(8) 1: do(8)
+ * 2: (+f0.0) if(8) 2: (+f0.0) if(8)
+ * END B1 ->B2 ->B5 END B1 ->B3 ->B2
+ * START B2 <-B1 START B2 <-B1
+ * 3: (+f0.0) if(8) 3: (+f0.0) break(8)
+ * END B2 ->B3 ->B4 END B2 ->B4 ->B3
+ * START B3 <-B2 START B3 <-B1 <-B2
+ * 4: break(8) 4: endif(8)
+ * END B3 ->B6 5: mov(8)
+ * START B4 <-B2 6: while(8)
+ * 5: endif(8) END B3 ->B1
+ * END B4 ->B5 START B4 <-B2
+ * START B5 <-B4 <-B1 7: mov(8)
+ * 6: endif(8) END B4
+ * 7: mov(8)
+ * 8: while(8)
+ * END B5 ->B1
+ * START B6 <-B3
+ * 9: mov(8)
+ * END B6
+ */
+
+ v->calculate_cfg();
+ EXPECT_EQ(7, v->cfg->num_blocks);
+ predicate_break(v);
+ EXPECT_EQ(5, v->cfg->num_blocks);
+ verify_cfg(v);
+}
+
+/* Tests that the predicated break pass works in the presence of a nested
+ * loop.
+ */
+TEST_F(predicated_break_test, nested_loop)
+{
+ v->emit(BRW_OPCODE_MOV);
+ v->emit(BRW_OPCODE_DO);
+ v->emit(v->IF(BRW_PREDICATE_NORMAL));
+ v->emit(BRW_OPCODE_BREAK);
+ v->emit(BRW_OPCODE_ENDIF);
+ v->emit(BRW_OPCODE_DO);
+ v->emit(v->IF(BRW_PREDICATE_NORMAL));
+ v->emit(BRW_OPCODE_BREAK);
+ v->emit(BRW_OPCODE_ENDIF);
+ v->emit(BRW_OPCODE_MOV);
+ v->emit(BRW_OPCODE_WHILE);
+ v->emit(BRW_OPCODE_MOV);
+ v->emit(BRW_OPCODE_WHILE);
+ v->emit(BRW_OPCODE_MOV);
+
+ /* = Before = = After =
+ * START B0 START B0
+ * 0: mov(8) 0: mov(8)
+ * END B0 ->B1 END B0 ->B1
+ * START B1 <-B0 <-B7 START B1 <-B0 <-B4
+ * 1: do(8) 1: do(8)
+ * 2: (+f0.0) if(8) 2: (+f0.0) break(8)
+ * END B1 ->B2 ->B3 END B1 ->B5 ->B2
+ * START B2 <-B1 START B2 <-B3 <-B1
+ * 3: break(8) 3: do(8)
+ * END B2 ->B8 4: (+f0.0) break(8)
+ * START B3 <-B1 END B2 ->B4 ->B3
+ * 4: endif(8) START B3 <-B2
+ * END B3 ->B4 5: mov(8)
+ * START B4 <-B3 <-B6 6: while(8)
+ * 5: do(8) END B3 ->B2
+ * 6: (+f0.0) if(8) START B4 <-B2
+ * END B4 ->B5 ->B6 7: mov(8)
+ * START B5 <-B4 8: while(8)
+ * 7: break(8) END B4 ->B1
+ * END B5 ->B7 START B5 <-B1
+ * START B6 <-B4 9: mov(8)
+ * 8: endif(8) END B5
+ * 9: mov(8)
+ * 10: while(8)
+ * END B6 ->B4
+ * START B7 <-B5
+ * 11: mov(8)
+ * 12: while(8)
+ * END B7 ->B1
+ * START B8 <-B2
+ * 13: mov(8)
+ * END B8
+ */
+
+ v->calculate_cfg();
+ EXPECT_EQ(9, v->cfg->num_blocks);
+ predicate_break(v);
+ EXPECT_EQ(6, v->cfg->num_blocks);
+ verify_cfg(v);
+}
--
2.0.4
More information about the mesa-dev
mailing list