public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/48580] missed optimization: integer overflow checks Date: Sun, 15 Aug 2021 11:45:15 +0000 [thread overview] Message-ID: <bug-48580-4-OpfSbF5j8a@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-48580-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48580 --- Comment #22 from Andrew Pinski <pinskia at gcc dot gnu.org> --- For the original testcase in comment #0 we produce (in GCC 11+): movl %edi, %eax mull %esi seto %dl xorl %r8d, %r8d movzbl %dl, %edx testl %eax, %eax jle .L1 testl %edx, %edx sete %r8b .L1: movl %r8d, %eax ret ------- CUT ---- I have a patch which I think improves the code even more. The gimple level looks like this correctly: x.0_1 = (unsigned int) x_6(D); y.1_2 = (unsigned int) y_7(D); _11 = .MUL_OVERFLOW (x.0_1, y.1_2); tmp_8 = REALPART_EXPR <_11>; tmp.3_3 = (int) tmp_8; if (tmp.3_3 > 0) goto <bb 3>; [59.00%] else goto <bb 4>; [41.00%] <bb 3> [local count: 633507680]: _12 = IMAGPART_EXPR <_11>; _10 = _12 == 0; <bb 4> [local count: 1073741824]: # iftmp.2_5 = PHI <_10(3), 0(2)> Notice no divide. The _12 == 0 part really should just _12 ^ 1. After my patch (which I need to finish up) we get: movl %edi, %eax mull %esi seto %dl xorl %r8d, %r8d movzbl %dl, %edx xorl $1, %edx testl %eax, %eax cmovg %edx, %r8d movl %r8d, %eax ret Which should be exactly what you wanted or very close. There looks to be a few micro-optimizations needed still really.
next prev parent reply other threads:[~2021-08-15 11:45 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-04-12 18:36 [Bug rtl-optimization/48580] New: " zackw at panix dot com 2011-04-12 20:18 ` [Bug rtl-optimization/48580] " joseph at codesourcery dot com 2011-04-12 20:40 ` zackw at panix dot com 2011-04-12 20:52 ` joseph at codesourcery dot com 2011-04-12 21:03 ` zackw at panix dot com 2011-04-12 21:04 ` zackw at panix dot com 2011-04-12 21:10 ` joseph at codesourcery dot com 2011-04-12 21:16 ` joseph at codesourcery dot com 2011-04-13 12:11 ` [Bug middle-end/48580] " rguenth at gcc dot gnu.org 2011-04-13 12:46 ` joseph at codesourcery dot com 2011-04-13 17:44 ` svfuerst at gmail dot com 2011-06-20 9:47 ` jsm28 at gcc dot gnu.org 2011-10-05 12:44 ` jules at gcc dot gnu.org 2011-10-05 13:08 ` jules at gcc dot gnu.org 2011-10-05 15:20 ` joseph at codesourcery dot com 2013-02-02 14:03 ` Martin.vGagern at gmx dot net 2013-02-02 17:02 ` noloader at gmail dot com 2013-02-02 18:54 ` Martin.vGagern at gmx dot net 2013-02-02 21:59 ` zackw at panix dot com 2013-02-02 22:08 ` Martin.vGagern at gmx dot net 2013-05-19 13:04 ` glisse at gcc dot gnu.org 2014-08-24 7:06 ` Martin.vGagern at gmx dot net 2021-08-15 11:45 ` pinskia at gcc dot gnu.org [this message] 2021-08-15 11:49 ` pinskia at gcc dot gnu.org 2021-10-22 22:18 ` pinskia at gcc dot gnu.org 2023-08-09 22:29 ` pinskia at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-48580-4-OpfSbF5j8a@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).