[polly] r252172 - Use per-BB value maps for non-exit BBs

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 5 08:17:18 PST 2015


Author: meinersbur
Date: Thu Nov  5 10:17:17 2015
New Revision: 252172

URL: http://llvm.org/viewvc/llvm-project?rev=252172&view=rev
Log:
Use per-BB value maps for non-exit BBs

For generating scalar writes of non-affine subregions, all except phi
writes are generated in the exit block. The phi writes are generated in
the incoming block for which we errornously used the same BBMap. This
can conflict if a value for one block is synthesized, and then reused
for another block which is not dominated by the first block. This is
fixed by using block-specific BBMaps for phi writes.

Added:
    polly/trunk/test/Isl/CodeGen/non-affine-region-exit-phi-incoming-synthesize.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=252172&r1=252171&r2=252172&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Thu Nov  5 10:17:17 2015
@@ -1168,17 +1168,22 @@ void RegionGenerator::generateScalarStor
     // 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.

Added: polly/trunk/test/Isl/CodeGen/non-affine-region-exit-phi-incoming-synthesize.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/non-affine-region-exit-phi-incoming-synthesize.ll?rev=252172&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/non-affine-region-exit-phi-incoming-synthesize.ll (added)
+++ polly/trunk/test/Isl/CodeGen/non-affine-region-exit-phi-incoming-synthesize.ll Thu Nov  5 10:17:17 2015
@@ -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
+}




More information about the llvm-commits mailing list