[PATCH] D24790: [LoopUnroll] Use the upper bound of the loop trip count to completely unroll loops

Haicheng Wu via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 20 21:52:50 PDT 2016


haicheng created this revision.
haicheng added reviewers: mzolotukhin, mcrosier, mssimpso.
haicheng added a subscriber: llvm-commits.
haicheng set the repository for this revision to rL LLVM.
Herald added a reviewer: tstellarAMD.
Herald added subscribers: nhaehnle, mzolotukhin, mcrosier, sanjoy.

This patch tries to fully unroll loops having break statement like this

```
    for (int i = 0; i < 8; i++) {                                                                     
        if (a[i] == value) {                                                                               
            found = true; 
            break;
        }                                                                                             
    }
```

GCC can fully unroll such loops, but currently LLVM cannot because LLVM only supports loops having exact constant trip counts.   

The upper bound of the trip count can be obtained from calling ScalarEvolution::getMaxBackedgeTakenCount().  Part of the patch is the refactoring work in SCEV to prevent duplicating code.

The feature of using the upper bound is enabled under the same circumstance when runtime unrolling is enabled since both are used to unroll loops without knowing the exact constant trip count.

The modified test/CodeGen/AMDGPU/tti-unroll-prefs.ll can be used as the test case of this patch.

Repository:
  rL LLVM

https://reviews.llvm.org/D24790

Files:
  include/llvm/Analysis/ScalarEvolution.h
  include/llvm/Analysis/TargetTransformInfo.h
  include/llvm/CodeGen/BasicTTIImpl.h
  include/llvm/Transforms/Scalar.h
  include/llvm/Transforms/Scalar/LoopUnrollPass.h
  include/llvm/Transforms/Utils/UnrollLoop.h
  lib/Analysis/ScalarEvolution.cpp
  lib/Transforms/Scalar/LoopUnrollPass.cpp
  lib/Transforms/Utils/LoopUnroll.cpp
  test/CodeGen/AMDGPU/tti-unroll-prefs.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24790.72006.patch
Type: text/x-patch
Size: 19454 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160921/834cc9b9/attachment.bin>


More information about the llvm-commits mailing list