nir/loop_unroll: Always unroll loops that iterate at most once
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 12 Oct 2021 20:06:04 +0000 (13:06 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 14 Oct 2021 03:11:13 +0000 (20:11 -0700)
commitae99ea6f4ddb90f7120b4986709a9e9064037f94
treecf266f985966255a1f09d2cc2db6e5eb24127b3d
parentc4323dc846d1b894ab86ce7d0eb98409085c6a18
nir/loop_unroll: Always unroll loops that iterate at most once

Two carchase compute shaders (shader-db) and two Fallout 4 fragment
shaders (fossil-db) were helped.  Based on the NIR of the shaders, all
four had structures like

    for (i = 0; i < 1; i++) {
        ...

for (...) {
            ...
}
    }

All HSW+ platforms had similar results. (Ice Lake shown)
total loops in shared programs: 6033 -> 6031 (-0.03%)
loops in affected programs: 4 -> 2 (-50.00%)
helped: 2
HURT: 0

All Intel platforms had similar results. (Ice Lake shown)
Instructions in all programs: 143692018 -> 143692006 (-0.0%)
SENDs in all programs: 6947154 -> 6947154 (+0.0%)
Loops in all programs: 38285 -> 38283 (-0.0%)
Cycles in all programs: 8434822225 -> 8434476815 (-0.0%)
Spills in all programs: 191665 -> 191665 (+0.0%)
Fills in all programs: 298822 -> 298822 (+0.0%)

In the presense of loop unrolling like this, the change in cycles is not
accurate.

v2: Rearrange the logic in the if-condition to read a little better.
Suggested by Tim.

Closes: #5089
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13323>
src/compiler/nir/nir_opt_loop_unroll.c