------- Comment #60 from steven at gcc dot gnu dot org 2008-12-11 00:27 ------- IMHO I the transformation to division is not fine. I would argue this is the core issue in this problem report.
You are right that a combination of div and mod is quite common in real-world code. Right now, GCC can catch that when the port emits a divmod libcall by default instead of just a div and/or a mod. However, I consider this a separate issue. GCC currently does not recognize div/mod or mod/div as patterns, because at the tree level this would show up as two separate expressions (possibly with statements between the div and mod expresssions), and expand works one statement at a time. Some targets (e.g. x86) call a divmod libcall by default for a div or a mod instruction. If there is a div/mod or mod/div sequence in the code, GCC optimizes away one of the libcalls via the REG_EQUAL notes, IIRC. But our concern now should be to avoid this situation where gcc "invents" a div or mod instruction in the first place. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32044