[PATCH] D15693: [Polly] Take a PHI's incoming block as value user

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 22 14:18:11 PST 2015


Meinersbur added a comment.

In http://reviews.llvm.org/D15693#315190, @jdoerfert wrote:

> > Before this patch, we determine whether a value escapes the SCoP by checking whether it the instruction itself is within the scop. This is wrong for PHINodes because the value must be available in the incoming block instead of of where the PHI is.
>
>
> I don't get it. A PHI (here Inst in the BlockGenerators) which is in the
>  SCoP escapes the SCoP, if it is used outside the SCoP, or not? Where is
>  the difference to any other instruction? Or do you talk about a user
>  PHI? In that case I would say an instruction (here Inst) escapes the
>  SCoP, if the user PHI is not in the SCoP. Either way the code we had
>  seems fine to me but I could have missed something here...


Yes, it is about the PHI as a user of a potentially escaping value (which by itself may or may not be defined by a PHI).

Think of the following case:

  scop_enter:
    phi float [%v, %outofscop]
    %v = ...
  
  scop_exit:
  
  outofscop:
    br label %scop_enter

Is %v escaping? The answer is yes, because otherwise we'd need to add a MK_PHI WRITE to br label %scop_enter, which we cannot do because it is not a ScopStmt. Also see the comment in bool DominatorTree::dominates(const Instruction *Def, const Use &U). ("PHI nodes use their operands on edges")

We had this problem before when creating ScopInfo. There is this code to workaround this which I intend to replace in http://reviews.llvm.org/D15706:

  // Uses by PHI nodes in the entry node count as external uses in case the
  // use is through an incoming block that is itself not contained in the
  // region.
  if (R->getEntry() == UseParent) {
    if (auto *PHI = dyn_cast<PHINode>(UI)) {
      bool ExternalUse = false;
      for (unsigned i = 0; i < PHI->getNumIncomingValues(); i++) {
        if (PHI->getIncomingValue(i) == Inst &&
            !R->contains(PHI->getIncomingBlock(i))) {
          ExternalUse = true;
          break;
        }
      }
   
      if (ExternalUse) {
        AnyCrossStmtUse = true;
        continue;
      }
    }
  }


http://reviews.llvm.org/D15693





More information about the llvm-commits mailing list