[polly] r252526 - Fix dominance when subregion exit is outside scop

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 9 15:07:39 PST 2015


Author: meinersbur
Date: Mon Nov  9 17:07:38 2015
New Revision: 252526

URL: http://llvm.org/viewvc/llvm-project?rev=252526&view=rev
Log:
Fix dominance when subregion exit is outside scop

The dominance of the generated non-affine subregion block was based on
the scop's merge block, therefore resulted in an invalid DominanceTree.
It resulted in some values as assumed to be unusable in the actual
generated exit block.

We detect the case that the exit block has been moved and decide
dominance using the BB at the original exit. If we create another exit
node, that exit nodes is dominated by the one generated from where the
original exit resides. This fixes llvm.org/PR25438 and part of
llvm.org/PR25439.

Added:
    polly/trunk/test/Isl/CodeGen/non-affine-exit-node-dominance.ll
Modified:
    polly/trunk/lib/CodeGen/BlockGenerators.cpp
    polly/trunk/test/Isl/CodeGen/non-affine-region-implicit-store.ll
    polly/trunk/test/Isl/CodeGen/pr25241.ll

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=252526&r1=252525&r2=252526&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Mon Nov  9 17:07:38 2015
@@ -1012,6 +1012,8 @@ void RegionGenerator::copyStmt(ScopStmt
   assert(Stmt.isRegionStmt() &&
          "Only region statements can be copied by the region generator");
 
+  Scop *S = Stmt.getParent();
+
   // Forget all old mappings.
   BlockMap.clear();
   RegionMaps.clear();
@@ -1037,6 +1039,17 @@ void RegionGenerator::copyStmt(ScopStmt
     if (!R->contains(*PI))
       BlockMap[*PI] = EntryBBCopy;
 
+  // Determine the original exit block of this subregion. If it the exit block
+  // is also the scop's exit, it it has been changed to polly.merge_new_and_old.
+  // We move one block back to find the original block. This only happens if the
+  // scop required simplification.
+  // If the whole scop consists of only this non-affine region, then they share
+  // the same Region object, such that we cannot change the exit of one and not
+  // the other.
+  BasicBlock *ExitBB = R->getExit();
+  if (!S->hasSingleExitEdge() && ExitBB == S->getRegion().getExit())
+    ExitBB = *(++pred_begin(ExitBB));
+
   // Iterate over all blocks in the region in a breadth-first search.
   std::deque<BasicBlock *> Blocks;
   SmallPtrSet<BasicBlock *, 8> SeenBlocks;
@@ -1078,7 +1091,7 @@ void RegionGenerator::copyStmt(ScopStmt
         Blocks.push_back(*SI);
 
     // Remember value in case it is visible after this subregion.
-    if (DT.dominates(BB, R->getExit()))
+    if (DT.dominates(BB, ExitBB))
       ValueMap.insert(RegionMap.begin(), RegionMap.end());
   }
 
@@ -1088,7 +1101,10 @@ void RegionGenerator::copyStmt(ScopStmt
   ExitBBCopy->setName("polly.stmt." + R->getExit()->getName() + ".exit");
   BlockMap[R->getExit()] = ExitBBCopy;
 
-  repairDominance(R->getExit(), ExitBBCopy);
+  if (ExitBB == R->getExit())
+    repairDominance(ExitBB, ExitBBCopy);
+  else
+    DT.changeImmediateDominator(ExitBBCopy, BlockMap.lookup(ExitBB));
 
   // As the block generator doesn't handle control flow we need to add the
   // region control flow by hand after all blocks have been copied.

Added: polly/trunk/test/Isl/CodeGen/non-affine-exit-node-dominance.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/non-affine-exit-node-dominance.ll?rev=252526&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/non-affine-exit-node-dominance.ll (added)
+++ polly/trunk/test/Isl/CodeGen/non-affine-exit-node-dominance.ll Mon Nov  9 17:07:38 2015
@@ -0,0 +1,30 @@
+; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s
+;
+; llvm.org/PR25439
+; The dominance of the generated non-affine subregion block was based on the
+; scop's merge block, therefore resulted in an invalid DominanceTree.
+; It resulted in some values as assumed to be unusable in the actual generated
+; exit block. Here we check whether the value %escaping is taken from the
+; generated block.
+;
+; CHECK-LABEL: polly.stmt.subregion_entry:
+; CHECK:         %p_escaping = select i1 undef, i32 undef, i32 undef
+;
+; CHECK-LABEL: polly.stmt.polly.merge_new_and_old.exit:
+; CHECK:         store i32 %p_escaping, i32* %escaping.s2a
+
+define i32 @func() {
+entry:
+  br label %subregion_entry
+
+subregion_entry:
+  %escaping = select i1 undef, i32 undef, i32 undef
+  %cond = or i1 undef, undef
+  br i1 %cond, label %subregion_exit, label %subregion_if
+
+subregion_if:
+  br label %subregion_exit
+
+subregion_exit:
+  ret i32 %escaping
+}

Modified: polly/trunk/test/Isl/CodeGen/non-affine-region-implicit-store.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/non-affine-region-implicit-store.ll?rev=252526&r1=252525&r2=252526&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/non-affine-region-implicit-store.ll (original)
+++ polly/trunk/test/Isl/CodeGen/non-affine-region-implicit-store.ll Mon Nov  9 17:07:38 2015
@@ -1,5 +1,5 @@
 ; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s
-; XFAIL: *
+;
 ; llvm.org/PR25438
 ; After loop versioning, a dominance check of a non-affine subregion's exit node
 ; causes the dominance check to always fail any block in the scop. The
@@ -13,7 +13,7 @@
 ; CHECK:        a.phiops.reload = load i32, i32* %a.phiops
 ;
 ; CHECK-LABEL: polly.stmt.polly.merge_new_and_old.exit:
-; CHECK:         store i32 %a.phiops.reload, i32* %a.s2a
+; CHECK:         store i32 %polly.a, i32* %a.s2a
 
 define void @func() {
 entry:

Modified: polly/trunk/test/Isl/CodeGen/pr25241.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/pr25241.ll?rev=252526&r1=252525&r2=252526&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/pr25241.ll (original)
+++ polly/trunk/test/Isl/CodeGen/pr25241.ll Mon Nov  9 17:07:38 2015
@@ -6,10 +6,11 @@
 
 ; CHECK-LABEL: polly.stmt.if.then.862:
 ; CHECK:         %[[R1:[0-9]+]] = add i32 %tmp, 1
+; CHECK:         store i32 %0, i32* %curr.3.s2a
 ; CHECK:         br label
 
-; CHECK-LABEL: polly.stmt.while.body.740.region_exiting:
-; CHECK:         %polly.curr.3.ph = phi i32 [ undef, %polly.stmt.if.else.864 ], [ %[[R1]], %polly.stmt.if.then.862 ]
+; CHECK-LABEL: polly.stmt.polly.merge_new_and_old.exit:
+; CHECK:         %curr.3.ph.final_reload = load i32, i32* %curr.3.s2a
 ; CHECK:         br label
 
 




More information about the llvm-commits mailing list