Skip to content
  • Timothy Arceri's avatar
    glsl: make loop unrolling more like the nir unrolling path · 646621c6
    Timothy Arceri authored
    
    
    The old code assumed that loop terminators will always be at
    the start of the loop, resulting in otherwise unrollable
    loops not being unrolled at all. For example the current
    code would unroll:
    
      int j = 0;
      do {
         if (j > 5)
            break;
    
         ... do stuff ...
    
         j++;
      } while (j < 4);
    
    But would fail to unroll the following as no iteration limit was
    calculated because it failed to find the terminator:
    
      int j = 0;
      do {
         ... do stuff ...
    
         j++;
      } while (j < 4);
    
    Also we would fail to unroll the following as we ended up
    calculating the iteration limit as 6 rather than 4. The unroll
    code then assumed we had 3 terminators rather the 2 as it
    wasn't able to determine that "if (j > 5)" was redundant.
    
      int j = 0;
      do {
         if (j > 5)
            break;
    
         ... do stuff ...
    
         if (bool(i))
            break;
    
         j++;
      } while (j < 4);
    
    This patch changes this pass to be more like the NIR unrolling pass.
    With this change we handle loop terminators correctly and also
    handle cases where the terminators have instructions in their
    branches other than a break.
    
    V2:
    - fixed regression where loops with a break in else were never
      unrolled in v1.
    - fixed confusing/wrong naming of bools in complex unrolling.
    
    Reviewed-by: default avatarNicolai Hähnle <nicolai.haehnle@amd.com>
    Tested-by: default avatarDieter Nützel <Dieter@nuetzel-hh.de>
    646621c6