diff options
author | Hongbin Zheng <etherzhhb@gmail.com> | 2017-05-12 02:17:15 +0000 |
---|---|---|
committer | Hongbin Zheng <etherzhhb@gmail.com> | 2017-05-12 02:17:15 +0000 |
commit | 4fe342cb7560993988dd6f978607a2442a905910 (patch) | |
tree | 8bf533c3b47257ff876e06caa6f0d2469568fef2 /polly/lib/CodeGen/LoopGenerators.cpp | |
parent | 581072e1a6591d65e55b21d6dce2459a3dffe81a (diff) | |
download | bcm5719-llvm-4fe342cb7560993988dd6f978607a2442a905910.tar.gz bcm5719-llvm-4fe342cb7560993988dd6f978607a2442a905910.zip |
[Polly] Generate more 'canonical' induction variable
Today Polly generates induction variable in this way:
polly.indvar = phi 0, polly.indvar.next
...
polly.indvar.next = polly.indvar + stide
polly.loop_cond = predicate polly.indvar, (UB - stride)
Instead of:
polly.indvar = phi 0, polly.indvar.next
...
polly.indvar.next = polly.indvar + stide
polly.loop_cond = predicate polly.indvar.next, UB
The way Polly generate induction variable cause some problem in the indvar simplify pass.
This patch make polly generate the later form, by assuming the induction variable never overflow
Differential Revision: https://reviews.llvm.org/D33089
llvm-svn: 302866
Diffstat (limited to 'polly/lib/CodeGen/LoopGenerators.cpp')
-rw-r--r-- | polly/lib/CodeGen/LoopGenerators.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/polly/lib/CodeGen/LoopGenerators.cpp b/polly/lib/CodeGen/LoopGenerators.cpp index e5f13ff8f4d..8a6258d2182 100644 --- a/polly/lib/CodeGen/LoopGenerators.cpp +++ b/polly/lib/CodeGen/LoopGenerators.cpp @@ -17,11 +17,13 @@ #include "llvm/IR/DataLayout.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Module.h" +#include "llvm/IR/PatternMatch.h" #include "llvm/Support/CommandLine.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" using namespace llvm; using namespace polly; +using namespace PatternMatch; static cl::opt<int> PollyNumThreads("polly-num-threads", @@ -49,6 +51,9 @@ static cl::opt<int> // contains the loop iv 'polly.indvar', the incremented loop iv // 'polly.indvar_next' as well as the condition to check if we execute another // iteration of the loop. After the loop has finished, we branch to ExitBB. +// We expect the type of UB, LB, UB+Stride to be large enough for values that +// UB may take throughout the execution of the loop, including the computation +// of indvar + Stride before the final abort. Value *polly::createLoop(Value *LB, Value *UB, Value *Stride, PollyIRBuilder &Builder, LoopInfo &LI, DominatorTree &DT, BasicBlock *&ExitBB, @@ -123,10 +128,8 @@ Value *polly::createLoop(Value *LB, Value *UB, Value *Stride, IV->addIncoming(LB, PreHeaderBB); Stride = Builder.CreateZExtOrBitCast(Stride, LoopIVType); Value *IncrementedIV = Builder.CreateNSWAdd(IV, Stride, "polly.indvar_next"); - Value *LoopCondition; - UB = Builder.CreateSub(UB, Stride, "polly.adjust_ub"); - LoopCondition = Builder.CreateICmp(Predicate, IV, UB); - LoopCondition->setName("polly.loop_cond"); + Value *LoopCondition = + Builder.CreateICmp(Predicate, IncrementedIV, UB, "polly.loop_cond"); // Create the loop latch and annotate it as such. BranchInst *B = Builder.CreateCondBr(LoopCondition, HeaderBB, ExitBB); |