[Mesa-dev] [PATCH v2 1/8] nir: evaluate if condition uses inside the if branches

Timothy Arceri tarceri at itsqueeze.com
Fri Jul 27 03:23:14 UTC 2018


On 26/07/18 14:04, Timothy Arceri wrote:
> On 23/07/18 18:02, Timothy Arceri wrote:
>> Since we know what side of the branch we ended up on we can just
>> replace the use with a constant.
>>
>> All the spill changes in shader-db are from Dolphin uber shaders,
>> despite some small regressions the change is clearly positive.
>>
>> shader-db results IVB:
>>
>> total instructions in shared programs: 9999201 -> 9993483 (-0.06%)
>> instructions in affected programs: 163235 -> 157517 (-3.50%)
>> helped: 132
>> HURT: 2
>>
>> total cycles in shared programs: 231670754 -> 219476091 (-5.26%)
>> cycles in affected programs: 143424120 -> 131229457 (-8.50%)
>> helped: 115
>> HURT: 24
>>
>> total spills in shared programs: 4383 -> 4370 (-0.30%)
>> spills in affected programs: 1656 -> 1643 (-0.79%)
>> helped: 9
>> HURT: 18
>>
>> total fills in shared programs: 4610 -> 4581 (-0.63%)
>> fills in affected programs: 374 -> 345 (-7.75%)
>> helped: 6
>> HURT: 0
>> ---
>>   src/compiler/nir/nir_opt_if.c | 124 ++++++++++++++++++++++++++++++++++
>>   1 file changed, 124 insertions(+)
>>
>> diff --git a/src/compiler/nir/nir_opt_if.c 
>> b/src/compiler/nir/nir_opt_if.c
>> index b3d0bf1decb..b3d5046a76e 100644
>> --- a/src/compiler/nir/nir_opt_if.c
>> +++ b/src/compiler/nir/nir_opt_if.c
>> @@ -369,6 +369,87 @@ opt_if_loop_terminator(nir_if *nif)
>>      return true;
>>   }
>> +static void
>> +replace_if_condition_use_with_const(nir_src *use, unsigned nir_boolean,
>> +                                    void *mem_ctx, bool if_condition)
>> +{
>> +   /* Create const */
>> +   nir_load_const_instr *load = nir_load_const_instr_create(mem_ctx, 
>> 1, 32);
>> +   load->value.u32[0] = nir_boolean;
>> +
>> +   if (if_condition) {
>> +      nir_instr_insert_before_cf(&use->parent_if->cf_node,  
>> &load->instr);
>> +   } else if (use->parent_instr->type == nir_instr_type_phi) {
>> +      nir_phi_instr *cond_phi = nir_instr_as_phi(use->parent_instr);
>> +
>> +      bool UNUSED found = false;
>> +      nir_foreach_phi_src(phi_src, cond_phi) {
>> +         if (phi_src->src.ssa == use->ssa) {
>> +            nir_instr_insert_before_block(phi_src->pred, &load->instr);
> 
> I've just noticed this needs to be nir_instr_insert_after_block() 
> otherwise we can end up inserting the const before so other phi which 
> trips up validation.
> 
> I've fixed this locally.

Ok we can't do that either because the last instruction in the block can 
be a jump. So I've reworked this to insert the const after the last phi.


> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list