[PATCH] D50433: A New Divergence Analysis for LLVM

Alexander via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 23 06:15:41 PDT 2018


alex-t added a comment.

I've not done with the source investigation yet but I already have one general objection.
The analysis algorithm is list-based iterative solver and hence it have to be of linear complexity.

To illustrate the idea I use again the HSAIL backend DA algorithm.
It is not list-based but it can be a good example.

  //Post-dominance frontiers
  std::map<BasicBlock*, std::vector<BasicBlock*>> PDF = computePDF(F);
  // in real code the wrapper that accepts PHI as a Value * and returns list of TermInsts it control dependent of
  
  // Post-Dominance computation by Cooper's algorithm  ( post-dominator tree traversal) is linear  and all necessary stuff like PDT has already been computed to construct SSA
  
  std::map<Value *, unsigned> Divergence;
  
  
  // seed
  for (auto & I : instructions(F))
    Divergence[I] = TTI->isSourceOfDivergence(I);
  // same for args etc....
  
  // All the instructions are in the map
  
  bool changed = true;
  while(changed) {                          //  while iterates twice for reducible graphs, for irreducible more then twice but it is still usually small constant
    changed = false;
    for (auto & I : Divergence)
      changed = update(I);
  }
  
  update(Instruction * I) {
    operand_list = operands(I);
    if (isa<PHI>(V)) {
      operands += getControlDependency(I);   // op1, op2, ... opN + term1, term2, ... termN
    }
    for (auto & Op : operands)
     Divergence[I]  |= Divergence[Op];
  }
      

Since the while loop iterates C times where C = 2 for reducible the whole algorithm is still linear - C * O(N);

Now let's consider the current algorithm. No pre-computation is necessary. That is good in the case where only few of the values are divergent.
Everything is good while we are analyzing the data dependencies - the users of the divergent value are pushed in the worklist. Algorithm is linear and worklist is as long as necessary.
When we discover the divergent control flow things tend to change. For each divergent branch we have to propagate the divergence computing the joins. For that we have to at least walk the successors until the immediate post dominator.  We literally do same job as we'd done constructing the SSA form! And with the loops this is much more complicated.
Good thing that we have the results caching though. 
In worth case algorithm is not linear anymore.

I do not consider this as a serious issue. I just noticed that there is a lot of code that computes the information that has already been computed once before.
I maybe missed some substantial details?
All the above is just my opinion.


Repository:
  rL LLVM

https://reviews.llvm.org/D50433





More information about the llvm-commits mailing list