https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112685
Bug ID: 112685 Summary: missed-optimization: division / modulo loops Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: goon.pri.low at gmail dot com Target Milestone: --- This code here: unsigned ldiv(unsigned r) { unsigned d = 0; while (r >= 3) { r -= 3; d++; } return d; } Could be optimized to a single division and save decades of processing time. This code here: unsigned lmod(unsigned r) { while (r >= 3) r -= 3; return r; } Could be optimized to a single modulo. Signed integers are a whole other problem, but maybe we could optimize loops for them also.