public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vincent-gcc at vinc17 dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/30484] INT_MIN % -1 is well defined for -fwrapv
Date: Tue, 24 Aug 2021 08:47:01 +0000 [thread overview]
Message-ID: <bug-30484-4-rXnieGUGZa@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-30484-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30484
--- Comment #18 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Vincent Lefèvre from comment #16)
> int f (int a, int b, int c)
> {
> if (b < 0)
> return a + b + c;
> else
> return a + c + b;
> }
>
> The generated code with -O3 has 6 instructions:
>
> leal (%rdi,%rdx), %eax
> addl %esi, %edi
> addl %edx, %edi
> addl %esi, %eax
> testl %esi, %esi
> cmovs %edi, %eax
>
> In theory, the compiler could normally optimize to produce the same code as
> with the source that assumes -fwrapv (here, a + b + c and a + c + b are
> obviously equivalent on a typical processor), but in practice, this is often
> not the case as shown above.
Surprisingly, GCC can optimize this second test to 2 instructions with -fwrapv.
I've reported PR102032 about the missed optimization without -fwrapv.
next prev parent reply other threads:[~2021-08-24 8:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bug-30484-4@http.gcc.gnu.org/bugzilla/>
2021-08-22 23:54 ` vincent-gcc at vinc17 dot net
2021-08-23 19:44 ` joseph at codesourcery dot com
2021-08-23 21:06 ` vincent-gcc at vinc17 dot net
2021-08-24 6:50 ` rguenther at suse dot de
2021-08-24 8:33 ` vincent-gcc at vinc17 dot net
2021-08-24 8:38 ` rguenther at suse dot de
2021-08-24 8:47 ` vincent-gcc at vinc17 dot net [this message]
2021-08-24 8:49 ` vincent-gcc at vinc17 dot net
2023-09-18 7:36 ` [Bug target/30484] INT_MIN % -1 is well defined for -fwrapv but traps on x86 rguenth at gcc dot gnu.org
2023-09-18 8:47 ` rguenth at gcc dot gnu.org
2023-09-18 8:47 ` rguenth at gcc dot gnu.org
2023-09-19 12:21 ` rguenth at gcc dot gnu.org
2023-09-19 12:28 ` rguenth 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-30484-4-rXnieGUGZa@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: link
Be 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).