nir/loop_analyze: Fix get_iteration for nir_op_ine
authorIan Romanick <ian.d.romanick@intel.com>
Mon, 9 Aug 2021 22:05:33 +0000 (15:05 -0700)
committerMarge Bot <emma+marge@anholt.net>
Tue, 22 Nov 2022 03:18:54 +0000 (03:18 +0000)
commitd9f014401bf842bbc0f57987570e34c9ce080cc4
tree287308ce0aadb6aa4a73f320649d0d69b16e7ad9
parentdbad33da1697a32e304b75b53a4d4a43eed688bc
nir/loop_analyze: Fix get_iteration for nir_op_ine

I discovered this problem because adding an algebraic transformation to
convert some uge and ult to ieq or ine caused a couple loops to stop
unrolling. Consider the loop:

    uint i = 0;
    while (true) {
       if (i >= 1)
          break;

       i++;
    }

This loop clearly executes exactly one time. Note that uge(x, 1) is
equivalent to ine(x, 0). Changing the condition to 'if (i != 0)' will
also execute exactly one time.

In the added test cases, uge_once correctly get an exact loop trip count
of 1. Without the changes to nir_loop_analyze.c, the ine_once case
detects a maximum loop trip count of zero and does not get an exact loop
trip count.

No changes in shader-db or fossil-db.

v2: Move nir_op_fneu changes to a separate commit.

v3: Rename test cases.

Fixes: 6772a17acc8 ("nir: Add a loop analysis pass")
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19732>
src/compiler/nir/nir_loop_analyze.c
src/compiler/nir/tests/loop_analyze_tests.cpp