[Bug middle-end/118072] [14/15/16 Regression] (n%7) sometimes uses udiv and sometimes does not depending on if `n/7` is used beforehand in a different function

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Feb 11 03:17:17 GMT 2026


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118072

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|missed-optimization,        |deferred
                   |needs-bisection             |
             Status|NEW                         |ASSIGNED
            Summary|[14/15/16 Regression] (n%7) |[14/15/16 Regression] (n%7)
                   |sometimes uses udiv and     |sometimes uses udiv and
                   |sometimes does not          |sometimes does not
                   |depending on if `n/7` is    |depending on if `n/7` is
                   |used beforehand             |used beforehand in a
                   |                            |different function
   Target Milestone|14.4                        |17.0
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The real issue dates back to 1998 with r0-17343-g9ec36da574f827 .
Specifically:
+Wed May 20 15:42:22 1998  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
+
+       * expmed.c (expand_divmod): Save last divison constant and
+       if rem is same as div, don't adjust rem cost.


The problem with this is it leaks things over function calls which is totally
unexpected.

I almost want to say this should be reset at each bb. I am going to go for
function level to begin with though.

Defer changing this until GCC 17 since it has been really an issue for 28 years
and leaking between functions has been there since then.

What this is trying to do is generate the same code for %7 and /7 if /7 was
first so they can be combined together.


More information about the Gcc-bugs mailing list