diff --git a/.pick_status.json b/.pick_status.json index 38545e35fb3..16a5df46c47 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -94,7 +94,7 @@ "description": "nir/loop_unroll: Always unroll loops that iterate at most once", "nominated": false, "nomination_type": null, - "resolution": 4, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/compiler/nir/nir_opt_loop_unroll.c b/src/compiler/nir/nir_opt_loop_unroll.c index c4c76742d79..0d0f5078b47 100644 --- a/src/compiler/nir/nir_opt_loop_unroll.c +++ b/src/compiler/nir/nir_opt_loop_unroll.c @@ -976,7 +976,27 @@ process_loops(nir_shader *sh, nir_cf_node *cf_node, bool *has_nested_loop_out, } } - if (has_nested_loop || !loop->info->limiting_terminator) + /* Intentionally don't consider exact_trip_count_known here. When + * max_trip_count is non-zero, it is the upper bound on the number of + * times the loop will iterate, but the loop may iterate less. For + * example, the following loop will iterate 0 or 1 time: + * + * for (i = 0; i < min(x, 1); i++) { ... } + * + * Trivial single-interation loops (e.g., do { ... } while (false)) and + * trivial zero-iteration loops (e.g., while (false) { ... }) will have + * already been handled. + * + * If the loop is known to execute at most once and meets the other + * unrolling criteria, unroll it even if it has nested loops. + * + * It is unlikely that such loops exist in real shaders. GraphicsFuzz is + * known to generate spurious loops that iterate exactly once. It is + * plausible that it could eventually start generating loops like the + * example above, so it seems logical to defend against it now. + */ + if (!loop->info->limiting_terminator || + (loop->info->max_trip_count != 1 && has_nested_loop)) goto exit; if (!check_unrolling_restrictions(sh, loop))