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)

Reply via email to