https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80980
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization Status|UNCONFIRMED |NEW Last reconfirmed| |2017-06-06 CC| |rguenth at gcc dot gnu.org Version|unknown |8.0 Summary|-Os generates larger code |-Os generates larger code |than -O1 because loop is |than -O1 because loop |not removed |header copying is not | |performend and thus loop is | |not removed Ever confirmed|0 |1 --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- This is loop header copying not being run on this loop -Os and thus niter analysis "failing" and ivcanon not removing the loop. The reason is that inside main() this loop is predicted cold and thus if (optimize_loop_for_size_p (loop)) { if (dump_file && (dump_flags & TDF_DETAILS)) fprintf (dump_file, " Not duplicating bb %i: optimizing for size.\n", header->index); return false; } triggers. I suppose instead factoring the above into the duplication size estimation cap instead would "fix" this particular case.