http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59538
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Arsham Skrenes from comment #2)
> The result of the loop is implicitly used though (benchmarking how long it
> takes to find nth prime number; I also use this code to create an artificial
> workload for a graduate-level project). This is new behaviour by this
> version of GCC. This is NOT a valid optimization as it clearly is having
> unintended side-effects which I am showcasing.
No you need an explicit use to avoid removing empty finite loops. Changing the
time is not a side effect of a loop which is defined by the C/C++ standards.
Many benchmarks can be optimized away if you are not careful; this is true of
any code and most programming languages.