public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94757] New: GCC does not optimise unsigned multiplication known not to overflow
@ 2020-04-25  8:55 felix.von.s at posteo dot de
  2020-04-27  6:35 ` [Bug tree-optimization/94757] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: felix.von.s at posteo dot de @ 2020-04-25  8:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94757
           Summary: GCC does not optimise unsigned multiplication known
                    not to overflow
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix.von.s at posteo dot de
  Target Milestone: ---

This code:

    #include <limits.h>

    unsigned f(unsigned x) {
        if (x > UINT_MAX / 3)
            __builtin_unreachable();
        return (x * 3) / 3;
    }

should be possible to optimise into the identity function, but (on x86_64) gcc
-O3 generates a multiplication (via LEA) then a division (via multiplication).
GCC knows that the multiplication cannot overflow, because replacing the
returned expression with __builtin_mul_overflow_p(x, 3, x) is makes it optimise
to returning constant 0.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-15 23:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-25  8:55 [Bug tree-optimization/94757] New: GCC does not optimise unsigned multiplication known not to overflow felix.von.s at posteo dot de
2020-04-27  6:35 ` [Bug tree-optimization/94757] " rguenth at gcc dot gnu.org
2020-06-19  8:09 ` qianjh at cn dot fujitsu.com
2021-12-15 23:56 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).