• Paul Berry's avatar
    glsl/loops: consolidate bounded loop handling into a lowering pass. · 2c17f97f
    Paul Berry authored
    Previously, all of the back-ends (ir_to_mesa, st_glsl_to_tgsi, and the
    i965 fs and vec4 visitors) had nearly identical logic for handling
    bounded loops.  This replaces the duplicate logic with an equivalent
    lowering pass that is used by all the back-ends.
    
    Note: on i965, there is a slight increase in instruction count.  For
    example, a loop like this:
    
        for (int i = 0; i < 100; i++) {
          total += i;
        }
    
    would previously compile down to this (vec4) native code:
    
              mov(8)       g4<1>.xD 0D
              mov(8)       g8<1>.xD 0D
        loop:
              cmp.ge.f0(8) null     g8<4;4,1>.xD 100D
        (+f0) break(8)
              add(8)       g5<1>.xD g5<4;4,1>.xD g4<4;4,1>.xD
              add(8)       g8<1>.xD g8<4;4,1>.xD 1D
              add(8)       g4<1>.xD g4<4;4,1>.xD 1D
              while(8) loop
    
    After this patch, the "(+f0) break(8)" turns into:
    
        (+f0) if(8)
              break(8)
              endif(8)
    
    because the back-end isn't smart enough to recognize that "if
    (condition) break;" can be done using a conditional break instruction.
    However, it should be relatively easy for a future peephole
    optimization to properly optimize this.
    Reviewed-by: default avatarJordan Justen <jordan.l.justen@intel.com>
    Reviewed-by: default avatarIan Romanick <ian.d.romanick@intel.com>
    2c17f97f
st_glsl_to_tgsi.cpp 168 KB