[polly] r252437 - [FIX] Initialize incoming scalar memory locations for PHIs
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 8 16:21:22 PST 2015
Author: jdoerfert
Date: Sun Nov 8 18:21:21 2015
New Revision: 252437
URL: http://llvm.org/viewvc/llvm-project?rev=252437&view=rev
Log:
[FIX] Initialize incoming scalar memory locations for PHIs
Added:
polly/trunk/test/Isl/CodeGen/uninitialized_scalar_memory.ll
Modified:
polly/trunk/lib/CodeGen/BlockGenerators.cpp
Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=252437&r1=252436&r2=252437&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Sun Nov 8 18:21:21 2015
@@ -466,6 +466,8 @@ void BlockGenerator::generateScalarStore
void BlockGenerator::createScalarInitialization(Scop &S) {
Region &R = S.getRegion();
+ BasicBlock *ExitBB = R.getExit();
+
// The split block __just before__ the region and optimized region.
BasicBlock *SplitBB = R.getEnteringBlock();
BranchInst *SplitBBTerm = cast<BranchInst>(SplitBB->getTerminator());
@@ -509,10 +511,13 @@ void BlockGenerator::createScalarInitial
if (Inst && R.contains(Inst))
continue;
- // PHI nodes that are not marked as such in their SAI object are exit PHI
- // nodes we model as common scalars but do not need to initialize.
- if (Inst && isa<PHINode>(Inst))
- continue;
+ // PHI nodes that are not marked as such in their SAI object are either exit
+ // PHI nodes we model as common scalars but without initialization, or
+ // incoming phi nodes that need to be initialized. Check if the first is the
+ // case for Inst and do not create and initialize memory if so.
+ if (auto *PHI = dyn_cast_or_null<PHINode>(Inst))
+ if (!S.hasSingleExitEdge() && PHI->getBasicBlockIndex(ExitBB) >= 0)
+ continue;
Builder.CreateStore(Array->getBasePtr(),
getOrCreateScalarAlloca(Array->getBasePtr()));
Added: polly/trunk/test/Isl/CodeGen/uninitialized_scalar_memory.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/uninitialized_scalar_memory.ll?rev=252437&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/uninitialized_scalar_memory.ll (added)
+++ polly/trunk/test/Isl/CodeGen/uninitialized_scalar_memory.ll Sun Nov 8 18:21:21 2015
@@ -0,0 +1,88 @@
+; RUN: opt %loadPolly -S -polly-codegen < %s | FileCheck %s
+;
+; Verify we initialize the scalar locations reserved for the incoming phi
+; values.
+;
+; CHECK: polly.start:
+; CHECK-NEXT: store float %ebig.0, float* %ebig.0.s2a
+; CHECK-NEXT: store i32 %iebig.0, i32* %iebig.0.s2a
+; CHECK-NEXT: br label %polly.stmt.if.end.entry
+;
+; int g(void);
+; float M;
+; int max(float *restrict xbig, int eres, int bres, float *restrict indx) {
+; int i, iebig;
+; float ebig;
+; for (i = 0; i < 4 + eres; i++) {
+; if (g())
+; break;
+;
+; if (xbig[i] > ebig) {
+; ebig = xbig[i];
+; iebig = (int)(indx[i] + bres);
+; }
+; }
+; return (iebig);
+; }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+ at M = common global float 0.000000e+00, align 4
+
+define i32 @max(float* noalias %xbig, i32 %eres, i32 %bres, float* noalias %indx) {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+ %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
+ %iebig.0 = phi i32 [ undef, %entry ], [ %iebig.1, %for.inc ]
+ %ebig.0 = phi float [ undef, %entry ], [ %ebig.1, %for.inc ]
+ %add = add nsw i32 %eres, 4
+ %tmp = sext i32 %add to i64
+ %cmp = icmp slt i64 %indvars.iv, %tmp
+ br i1 %cmp, label %for.body, label %for.end.loopexit
+
+for.body: ; preds = %for.cond
+ %call = call i32 @g() #2
+ %tobool = icmp eq i32 %call, 0
+ br i1 %tobool, label %if.end, label %if.then
+
+if.then: ; preds = %for.body
+ %iebig.0.lcssa1 = phi i32 [ %iebig.0, %for.body ]
+ br label %for.end
+
+if.end: ; preds = %for.body
+ %arrayidx = getelementptr inbounds float, float* %xbig, i64 %indvars.iv
+ %tmp3 = load float, float* %arrayidx, align 4
+ %cmp1 = fcmp ogt float %tmp3, %ebig.0
+ br i1 %cmp1, label %if.then.2, label %if.end.9
+
+if.then.2: ; preds = %if.end
+ %arrayidx4 = getelementptr inbounds float, float* %xbig, i64 %indvars.iv
+ %tmp4 = load float, float* %arrayidx4, align 4
+ %arrayidx6 = getelementptr inbounds float, float* %indx, i64 %indvars.iv
+ %tmp5 = load float, float* %arrayidx6, align 4
+ %conv = sitofp i32 %bres to float
+ %add7 = fadd float %tmp5, %conv
+ %conv8 = fptosi float %add7 to i32
+ br label %if.end.9
+
+if.end.9: ; preds = %if.then.2, %if.end
+ %iebig.1 = phi i32 [ %conv8, %if.then.2 ], [ %iebig.0, %if.end ]
+ %ebig.1 = phi float [ %tmp4, %if.then.2 ], [ %ebig.0, %if.end ]
+ br label %for.inc
+
+for.inc: ; preds = %if.end.9
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+ br label %for.cond
+
+for.end.loopexit: ; preds = %for.cond
+ %iebig.0.lcssa = phi i32 [ %iebig.0, %for.cond ]
+ br label %for.end
+
+for.end: ; preds = %for.end.loopexit, %if.then
+ %iebig.02 = phi i32 [ %iebig.0.lcssa, %for.end.loopexit ], [ %iebig.0.lcssa1, %if.then ]
+ ret i32 %iebig.02
+}
+
+declare i32 @g() #1
More information about the llvm-commits
mailing list