https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100890
Bug ID: 100890 Summary: The "div" standard library functions could be optimised as builtins Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: david at westcontrol dot com Target Milestone: --- The C standard library has a family of functions for calculating the division and remainder as a pair - "div", "ldiv", "lldiv", "imaxdiv". These could be optimised by the compiler using inline code, in the same manner as many other library functions such as the "abs" family (listed under "Other builtins" in the manual). For example, "div" can be implemented as: div_t div(int a, int b) { div_t d; d.quot = a / b; d.rem = a % b; return d; } Inlining this in place of a call to "div" results in code that is smaller and faster on most targets, as well as providing far more optimisation opportunities (constant propagation, re-arranging with other code, etc.).