[Mesa-dev] [PATCH] i965/fs: Eliminate pointless self-moves.

Kenneth Graunke kenneth at whitecape.org
Sat Nov 3 20:44:38 PDT 2012


We sometimes generate these, and they're so easy to remove...

shader-db results:
total instructions in shared programs: 1394522 -> 1394500 (-0.00%)
instructions in affected programs:     6533 -> 6511 (-0.34%)

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/drivers/dri/i965/brw_fs.cpp | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 777879e..711cde7 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -1379,9 +1379,15 @@ fs_visitor::dead_code_eliminate()
    foreach_list_safe(node, &this->instructions) {
       fs_inst *inst = (fs_inst *)node;
 
-      if (inst->dst.file == GRF && this->virtual_grf_use[inst->dst.reg] <= pc) {
-	 inst->remove();
-	 progress = true;
+      bool self_move =
+         inst->opcode == BRW_OPCODE_MOV && !inst->saturate &&
+         inst->dst.equals(inst->src[0]);
+      bool never_used =
+         inst->dst.file == GRF && this->virtual_grf_use[inst->dst.reg] <= pc;
+
+      if (self_move || never_used) {
+         inst->remove();
+         progress = true;
       }
 
       pc++;
-- 
1.8.0



More information about the mesa-dev mailing list