diff options
-rw-r--r-- | polly/lib/CodeGen/BlockGenerators.cpp | 7 | ||||
-rw-r--r-- | polly/test/Isl/CodeGen/non-affine-region-exit-phi-incoming-synthesize.ll | 35 |
2 files changed, 41 insertions, 1 deletions
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index 084f6d4643b..f53ab75c315 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -1168,17 +1168,22 @@ void RegionGenerator::generateScalarStores(ScopStmt &Stmt, LoopToScevMapT <S, // In case we add the store into an exiting block, we need to restore the // position for stores in the exit node. auto SavedInsertionPoint = Builder.GetInsertPoint(); + ValueMapT *LocalBBMap = &BBMap; // Implicit writes induced by PHIs must be written in the incoming blocks. if (isa<TerminatorInst>(ScalarInst)) { BasicBlock *ExitingBB = ScalarInst->getParent(); BasicBlock *ExitingBBCopy = BlockMap[ExitingBB]; Builder.SetInsertPoint(ExitingBBCopy->getTerminator()); + + // For the incoming blocks, use the block's BBMap instead of the one for + // the entire region. + LocalBBMap = &RegionMaps[ExitingBBCopy]; } auto Address = getOrCreateAlloca(*MA); - Val = getNewScalarValue(Val, R, Stmt, LTS, BBMap); + Val = getNewScalarValue(Val, R, Stmt, LTS, *LocalBBMap); Builder.CreateStore(Val, Address); // Restore the insertion point if necessary. diff --git a/polly/test/Isl/CodeGen/non-affine-region-exit-phi-incoming-synthesize.ll b/polly/test/Isl/CodeGen/non-affine-region-exit-phi-incoming-synthesize.ll new file mode 100644 index 00000000000..f7f7d3c1e35 --- /dev/null +++ b/polly/test/Isl/CodeGen/non-affine-region-exit-phi-incoming-synthesize.ll @@ -0,0 +1,35 @@ +; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s +; +; This caused the code generation to generate invalid code as the same BBMap was +; used for the whole non-affine region. When %add is synthesized for the +; incoming value of subregion_if first, the code for it was generated into +; subregion_if, but reused for the incoming value of subregion_exit, although it +; is not dominated by subregion_if. +; +; CHECK-LABEL: polly.stmt.subregion_entry: +; CHECK: %[[R0:[0-9]*]] = add i32 %n, -2 +; CHECK: store i32 %[[R0]], i32* %retval.s2a +; +; CHECK-LABEL: polly.stmt.subregion_if: +; CHECK: %[[R1:[0-9]*]] = add i32 %n, -2 +; CHECK: store i32 %[[R1]], i32* %retval.s2a +; +; CHECK-LABEL: polly.stmt.polly.merge_new_and_old.exit: +; CHECK: load i32, i32* %retval.s2a + +define i32 @func(i32 %n){ +entry: + br label %subregion_entry + +subregion_entry: + %add = add nsw i32 %n, -2 + %cmp = fcmp ogt float undef, undef + br i1 %cmp, label %subregion_if, label %subregion_exit + +subregion_if: + br label %subregion_exit + +subregion_exit: + %retval = phi i32 [ %add, %subregion_if ], [ %add, %subregion_entry ] + ret i32 %retval +} |