[llvm-branch-commits] [polly] r183374 - Update LoopInfo correctly
Tobias Grosser
grosser at fim.uni-passau.de
Wed Jun 5 19:48:37 PDT 2013
Author: grosser
Date: Wed Jun 5 21:47:49 2013
New Revision: 183374
URL: http://llvm.org/viewvc/llvm-project?rev=183374&view=rev
Log:
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 at codeaurora.org>
Merged from: https://llvm.org/svn/llvm-project/polly/trunk@181987
Modified:
polly/branches/release_33/lib/CodeGen/CodeGeneration.cpp
polly/branches/release_33/lib/CodeGen/IslCodeGeneration.cpp
polly/branches/release_33/lib/CodeGen/LoopGenerators.cpp
polly/branches/release_33/test/Cloog/CodeGen/loop_with_condition_nested.ll
polly/branches/release_33/test/Isl/CodeGen/loop_with_condition_nested.ll
polly/branches/release_33/test/Isl/single_loop_param_less_equal.ll
Modified: polly/branches/release_33/lib/CodeGen/CodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/branches/release_33/lib/CodeGen/CodeGeneration.cpp?rev=183374&r1=183373&r2=183374&view=diff
==============================================================================
--- polly/branches/release_33/lib/CodeGen/CodeGeneration.cpp (original)
+++ polly/branches/release_33/lib/CodeGen/CodeGeneration.cpp Wed Jun 5 21:47:49 2013
@@ -924,6 +924,13 @@ void ClastStmtCodeGen::codegen(const cla
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>();
Modified: polly/branches/release_33/lib/CodeGen/IslCodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/branches/release_33/lib/CodeGen/IslCodeGeneration.cpp?rev=183374&r1=183373&r2=183374&view=diff
==============================================================================
--- polly/branches/release_33/lib/CodeGen/IslCodeGeneration.cpp (original)
+++ polly/branches/release_33/lib/CodeGen/IslCodeGeneration.cpp Wed Jun 5 21:47:49 2013
@@ -860,6 +860,13 @@ void IslNodeBuilder::createIf(__isl_take
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>();
Modified: polly/branches/release_33/lib/CodeGen/LoopGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/branches/release_33/lib/CodeGen/LoopGenerators.cpp?rev=183374&r1=183373&r2=183374&view=diff
==============================================================================
--- polly/branches/release_33/lib/CodeGen/LoopGenerators.cpp (original)
+++ polly/branches/release_33/lib/CodeGen/LoopGenerators.cpp Wed Jun 5 21:47:49 2013
@@ -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, Valu
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, Valu
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");
Modified: polly/branches/release_33/test/Cloog/CodeGen/loop_with_condition_nested.ll
URL: http://llvm.org/viewvc/llvm-project/polly/branches/release_33/test/Cloog/CodeGen/loop_with_condition_nested.ll?rev=183374&r1=183373&r2=183374&view=diff
==============================================================================
--- polly/branches/release_33/test/Cloog/CodeGen/loop_with_condition_nested.ll (original)
+++ polly/branches/release_33/test/Cloog/CodeGen/loop_with_condition_nested.ll Wed Jun 5 21:47:49 2013
@@ -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* n
; 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>
Modified: polly/branches/release_33/test/Isl/CodeGen/loop_with_condition_nested.ll
URL: http://llvm.org/viewvc/llvm-project/polly/branches/release_33/test/Isl/CodeGen/loop_with_condition_nested.ll?rev=183374&r1=183373&r2=183374&view=diff
==============================================================================
--- polly/branches/release_33/test/Isl/CodeGen/loop_with_condition_nested.ll (original)
+++ polly/branches/release_33/test/Isl/CodeGen/loop_with_condition_nested.ll Wed Jun 5 21:47:49 2013
@@ -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* n
; 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>
Modified: polly/branches/release_33/test/Isl/single_loop_param_less_equal.ll
URL: http://llvm.org/viewvc/llvm-project/polly/branches/release_33/test/Isl/single_loop_param_less_equal.ll?rev=183374&r1=183373&r2=183374&view=diff
==============================================================================
--- polly/branches/release_33/test/Isl/single_loop_param_less_equal.ll (original)
+++ polly/branches/release_33/test/Isl/single_loop_param_less_equal.ll Wed Jun 5 21:47:49 2013
@@ -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>
More information about the llvm-branch-commits
mailing list