The following removes the optimization eliding the maybe_zero condition
from number_of_iterations_lt_to_ne when the IV can overflow since the
IV delta input is not accurately reflecting this.
PR tree-optimization/122537
* tree-ssa-loop-niter.cc (number_of_iterations_lt_to_ne): Register
may_be_zero condition when the IV may overflow.
* gcc.dg/torture/pr122537.c: New testcase.
--- /dev/null
+/* { dg-do run } */
+/* { dg-additional-options "-fwrapv" } */
+
+void abort ();
+int a, b;
+int main()
+{
+ int c = 61;
+ int d = 61;
+ c += 8;
+ while (c + a - 80 >= d + a - 80) {
+ c -= d;
+ b++;
+ }
+ if (b != 1)
+ abort ();
+ return 0;
+}
}
/* IV0 < IV1 does not loop if IV0->base >= IV1->base. */
- if (mpz_cmp (mmod, bnds->below) < 0)
+ if (fv_comp_no_overflow && mpz_cmp (mmod, bnds->below) < 0)
noloop = boolean_false_node;
else
noloop = fold_build2 (GE_EXPR, boolean_type_node,