[Mesa-dev] [PATCH 4/6] i965/fs: Optimize IF/MOV/ELSE/MOV/ENDIF to SEL when possible.

Kenneth Graunke kenneth at whitecape.org
Mon Aug 12 12:19:04 PDT 2013


On 08/07/2013 03:45 PM, Ian Romanick wrote:
> On 08/05/2013 06:28 PM, Kenneth Graunke wrote:
[snip]
>> + *    (+f0) IF
>> + *    MOV dst src0
>> + *    ELSE
>> + *    MOV dst src1
>> + *    ENDIF
>
> Do we see many cases of
>
>      foo = batman;
>      if (condition)
>          foo = robin;

I haven't seen many cases of that, no.

>> + *
>> + * which can be easily translated into:
>> + *
>> + *    (+f0) SEL dst src0 src1
>> + *
>> + * If src0 is an immediate value, we promote it to a temporary GRF.
>> + */
>> +void
>> +fs_visitor::try_replace_with_sel()
>> +{
>> +   fs_inst *endif_inst = (fs_inst *) instructions.get_tail();
>> +   assert(endif_inst->opcode == BRW_OPCODE_ENDIF);
>> +
>> +   /* Pattern match in reverse: IF, MOV, ELSE, MOV, ENDIF. */
>
> Just curious about the decision to match in reverse...

We do normal code generation for an ir_if, then, after emitting the 
closing ENDIF, check if it fits the pattern.  Since the end of the list 
is just after the ENDIF, and I don't know how many instructions may have 
been generated, it makes sense to do it in reverse.


More information about the mesa-dev mailing list