[Mesa-dev] [PATCH 2/3] nir: Try commutative sources in CSE
Jason Ekstrand
jason at jlekstrand.net
Tue Apr 14 12:50:24 PDT 2015
On Tue, Apr 14, 2015 at 12:33 PM, Connor Abbott <cwabbott0 at gmail.com> wrote:
> On Tue, Apr 14, 2015 at 11:43 AM, Ian Romanick <idr at freedesktop.org> wrote:
>> From: Ian Romanick <ian.d.romanick at intel.com>
>>
>> Shader-db results:
>>
>> GM45 NIR:
>> total instructions in shared programs: 4082044 -> 4081919 (-0.00%)
>> instructions in affected programs: 27609 -> 27484 (-0.45%)
>> helped: 44
>>
>> Iron Lake NIR:
>> total instructions in shared programs: 5678776 -> 5678646 (-0.00%)
>> instructions in affected programs: 27406 -> 27276 (-0.47%)
>> helped: 45
>>
>> Sandy Bridge NIR:
>> total instructions in shared programs: 7329995 -> 7329096 (-0.01%)
>> instructions in affected programs: 142035 -> 141136 (-0.63%)
>> helped: 406
>> HURT: 19
>>
>> Ivy Bridge NIR:
>> total instructions in shared programs: 6769314 -> 6768359 (-0.01%)
>> instructions in affected programs: 140820 -> 139865 (-0.68%)
>> helped: 423
>> HURT: 2
>>
>> Haswell NIR:
>> total instructions in shared programs: 6183693 -> 6183298 (-0.01%)
>> instructions in affected programs: 96538 -> 96143 (-0.41%)
>> helped: 303
>> HURT: 4
>>
>> Broadwell NIR:
>> total instructions in shared programs: 7501711 -> 7498170 (-0.05%)
>> instructions in affected programs: 266403 -> 262862 (-1.33%)
>> helped: 705
>> HURT: 5
>> GAINED: 4
>>
>> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
>> ---
>> src/glsl/nir/nir_opt_cse.c | 18 ++++++++++++++----
>> 1 file changed, 14 insertions(+), 4 deletions(-)
>>
>> diff --git a/src/glsl/nir/nir_opt_cse.c b/src/glsl/nir/nir_opt_cse.c
>> index 03039cf..bd994a8 100644
>> --- a/src/glsl/nir/nir_opt_cse.c
>> +++ b/src/glsl/nir/nir_opt_cse.c
>> @@ -73,10 +73,20 @@ nir_instrs_equal(nir_instr *instr1, nir_instr *instr2)
>> if (alu1->dest.dest.ssa.num_components != alu2->dest.dest.ssa.num_components)
>> return false;
>>
>> - for (unsigned i = 0; i < nir_op_infos[alu1->op].num_inputs; i++) {
>> - if (!nir_alu_srcs_equal(alu1->src[i], alu2->src[i],
>> - (1 << alu1->dest.dest.ssa.num_components) - 1))
>> - return false;
>> + if (nir_op_infos[alu1->op].num_inputs == 2 &&
>> + (nir_op_infos[alu1->op].algebraic_properties & NIR_OP_IS_COMMUTATIVE)) {
>> + const uint8_t read_mask = (1 << alu1->dest.dest.ssa.num_components) - 1;
>
> I was going to recommend that you move this above the if statement,
> but then I realized that this code is actually bogus since for
> not-per-component things like dot product the "read mask" isn't always
> the same as the write mask. I'll send out a bugfix and then you should
> rebase on top of it. The other two patches have my r-b though.
Yeah, we need to fix that...
>> +
>> + return (nir_alu_srcs_equal(alu1->src[0], alu2->src[0], read_mask) &&
>> + nir_alu_srcs_equal(alu1->src[1], alu2->src[1], read_mask)) ||
>> + (nir_alu_srcs_equal(alu1->src[0], alu2->src[1], read_mask) &&
>> + nir_alu_srcs_equal(alu1->src[1], alu2->src[0], read_mask));
>> + } else {
>> + for (unsigned i = 0; i < nir_op_infos[alu1->op].num_inputs; i++) {
>> + if (!nir_alu_srcs_equal(alu1->src[i], alu2->src[i],
>> + (1 << alu1->dest.dest.ssa.num_components) - 1))
>> + return false;
>> + }
>> }
>> return true;
>> }
>> --
>> 2.1.0
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list