[PATCH] D93734: [LoopDeletion] Insert an early exit from dead path in loop

Jonas Paulsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 8 10:02:58 PDT 2022


jonpa added a comment.

I have derived two reduced test cases where this patch improve the loop branching from SPEC. These were the first two files I looked at out of many, and it seems that in both cases LoopDeletion fails in deleting the loop as it is found to be not variant. In both of these cases it was a matter of breaking the outer loop if the inner loop was never visited.

On SPEC, I still see 2185 of these early exits inserted. This is kind of interesting, although it may be that this is not going to improve any benchmarks. Maybe it relates to outer loops with inner loops that always are executed. Maybe the overhead of the outer loop isn't that great in other cases...

  // Derived from gcc / tree-vect-slp.c                                                                                                                                                                                                                                             
  
  int VEC_gimple_base_iterate_vec_;
  
  void build_vector();
  
  unsigned VEC_gimple_base_length();
  
  int VEC_gimple_base_iterate() {
    if (VEC_gimple_base_iterate_vec_)
      return 1;
    return 0;
  }
  
  void vect_get_constant_vectors() {
    int j = VEC_gimple_base_length();
    for (; j; j++)                            **// No Loop deletion, but early exit if inner loop never visited.  **                                                                                                                                                                                              
      for (; VEC_gimple_base_iterate();)
        build_vector();
  }
  
  clang -c -o tree-vect-slp.s -S -O3 -march=arch13  tree-vect-slp.i -w -mllvm -debug-only=loop-delete
  
  Analyzing Loop for deletion: Loop at depth 1 containing: %for.cond1.preheader<header>,%for.body4,%for.inc<latch><exiting>,%for.body4.preheader,%for.inc.loopexit
      Loop at depth 2 containing: %for.body4<header><latch><exiting>
  Loop is not invariant, cannot delete.
  Trying to insert early exits:
  Top region: for.cond1.preheader, for.body4.preheader, 
  Bot region: for.inc, for.inc.loopexit, 
  Inserting early exit in for.cond1.preheader:
    br i1 %tobool.not.i.not7, label %for.inc, label %for.body4.preheader
    =>
    br i1 %tobool.not.i.not7, label %for.end5.loopexit10, label %for.body4.preheader



  // Derived from cactus / FlatBoundary.c                                                                                                                                                                                                                                           
  
  void memcpy();
  int CCTK_GroupDimI();
  
  typedef struct {
    int *cctk_lsh
  } cGH;
  
  int Glob_A, Glob_B, Glob_C;
  
  void BndFlatDirVIApplyBndFlat(cGH *GH) {
    int i = 0, j = 0, k = 0, ash[3] = {0, 0, 0}, lsh[3] = {0, 0, 0};
    int vtypesize = CCTK_GroupDimI();
  
    for (; Glob_A;) {
      for (i = 0; i < Glob_B; i++)
        ash[i] = lsh[i] = GH->cctk_lsh[i];
  
      for (k = 0; k < Glob_C; k++)
        for (; j < 1;)
          for (; lsh[0];)
            ;
  
      for (; k < 100000; k++) {               // No Loop deletion, but early exit if inner loop(s) never visited.                                                                                                                                                                               
        for (j = 0; j < lsh[1]; j++) {
          for (i = 0; i < lsh[0]; i++) {
            int _index_to = ash[0] * ash[1] * (k - 1) * vtypesize;
            memcpy(GH + _index_to);
          }
        }
      }
    }
  
  }
  
  
  
  Analyzing Loop for deletion: Loop at depth 2 containing: %for.cond25.preheader.us<header>,%for.cond29.preheader.us.us,%for.body32.us.us,%for.cond29.for.inc40_crit_edge.us.us,%for.cond25.for.inc43_crit_edge.us<latch><exiting>,%for.cond29.preheader.us.us.preheader,%for.cond25.for.inc43_crit_edge.us.loopexit
      Loop at depth 3 containing: %for.cond29.preheader.us.us<header>,%for.body32.us.us,%for.cond29.for.inc40_crit_edge.us.us<latch><exiting>
          Loop at depth 4 containing: %for.body32.us.us<header><latch><exiting>
  Loop is not invariant, cannot delete.
  Trying to insert early exits:
  Top region: for.cond25.preheader.us, for.cond29.preheader.us.us.preheader, 
  Bot region: for.cond25.for.inc43_crit_edge.us, for.cond25.for.inc43_crit_edge.us.loopexit, 
  Inserting early exit in for.cond25.preheader.us:
    br i1 %cmp3165, label %for.cond29.preheader.us.us.preheader, label %for.cond25.for.inc43_crit_edge.us
    =>
    br i1 %cmp3165, label %for.cond29.preheader.us.us.preheader, label %for.cond.loopexit.loopexit


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93734/new/

https://reviews.llvm.org/D93734



More information about the llvm-commits mailing list