[polly] r244721 - Always model PHI nodes in scop (if not in same nonaffine subregion)

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 00:48:55 PDT 2015


Author: grosser
Date: Wed Aug 12 02:48:54 2015
New Revision: 244721

URL: http://llvm.org/viewvc/llvm-project?rev=244721&view=rev
Log:
Always model PHI nodes in scop (if not in same nonaffine subregion)

Before we only modeled PHI nodes if at least one incoming basic block was itself
part of the region, now we always model them except if all of their operands are
part of a single non-affine subregion which we model as a black-box.

This change only affects PHI nodes in the entry block, that have exactly one
incoming edge. Before this change, we did not model them and as a result code
generation would not know how to code generate them. With this change, code
generation can code generate them like any other PHI node.

This issue was exposed by r244606. Before this change simplifyRegion would have
moved these PHI nodes out of the SCoP, so we would never have tried to code
generate them. We could implement this behavior again, but changing the IR
after the scop has been modeled and transformed always adds a risk of us
invalidating earlier analysis results. It seems more save and overall also more
consistent to just model and handle this one-entry-edge PHI nodes like any
other PHI node in the scop.

Solution proposed by:  Michael Kruse  <llvm at meinersbur.de>

Modified:
    polly/trunk/lib/Analysis/TempScopInfo.cpp
    polly/trunk/test/Isl/CodeGen/entry_with_trivial_phi.ll

Modified: polly/trunk/lib/Analysis/TempScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/TempScopInfo.cpp?rev=244721&r1=244720&r2=244721&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/TempScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/TempScopInfo.cpp Wed Aug 12 02:48:54 2015
@@ -114,18 +114,20 @@ void TempScopInfo::buildPHIAccesses(PHIN
   // PHI nodes are modeled as if they had been demoted prior to the SCoP
   // detection. Hence, the PHI is a load of a new memory location in which the
   // incoming value was written at the end of the incoming basic block.
-  bool Written = false;
+  bool OnlyNonAffineSubRegionOperands = true;
   for (unsigned u = 0; u < PHI->getNumIncomingValues(); u++) {
     Value *Op = PHI->getIncomingValue(u);
     BasicBlock *OpBB = PHI->getIncomingBlock(u);
 
-    if (!R.contains(OpBB))
-      continue;
-
     // Do not build scalar dependences inside a non-affine subregion.
     if (NonAffineSubRegion && NonAffineSubRegion->contains(OpBB))
       continue;
 
+    OnlyNonAffineSubRegionOperands = false;
+
+    if (!R.contains(OpBB))
+      continue;
+
     Instruction *OpI = dyn_cast<Instruction>(Op);
     if (OpI) {
       BasicBlock *OpIBB = OpI->getParent();
@@ -145,14 +147,12 @@ void TempScopInfo::buildPHIAccesses(PHIN
     if (!OpI)
       OpI = OpBB->getTerminator();
 
-    Written = true;
-
     IRAccess ScalarAccess(IRAccess::MUST_WRITE, PHI, ZeroOffset, 1, true,
                           /* IsPHI */ true);
     AccFuncMap[OpBB].push_back(std::make_pair(ScalarAccess, OpI));
   }
 
-  if (Written) {
+  if (!OnlyNonAffineSubRegionOperands) {
     IRAccess ScalarAccess(IRAccess::READ, PHI, ZeroOffset, 1, true,
                           /* IsPHI */ true);
     Functions.push_back(std::make_pair(ScalarAccess, PHI));

Modified: polly/trunk/test/Isl/CodeGen/entry_with_trivial_phi.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/entry_with_trivial_phi.ll?rev=244721&r1=244720&r2=244721&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/entry_with_trivial_phi.ll (original)
+++ polly/trunk/test/Isl/CodeGen/entry_with_trivial_phi.ll Wed Aug 12 02:48:54 2015
@@ -4,14 +4,18 @@
 ; PHI node. LCSSA may create such PHI nodes. This is a breakdown of this case in
 ; the function 'Laguerre_With_Deflation' of oggenc from LLVM's test-suite.
 ;
-; XFAIL: *
-;
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 
 define void @test(i64 %n, float* noalias nonnull %A, float %a) {
 entry:
   br label %entry.split
 
+; CHECK-LABEL: %polly.split_new_and_old
+; CHECK-NEXT:    store float %a, float* %b.phiops
+
+; CHECK-LABEL: polly.stmt.entry.split
+; CHECK-NEXT:    %b.phiops.reload = load float, float* %b.phiops
+
 entry.split:
   %b = phi float [ %a, %entry ]
   store float %b, float* %A, align 4




More information about the llvm-commits mailing list