nir/loop_analyze: Don't test non-positive iterations count

Testing negative iterations count makes no sense, and can cause issues
when the unsigned type is used.
Testing 0 iterations is already covered with
will_break_on_first_iteration, so it can be skipped too.

Fixes: 6772a17a ("nir: Add a loop analysis pass")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9913
Signed-off-by: Sviatoslav Peleshko <sviatoslav.peleshko@globallogic.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26173>
This commit is contained in:
Sviatoslav Peleshko 2023-11-13 13:40:10 +02:00 committed by Marge Bot
parent dd144962c2
commit a6459e0f7b
2 changed files with 14 additions and 1 deletions

View file

@ -1171,11 +1171,13 @@ calculate_iterations(nir_scalar basis, nir_scalar limit_basis,
*/
for (int bias = -1; bias <= 1; bias++) {
const int iter_bias = iter_int + bias;
if (iter_bias < 1)
continue;
if (test_iterations(iter_bias, step, limit, alu_op, bit_size,
induction_base_type, initial,
limit_rhs, invert_cond, execution_mode)) {
return iter_bias > 0 ? iter_bias - trip_offset : iter_bias;
return iter_bias - trip_offset;
}
}

View file

@ -285,6 +285,7 @@ COMPARE_REVERSE(ishl)
INOT_COMPARE(ilt_rev)
INOT_COMPARE(ine)
INOT_COMPARE(uge_rev)
#define CMP_MIN(cmp, min) \
static nir_def *nir_##cmp##_##min(nir_builder *b, nir_def *counter, nir_def *limit) \
@ -635,6 +636,16 @@ KNOWN_COUNT_TEST(0x0000000a, 0x00000005, 0xffffffff, inot_ilt_rev, iadd, 5)
*/
UNKNOWN_COUNT_TEST(0x0000000a, 0x00000005, 0xffffffff, inot_ilt_imin_rev, iadd)
/* uint i = 0;
* while (true) {
* if (!(0 >= i))
* break;
*
* i += 1;
* }
*/
KNOWN_COUNT_TEST(0x00000000, 0x00000000, 0x00000001, inot_uge_rev, iadd, 1)
/* uint i = 0;
* while (true) {
* if (i != 0)