diff options
author | Tobias Grosser <grosser@fim.uni-passau.de> | 2013-05-16 06:40:24 +0000 |
---|---|---|
committer | Tobias Grosser <grosser@fim.uni-passau.de> | 2013-05-16 06:40:24 +0000 |
commit | 3081b0f5ec95a150a88ae9f80b079c42d686eea3 (patch) | |
tree | 88eac20e4bdecb92a81b9dd5a193dfa25e46a47c | |
parent | 5db6ffd76f50e58467530c63feb098d2ec59410e (diff) | |
download | bcm5719-llvm-3081b0f5ec95a150a88ae9f80b079c42d686eea3.tar.gz bcm5719-llvm-3081b0f5ec95a150a88ae9f80b079c42d686eea3.zip |
Update LoopInfo correctly
When the Polly code generation was written we did not correctly update the
LoopInfo data, but still claimed that the loop information is correct. This
does not only lead to missed optimizations, but it can also cause
miscompilations in case passes such as LoopSimplify are run after Polly.
Reported-by: Sergei Larin <slarin@codeaurora.org>
llvm-svn: 181987
-rw-r--r-- | polly/lib/CodeGen/CodeGeneration.cpp | 9 | ||||
-rw-r--r-- | polly/lib/CodeGen/IslCodeGeneration.cpp | 8 | ||||
-rw-r--r-- | polly/lib/CodeGen/LoopGenerators.cpp | 19 | ||||
-rw-r--r-- | polly/test/Cloog/CodeGen/loop_with_condition_nested.ll | 7 | ||||
-rw-r--r-- | polly/test/Isl/CodeGen/loop_with_condition_nested.ll | 9 | ||||
-rw-r--r-- | polly/test/Isl/single_loop_param_less_equal.ll | 4 |
6 files changed, 51 insertions, 5 deletions
diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp index 06f0fa7854f..753942fea21 100644 --- a/polly/lib/CodeGen/CodeGeneration.cpp +++ b/polly/lib/CodeGen/CodeGeneration.cpp @@ -924,6 +924,13 @@ void ClastStmtCodeGen::codegen(const clast_guard *g) { Builder.CreateBr(MergeBB); Builder.SetInsertPoint(ThenBB->begin()); + LoopInfo &LI = P->getAnalysis<LoopInfo>(); + Loop *L = LI.getLoopFor(CondBB); + if (L) { + L->addBasicBlockToLoop(ThenBB, LI.getBase()); + L->addBasicBlockToLoop(MergeBB, LI.getBase()); + } + codegen(g->then); Builder.SetInsertPoint(MergeBB->begin()); @@ -1030,8 +1037,6 @@ public: AU.addPreserved<CloogInfo>(); AU.addPreserved<Dependences>(); - - // FIXME: We do not create LoopInfo for the newly generated loops. AU.addPreserved<LoopInfo>(); AU.addPreserved<DominatorTree>(); AU.addPreserved<ScopDetection>(); diff --git a/polly/lib/CodeGen/IslCodeGeneration.cpp b/polly/lib/CodeGen/IslCodeGeneration.cpp index 136a87321f4..d5c3a9f4359 100644 --- a/polly/lib/CodeGen/IslCodeGeneration.cpp +++ b/polly/lib/CodeGen/IslCodeGeneration.cpp @@ -860,6 +860,13 @@ void IslNodeBuilder::createIf(__isl_take isl_ast_node *If) { DT.addNewBlock(ElseBB, CondBB); DT.changeImmediateDominator(MergeBB, CondBB); + LoopInfo &LI = P->getAnalysis<LoopInfo>(); + Loop *L = LI.getLoopFor(CondBB); + if (L) { + L->addBasicBlockToLoop(ThenBB, LI.getBase()); + L->addBasicBlockToLoop(ElseBB, LI.getBase()); + } + CondBB->getTerminator()->eraseFromParent(); Builder.SetInsertPoint(CondBB); @@ -1051,7 +1058,6 @@ public: AU.addPreserved<Dependences>(); - // FIXME: We do not create LoopInfo for the newly generated loops. AU.addPreserved<LoopInfo>(); AU.addPreserved<DominatorTree>(); AU.addPreserved<IslAstInfo>(); diff --git a/polly/lib/CodeGen/LoopGenerators.cpp b/polly/lib/CodeGen/LoopGenerators.cpp index 881a0ac24aa..da0c782bc6d 100644 --- a/polly/lib/CodeGen/LoopGenerators.cpp +++ b/polly/lib/CodeGen/LoopGenerators.cpp @@ -15,6 +15,7 @@ #include "polly/ScopDetection.h" #include "polly/CodeGen/LoopGenerators.h" #include "llvm/Analysis/Dominators.h" +#include "llvm/Analysis/LoopInfo.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/Module.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" @@ -50,6 +51,7 @@ Value *polly::createLoop(Value *LB, Value *UB, Value *Stride, ICmpInst::Predicate Predicate) { DominatorTree &DT = P->getAnalysis<DominatorTree>(); + LoopInfo &LI = P->getAnalysis<LoopInfo>(); Function *F = Builder.GetInsertBlock()->getParent(); LLVMContext &Context = F->getContext(); @@ -63,6 +65,23 @@ Value *polly::createLoop(Value *LB, Value *UB, Value *Stride, BasicBlock *PreHeaderBB = BasicBlock::Create(Context, "polly.loop_preheader", F); + // Update LoopInfo + Loop *OuterLoop = LI.getLoopFor(BeforeBB); + Loop *NewLoop = new Loop(); + + if (OuterLoop) { + OuterLoop->addChildLoop(NewLoop); + } else { + LI.addTopLevelLoop(NewLoop); + } + + if (OuterLoop) { + OuterLoop->addBasicBlockToLoop(GuardBB, LI.getBase()); + OuterLoop->addBasicBlockToLoop(PreHeaderBB, LI.getBase()); + } + + NewLoop->addBasicBlockToLoop(HeaderBB, LI.getBase()); + // ExitBB ExitBB = SplitBlock(BeforeBB, Builder.GetInsertPoint()++, P); ExitBB->setName("polly.loop_exit"); diff --git a/polly/test/Cloog/CodeGen/loop_with_condition_nested.ll b/polly/test/Cloog/CodeGen/loop_with_condition_nested.ll index 0ecdfe5ed75..40a1fd89b44 100644 --- a/polly/test/Cloog/CodeGen/loop_with_condition_nested.ll +++ b/polly/test/Cloog/CodeGen/loop_with_condition_nested.ll @@ -1,4 +1,5 @@ -; RUN: opt %loadPolly %defaultOpts -polly-cloog -analyze < %s | FileCheck %s +; RUN: opt %loadPolly -basicaa -polly-cloog -analyze < %s | FileCheck %s +; RUN: opt %loadPolly -basicaa -polly-codegen -loops -analyze < %s | FileCheck %s -check-prefix=LOOPS ;#include <string.h> ;#define N 1024 @@ -214,3 +215,7 @@ declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind ; CHECK: Stmt_9(c2); ; CHECK: } + +; LOOPS: Loop at depth 1 containing: %polly.loop_header<header>,%polly.stmt.,%polly.stmt.3<latch><exiting> +; LOOPS: Loop at depth 1 containing: %polly.loop_header5<header>,%polly.stmt.11,%polly.stmt.12<latch><exiting> +; LOOPS: Loop at depth 1 containing: %polly.loop_header15<header>,%polly.stmt.21<latch><exiting> diff --git a/polly/test/Isl/CodeGen/loop_with_condition_nested.ll b/polly/test/Isl/CodeGen/loop_with_condition_nested.ll index 188e293409e..d6b710302d4 100644 --- a/polly/test/Isl/CodeGen/loop_with_condition_nested.ll +++ b/polly/test/Isl/CodeGen/loop_with_condition_nested.ll @@ -1,4 +1,6 @@ -; RUN: opt %loadPolly %defaultOpts -polly-ast -analyze < %s | FileCheck %s +; RUN: opt %loadPolly -basicaa -polly-ast -analyze < %s | FileCheck %s +; RUN: opt %loadPolly -basicaa -polly-codegen-isl -loops -analyze < %s | FileCheck %s -check-prefix=LOOPS + ;#include <string.h> ;#define N 1024 @@ -209,3 +211,8 @@ declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind ; CHECK: Stmt_6(c1); ; CHECK: Stmt_9(c1); ; CHECK: } + +; LOOPS: Printing analysis 'Natural Loop Information' for function 'loop_with_condition': +; LOOPS: Loop at depth 1 containing: %1<header><exiting>,%2,%4,%7,%6,%8,%9,%10<latch> +; LOOPS: Loop at depth 1 containing: +; LOOPS: %polly.loop_header<header>,%polly.cond,%polly.merge,%polly.then,%polly.else,%polly.stmt.,%polly.cond3,%polly.merge4,%polly.then5,%polly.else6,%polly.stmt.7,%polly.stmt.8<latch><exiting> diff --git a/polly/test/Isl/single_loop_param_less_equal.ll b/polly/test/Isl/single_loop_param_less_equal.ll index 06d32085b63..fbc798ea36b 100644 --- a/polly/test/Isl/single_loop_param_less_equal.ll +++ b/polly/test/Isl/single_loop_param_less_equal.ll @@ -1,5 +1,6 @@ ; RUN: opt %loadPolly -polly-ast -analyze < %s | FileCheck %s ; RUN: opt %loadPolly -polly-codegen-isl -S < %s | FileCheck %s -check-prefix=CODEGEN +; RUN: opt %loadPolly -polly-codegen-isl -loops -analyze < %s | FileCheck %s -check-prefix=LOOPS target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-pc-linux-gnu" @@ -57,3 +58,6 @@ ret: ; CODEGEN: polly.loop_preheader: ; CODEGEN: br label %polly.loop_header + +; LOOPS: Loop at depth 1 containing: %loop.header<header><exiting>,%loop.body,%loop.backedge<latch> +; LOOPS: Loop at depth 1 containing: %polly.loop_header<header>,%polly.stmt.loop.body<latch><exiting> |