i965/fs: Constant-fold immediates in src0 of SEL instructions.
authorEric Anholt <eric@anholt.net>
Sat, 9 Apr 2011 18:29:59 +0000 (08:29 -1000)
committerEric Anholt <eric@anholt.net>
Thu, 14 Apr 2011 00:57:53 +0000 (17:57 -0700)
This is like what we do for add/mul, but we have to invert the
predicate to choose the other source instead.

This removes 5 extra moves of constants in nexuiz shaders.  No
statistically significant performance difference on my Sandybridge
laptop (n=5).

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/i965/brw_eu.c
src/mesa/drivers/dri/i965/brw_eu.h
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs.h

index b59d6b251e6d0ae28801f2160c288a1d5b5af6d6..7e63482d8fa9ec94a6a975dbbd9723552c833999 100644 (file)
@@ -82,6 +82,11 @@ void brw_set_predicate_control( struct brw_compile *p, GLuint pc )
    p->current->header.predicate_control = pc;
 }
 
+void brw_set_predicate_inverse(struct brw_compile *p, bool predicate_inverse)
+{
+   p->current->header.predicate_inverse = predicate_inverse;
+}
+
 void brw_set_conditionalmod( struct brw_compile *p, GLuint conditional )
 {
    p->current->header.destreg__conditionalmod = conditional;
index c2e59c1be13da44d153834397b9bb186b880edeb..718b3800423c27710d5fb1667faab3686814066a 100644 (file)
@@ -772,6 +772,7 @@ void brw_set_access_mode( struct brw_compile *p, GLuint access_mode );
 void brw_set_compression_control( struct brw_compile *p, GLboolean control );
 void brw_set_predicate_control_flag_value( struct brw_compile *p, GLuint value );
 void brw_set_predicate_control( struct brw_compile *p, GLuint pc );
+void brw_set_predicate_inverse(struct brw_compile *p, bool predicate_inverse);
 void brw_set_conditionalmod( struct brw_compile *p, GLuint conditional );
 void brw_set_acc_write_control(struct brw_compile *p, GLuint value);
 
index 128bbe93a323788f220da231d8c71aa9dd14f7aa..5426925e372ea2f2345efc28ce23a5b0b48552b7 100644 (file)
@@ -2963,6 +2963,14 @@ fs_visitor::propagate_constants()
               if (i == 1) {
                  scan_inst->src[i] = inst->src[0];
                  progress = true;
+              } else if (i == 0 && scan_inst->src[1].file != IMM) {
+                 /* Fit this constant in by swapping the operands and
+                  * flipping the predicate
+                  */
+                 scan_inst->src[0] = scan_inst->src[1];
+                 scan_inst->src[1] = inst->src[0];
+                 scan_inst->predicate_inverse = !scan_inst->predicate_inverse;
+                 progress = true;
               }
               break;
            }
@@ -3450,6 +3458,7 @@ fs_visitor::generate_code()
 
       brw_set_conditionalmod(p, inst->conditional_mod);
       brw_set_predicate_control(p, inst->predicated);
+      brw_set_predicate_inverse(p, inst->predicate_inverse);
       brw_set_saturate(p, inst->saturate);
 
       switch (inst->opcode) {
index e48bf40e3e4392beeb5293a30e6c6989c26d55f1..f792906cfe79afeb41132c6818a859d82df0823d 100644 (file)
@@ -331,6 +331,7 @@ public:
    fs_reg src[3];
    bool saturate;
    bool predicated;
+   bool predicate_inverse;
    int conditional_mod; /**< BRW_CONDITIONAL_* */
 
    int mlen; /**< SEND message length */