public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/96009] New: missed optimization with floating point operations and integer literals
@ 2020-06-30 17:35 sshannin at gmail dot com
  2020-06-30 18:39 ` [Bug tree-optimization/96009] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: sshannin at gmail dot com @ 2020-06-30 17:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96009
           Summary: missed optimization with floating point operations and
                    integer literals
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sshannin at gmail dot com
  Target Milestone: ---

Consider the two variants below:

double foo(char i) {
    double f = i * 100;
    return f / 100;
}

double bar(char i) {
    return i;
}

Compiled under -Ofast with gcc 9.1.0, we get the following:

foo:
movsbl  %dil, %edi
pxor  %xmm0, %xmm0
imull  $100, %edi, %edi
cvtsi2sdl %edi, %xmm0
mulsd  .LC0(%rip), %xmm0
ret

bar:
movsbl  %dil, %edi
pxor  %xmm0, %xmm0
cvtsi2sdl %edi, %xmm0
ret

.LC0:
.long  1202590843
.long  1065646817

But I think foo should be to be simplified to the same as bar, right?

This seems somewhat similar to PR91739 and PR84997, although not quite the same
as far as I can discern.

(Also, separately, aren't the first two instructions of bar unnecessary? Can't
we just cvtsi2sdl and ret?)

seth@dev4:$ /toolchain14/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/toolchain14/bin/g++
COLLECT_LTO_WRAPPER=/toolchain14/libexec/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc_9_1_0/configure --prefix=/toolchain14
--enable-languages=c,c++,fortran --enable-lto --disable-plugin
--program-suffix=-9.1.0 --disable-multi-lib
Thread model: posix
gcc version 9.1.0 (GCC)

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

* [Bug tree-optimization/96009] missed optimization with floating point operations and integer literals
  2020-06-30 17:35 [Bug c/96009] New: missed optimization with floating point operations and integer literals sshannin at gmail dot com
@ 2020-06-30 18:39 ` pinskia at gcc dot gnu.org
  2020-07-01  6:50 ` rguenth at gcc dot gnu.org
  2020-07-01 10:11 ` glisse at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-06-30 18:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
          Component|c                           |tree-optimization
           Keywords|                            |missed-optimization

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

* [Bug tree-optimization/96009] missed optimization with floating point operations and integer literals
  2020-06-30 17:35 [Bug c/96009] New: missed optimization with floating point operations and integer literals sshannin at gmail dot com
  2020-06-30 18:39 ` [Bug tree-optimization/96009] " pinskia at gcc dot gnu.org
@ 2020-07-01  6:50 ` rguenth at gcc dot gnu.org
  2020-07-01 10:11 ` glisse at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-07-01  6:50 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-07-01

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.

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

* [Bug tree-optimization/96009] missed optimization with floating point operations and integer literals
  2020-06-30 17:35 [Bug c/96009] New: missed optimization with floating point operations and integer literals sshannin at gmail dot com
  2020-06-30 18:39 ` [Bug tree-optimization/96009] " pinskia at gcc dot gnu.org
  2020-07-01  6:50 ` rguenth at gcc dot gnu.org
@ 2020-07-01 10:11 ` glisse at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-07-01 10:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
Note that we don't do the optimization if you replace double with long either.

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

end of thread, other threads:[~2020-07-01 10:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30 17:35 [Bug c/96009] New: missed optimization with floating point operations and integer literals sshannin at gmail dot com
2020-06-30 18:39 ` [Bug tree-optimization/96009] " pinskia at gcc dot gnu.org
2020-07-01  6:50 ` rguenth at gcc dot gnu.org
2020-07-01 10:11 ` glisse 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).