public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "hugo_musso_gualandi at hotmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/96392] New: Optimize x+0.0 if x is an integer Date: Thu, 30 Jul 2020 19:08:50 +0000 [thread overview] Message-ID: <bug-96392-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96392 Bug ID: 96392 Summary: Optimize x+0.0 if x is an integer Product: gcc Version: 10.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: hugo_musso_gualandi at hotmail dot com Target Milestone: --- One way to convert an integer to a floating point number in C is to multiply it by 1.0. In this case, gcc is clever enough to optimize away the multiplication. Another way is to add 0.0. However, in this case, GCC does not optimize away the addition. Example C code: double times1(int x) { return x * 1.0; } double plus0(int x) { return x + 0.0; } Output of objdump -d after compiling with gcc -O2 -c: 0000000000000000 <times1>: 0: 66 0f ef c0 pxor %xmm0,%xmm0 4: f2 0f 2a c7 cvtsi2sd %edi,%xmm0 8: c3 retq 9: 0f 1f 80 00 00 00 00 nopl 0x0(%rax) 0000000000000010 <plus0>: 10: 66 0f ef c0 pxor %xmm0,%xmm0 14: f2 0f 2a c7 cvtsi2sd %edi,%xmm0 18: f2 0f 58 05 00 00 00 addsd 0x0(%rip),%xmm0 1f: 00 20: c3 retq I believe that the reason that GCC does not optimize x+0.0 is that it is worried that x could be negative zero. However, promoting an integer to floating point can never yield negative zero so it should be possible to optimize in this particular case. (For the matter, Clang does optimize it.)
next reply other threads:[~2020-07-30 19:08 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-07-30 19:08 hugo_musso_gualandi at hotmail dot com [this message] 2020-07-30 20:34 ` [Bug tree-optimization/96392] " glisse at gcc dot gnu.org 2021-06-11 16:18 ` cvs-commit at gcc dot gnu.org 2021-06-11 16:43 ` cvs-commit at gcc dot gnu.org 2021-07-10 8:37 ` roger at nextmovesoftware dot com 2022-02-09 14:24 ` cvs-commit 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-96392-4@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).