i965/fs: Optimize sqrt+inv into rsq.
authorMatt Turner <mattst88@gmail.com>
Sat, 27 Sep 2014 17:34:56 +0000 (10:34 -0700)
committerMatt Turner <mattst88@gmail.com>
Wed, 1 Oct 2014 00:09:34 +0000 (17:09 -0700)
Transform

   sqrt a, b
   rcp  c, a

into

   sqrt a, b
   rsq  c, b

The improvement here is that we've broken a dependency between these
instructions. Leads to 330 fewer INV instructions and 330 more RSQ.

Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/i965/brw_fs.cpp

index ab4ee34b41cb5786ea402b6348bf2fa8a7155b21..19e9cb957e050c8882e24fe5909c039148380602 100644 (file)
@@ -2334,6 +2334,17 @@ fs_visitor::opt_algebraic()
             }
          }
          break;
+      case SHADER_OPCODE_RCP: {
+         fs_inst *prev = (fs_inst *)inst->prev;
+         if (prev->opcode == SHADER_OPCODE_SQRT) {
+            if (inst->src[0].equals(prev->dst)) {
+               inst->opcode = SHADER_OPCODE_RSQ;
+               inst->src[0] = prev->src[0];
+               progress = true;
+            }
+         }
+         break;
+      }
       default:
         break;
       }