nir/loop_analyze: Treat do{}while(false) loops as 0 iterations
authorDanylo Piliaiev <danylo.piliaiev@globallogic.com>
Tue, 20 Aug 2019 15:48:33 +0000 (18:48 +0300)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 21 Aug 2019 11:01:15 +0000 (11:01 +0000)
commite71fc7f2387dc14d08b7b310c41d83aa7a84c3b4
tree114042ec09c306ec200c36896504c0b66936ccdb
parent84b3ef6a96eabc28b18e8cdf1b0d61826b1a8a67
nir/loop_analyze: Treat do{}while(false) loops as 0 iterations

Loops like:

block block_0:
vec1 32 ssa_2 = load_const (0x00000020)
vec1 32 ssa_3 = load_const (0x00000001)
loop {
    vec1 32 ssa_7 = phi block_0: ssa_3, block_4: ssa_9
    vec1 1 ssa_8 = ige ssa_2, ssa_7
    if ssa_8 {
        break
    } else {
    }
    vec1 32 ssa_9 = iadd ssa_7, ssa_1
}

Were treated as having more than 1 iteration and after unrolling
produced wrong results, however such loop will exit during
the first iteration if not unrolled.

So we check if loop will actually loop.

Fixes tests/shaders/glsl-fs-loop-while-false-02.shader_test

Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/nir/nir_loop_analyze.c