[PATCH] D26877: Minor fixes in Loop Strength Reduction

Wei Mi via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 21 15:23:42 PST 2016


I attached the testcase: test/Transforms/LoopStrengthReduce/X86/bestreg.ll

The testcase is relatively large because otherwise the pruning search
space heuristic will not be triggered.

For the testcase, without the patch, we will generate two
getelementptrs for the address of every store inside of loop. With the
patch, we only generate one getelementptr for the address of every
store. The different number of getelementptrs will translate to
instruction number difference inside of inner loop.

Thanks,
Wei.



On Mon, Nov 21, 2016 at 2:33 PM, Wei Mi <wmi at google.com> wrote:
> We found a testcase related with item3 and the patch here fixed it. I
> will contribute a testcase soon. Thanks for the patch!
>
> Thanks,
> Wei.
>
>
> On Mon, Nov 21, 2016 at 2:18 PM, Evgeny Stupachenko <evstupac at gmail.com> wrote:
>> evstupac updated this revision to Diff 78784.
>> evstupac added a comment.
>>
>> "2. Debug print: ..." committed separately.
>>
>>
>> Repository:
>>   rL LLVM
>>
>> https://reviews.llvm.org/D26877
>>
>> Files:
>>   lib/Transforms/Scalar/LoopStrengthReduce.cpp
>>
>>
>> Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp
>> ===================================================================
>> --- lib/Transforms/Scalar/LoopStrengthReduce.cpp
>> +++ lib/Transforms/Scalar/LoopStrengthReduce.cpp
>> @@ -1674,7 +1674,7 @@
>>    SmallPtrSet<Use*, MaxChains> IVIncSet;
>>
>>    void OptimizeShadowIV();
>> -  bool FindIVUserForCond(ICmpInst *Cond, IVStrideUse *&CondUse);
>> +  bool FindIVUserForInst(Instruction *Inst, IVStrideUse *&InstUse);
>>    ICmpInst *OptimizeMax(ICmpInst *Cond, IVStrideUse* &CondUse);
>>    void OptimizeLoopTermCond();
>>
>> @@ -1896,15 +1896,15 @@
>>    }
>>  }
>>
>> -/// If Cond has an operand that is an expression of an IV, set the IV user and
>> +/// If Inst has an operand that is an expression of an IV, set the IV user and
>>  /// stride information and return true, otherwise return false.
>> -bool LSRInstance::FindIVUserForCond(ICmpInst *Cond, IVStrideUse *&CondUse) {
>> +bool LSRInstance::FindIVUserForInst(Instruction *Inst, IVStrideUse *&InstUse) {
>>    for (IVStrideUse &U : IU)
>> -    if (U.getUser() == Cond) {
>> +    if (U.getUser() == Inst) {
>>        // NOTE: we could handle setcc instructions with multiple uses here, but
>>        // InstCombine does it as well for simple uses, it's not clear that it
>>        // occurs enough in real life to handle.
>> -      CondUse = &U;
>> +      InstUse = &U;
>>        return true;
>>      }
>>    return false;
>> @@ -2114,7 +2114,7 @@
>>      // Search IVUsesByStride to find Cond's IVUse if there is one.
>>      IVStrideUse *CondUse = nullptr;
>>      ICmpInst *Cond = cast<ICmpInst>(TermBr->getCondition());
>> -    if (!FindIVUserForCond(Cond, CondUse))
>> +    if (!FindIVUserForInst(Cond, CondUse))
>>        continue;
>>
>>      // If the trip count is computed in terms of a max (due to ScalarEvolution
>> @@ -4144,9 +4144,10 @@
>>      for (const SCEV *Reg : RegUses) {
>>        if (Taken.count(Reg))
>>          continue;
>> -      if (!Best)
>> +      if (!Best) {
>>          Best = Reg;
>> -      else {
>> +        BestNum = RegUses.getUsedByIndices(Reg).count();
>> +      } else {
>>          unsigned Count = RegUses.getUsedByIndices(Reg).count();
>>          if (Count > BestNum) {
>>            Best = Reg;
>>
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bestreg.ll
Type: application/octet-stream
Size: 4593 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161121/36d9feff/attachment.obj>


More information about the llvm-commits mailing list