http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53265
Bug #: 53265 Summary: Warn when undefined behavior implies smaller iteration count Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Keywords: diagnostic Severity: enhancement Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: amona...@gcc.gnu.org As requested in PR 53128, this is an enhancement request that asks to produce a warning when loop bound inferred from undefined behavior may be used to transform the loop in a surprising way. Example code: enum {N=4}; int a[N], pfx[N]; void foo() { int i, accum; for (i=0, accum=a[0]; i < N; i++, accum+=a[i]) pfx[i] = accum; } VRP in trunk produces an infinite loop from the above. By the way, with -fno-tree-vrp one would expect that cunroll unrolls just 3 iterations of the loop, but in fact it unrolls 4, because nb_iterations is not updated when nb_iterations_upper_bound is reduced from UB analysis. Can we simply warn when UB analysis reduces nb_iterations_upper_bound and makes it statically smaller than symbolic nb_iterations?