[Mesa-dev] [PATCH v2] nv50/ir: optimize ADD(SHL(a, b), c) to SHLADD(a, b, c)

Ilia Mirkin imirkin at alum.mit.edu
Tue Oct 11 21:37:23 UTC 2016


On Tue, Oct 11, 2016 at 5:34 PM, Samuel Pitoiset
<samuel.pitoiset at gmail.com> wrote:
>
>
> On 10/11/2016 11:17 PM, Ilia Mirkin wrote:
>>
>> On Tue, Oct 11, 2016 at 5:01 PM, Samuel Pitoiset
>> <samuel.pitoiset at gmail.com> wrote:
>>>
>>> total instructions in shared programs :2286901 -> 2284473 (-0.11%)
>>> total gprs used in shared programs    :335256 -> 335273 (0.01%)
>>> total local used in shared programs   :31968 -> 31968 (0.00%)
>>>
>>>                 local        gpr       inst      bytes
>>>     helped           0          41         852         852
>>>       hurt           0          44          23          23
>>>
>>> v2: - use visit(Instruction *)
>>>     - use getUniqueInsn()
>>>     - use getImmediate()
>>>     - fix mod for src0
>>>
>>> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
>>> ---
>>>  .../drivers/nouveau/codegen/nv50_ir_peephole.cpp   | 87
>>> ++++++++++++++++++++++
>>>  1 file changed, 87 insertions(+)
>>>
>>> diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
>>> b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
>>> index 6efb29e..6045e8b 100644
>>> --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
>>> +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp
>>> @@ -2132,6 +2132,92 @@ AlgebraicOpt::visit(BasicBlock *bb)
>>>
>>>  //
>>> =============================================================================
>>>
>>> +// ADD(SHL(a, b), c) -> SHLADD(a, b, c)
>>> +class LateAlgebraicOpt : public Pass
>>> +{
>>> +private:
>>> +   virtual bool visit(Instruction *);
>>> +
>>> +   void handleADD(Instruction *);
>>> +   bool tryADDToSHLADD(Instruction *);
>>> +};
>>> +
>>> +void
>>> +LateAlgebraicOpt::handleADD(Instruction *add)
>>> +{
>>> +   Value *src0 = add->getSrc(0);
>>> +   Value *src1 = add->getSrc(1);
>>> +
>>> +   if (src0->reg.file != FILE_GPR || src1->reg.file != FILE_GPR)
>>> +      return;
>>> +
>>> +   if (prog->getTarget()->isOpSupported(OP_SHLADD, add->dType))
>>> +      tryADDToSHLADD(add);
>>> +}
>>> +
>>> +// ADD(SHL(a, b), c) -> SHLADD(a, b, c)
>>> +bool
>>> +LateAlgebraicOpt::tryADDToSHLADD(Instruction *add)
>>> +{
>>> +   Value *src0 = add->getSrc(0);
>>> +   Value *src1 = add->getSrc(1);
>>> +   ImmediateValue imm;
>>> +   Instruction *shl;
>>> +   Modifier mod[2];
>>> +   Value *src;
>>> +   int s;
>>> +
>>> +   if (add->saturate || add->usesFlags() || typeSizeof(add->dType) == 8)
>>> +      return false;
>>
>>
>> || isFloatType(add->dType)
>
>
> This is not really needed because we can't do SHL with floats, so the block
> above handles that, but it won't hurt to add this check earlier.

Yeah, but the add can be float. You could have something like

int a;
float bar, foo = uintBitsAsFloat(a << 4) + bar;


More information about the mesa-dev mailing list