[Mesa-dev] [PATCH 2/2] i965: Remove redundant discard jumps.
Kenneth Graunke
kenneth at whitecape.org
Mon Aug 18 17:50:17 PDT 2014
With the previous optimization in place, some shaders wind up with
multiple discard jumps in a row, or jumps directly to the next
instruction. We can remove those.
total instructions in shared programs: 5122144 -> 5121604 (-0.01%)
instructions in affected programs: 11928 -> 11388 (-4.53%)
Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
src/mesa/drivers/dri/i965/brw_fs.cpp | 40 ++++++++++++++++++++++++++++++++++++
src/mesa/drivers/dri/i965/brw_fs.h | 1 +
2 files changed, 41 insertions(+)
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 6d80603..8cace49 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -2177,6 +2177,45 @@ fs_visitor::opt_conditional_discard()
return progress;
}
+/**
+ * Remove redundant or useless discard jumps.
+ *
+ * For example, we can eliminate jumps in the following sequence:
+ *
+ * discard-jump (redundant with the next jump)
+ * discard-jump (useless; jumps to the next instruction)
+ * placeholder-halt
+ */
+bool
+fs_visitor::opt_redundant_discard_jumps()
+{
+ bool progress = false;
+
+ fs_inst *placeholder_halt = NULL;
+ foreach_in_list_reverse(fs_inst, inst, &instructions) {
+ if (inst->opcode == FS_OPCODE_PLACEHOLDER_HALT) {
+ placeholder_halt = inst;
+ break;
+ }
+ }
+
+ if (!placeholder_halt)
+ return false;
+
+ /* Delete any HALTs immediately before the placeholder halt. */
+ for (fs_inst *prev = (fs_inst *) placeholder_halt->prev;
+ prev->opcode == FS_OPCODE_DISCARD_JUMP;
+ prev = (fs_inst *) placeholder_halt->prev) {
+ prev->remove();
+ progress = true;
+ }
+
+ if (progress)
+ invalidate_live_intervals();
+
+ return progress;
+}
+
bool
fs_visitor::compute_to_mrf()
{
@@ -3298,6 +3337,7 @@ fs_visitor::run()
OPT(dead_control_flow_eliminate, this);
OPT(opt_register_renaming);
OPT(opt_conditional_discard);
+ OPT(opt_redundant_discard_jumps);
OPT(opt_saturate_propagation);
OPT(register_coalesce);
OPT(compute_to_mrf);
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 1660ad7..1de8254 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -333,6 +333,7 @@ public:
void calculate_register_pressure();
bool opt_algebraic();
bool opt_conditional_discard();
+ bool opt_redundant_discard_jumps();
bool opt_cse();
bool opt_cse_local(bblock_t *block);
bool opt_copy_propagate();
--
2.0.2
More information about the mesa-dev
mailing list