From bc29e0b27c4d674e04d6ca5c1fadd644809b4278 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Thu, 12 Nov 2015 07:34:09 +0000 Subject: [PATCH] RegionGenerator: Only introduce subregion.ivs for loops fully within a subregion IVs of loops for which the loop header is in the subregion, but not the entire loop may be incremented outside of the subregion and can consequently not be kept private to the subregion. Instead, they need to and are modeled as virtual loops in the iteration domains. As this is the case, generating new subregion induction variables for such loops is not needed and indeed wrong as they would hide the virtual induction variables modeled in the scop. This fixes a miscompile in MultiSource/Benchmarks/Ptrdist/bc and MultiSource/Benchmarks/nbench/. Thanks Michael and Johannes for their investiagations and helpful observations regarding this bug. llvm-svn: 252860 --- polly/lib/CodeGen/BlockGenerators.cpp | 2 +- polly/test/Isl/CodeGen/non-affine-phi-node-expansion-3.ll | 2 -- polly/test/Isl/CodeGen/non-affine-phi-node-expansion-4.ll | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index 6453271a4f8d..962cc3802443 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -1141,7 +1141,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT <S, // replacement for SCEVs refering to the old loop. for (BasicBlock *BB : SeenBlocks) { Loop *L = LI.getLoopFor(BB); - if (L == nullptr || L->getHeader() != BB) + if (L == nullptr || L->getHeader() != BB || !R->contains(L)) continue; BasicBlock *BBCopy = BlockMap[BB]; diff --git a/polly/test/Isl/CodeGen/non-affine-phi-node-expansion-3.ll b/polly/test/Isl/CodeGen/non-affine-phi-node-expansion-3.ll index 8cbbc227636e..2f264487038a 100644 --- a/polly/test/Isl/CodeGen/non-affine-phi-node-expansion-3.ll +++ b/polly/test/Isl/CodeGen/non-affine-phi-node-expansion-3.ll @@ -13,11 +13,9 @@ loop: br i1 %cond0, label %branch1, label %backedge ; CHECK-LABEL: polly.stmt.loop: -; CHECK-NEXT: %polly.subregion.iv = phi i32 [ 0, %polly.stmt.loop.entry ] ; CHECK-NEXT: %p_val0 = fadd float 1.000000e+00, 2.000000e+00 ; CHECK-NEXT: %p_val1 = fadd float 1.000000e+00, 2.000000e+00 ; CHECK-NEXT: %p_val2 = fadd float 1.000000e+00, 2.000000e+00 -; CHECK-NEXT: %polly.subregion.iv.inc = add i32 %polly.subregion.iv, 1 ; CHECK-NEXT: store float %p_val0, float* %merge.phiops ; CHECK-NEXT: br i1 diff --git a/polly/test/Isl/CodeGen/non-affine-phi-node-expansion-4.ll b/polly/test/Isl/CodeGen/non-affine-phi-node-expansion-4.ll index 2ad52d180e4c..158bfe2304a4 100644 --- a/polly/test/Isl/CodeGen/non-affine-phi-node-expansion-4.ll +++ b/polly/test/Isl/CodeGen/non-affine-phi-node-expansion-4.ll @@ -12,10 +12,8 @@ loop: br i1 %cond0, label %branch1, label %backedge ; CHECK-LABEL: polly.stmt.loop: -; CHECK-NEXT: %polly.subregion.iv = phi i32 [ 0, %polly.stmt.loop.entry ] ; CHECK-NEXT: %p_val0 = fadd float 1.000000e+00, 2.000000e+00 ; CHECK-NEXT: %p_val1 = fadd float 1.000000e+00, 2.000000e+00 -; CHECK-NEXT: %polly.subregion.iv.inc = add i32 %polly.subregion.iv, 1 ; CHECK-NEXT: store float %p_val0, float* %merge.phiops ; CHECK-NEXT: br i1