public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/55912] New: missing optimization of x/x and x/std::abs(x)
@ 2013-01-09  7:46 vincenzo.innocente at cern dot ch
  2013-01-09  8:59 ` [Bug tree-optimization/55912] " glisse at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2013-01-09  7:46 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55912

             Bug #: 55912
           Summary: missing optimization of x/x and x/std::abs(x)
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vincenzo.innocente@cern.ch


in the following examples I'm quite surprised that only (x/x)is optimized to
"!".
With Ofast (and even more with -mrecip) I would have expected that
commutativity of multiplication to be used at least to optimized x*a/x

Optimizing x/x and x/std::abs(x) would be beneficial with -mrecip to amortize a
trivial loss of precision.

cat one.cc;c++ -Ofast  -S one.cc -msse4.2; cat one.s
#include<cmath>
int one1(float a, float x) {
  return x*a/x;
}

#include<cmath>
int one2(float a, float x) {
  return a*(x/x);
}



int sign1(float a, float x) {
  return x*a/std::abs(x);
}

int sign2(float a, float x) {
  return a*(x/std::abs(x));
}

    .text
    .align 4,0x90
    .globl __Z4one1ff
__Z4one1ff:
LFB86:
    mulss    %xmm1, %xmm0
    divss    %xmm1, %xmm0
    cvttss2si    %xmm0, %eax
    ret
LFE86:
    .align 4,0x90
    .globl __Z4one2ff
__Z4one2ff:
LFB87:
    cvttss2si    %xmm0, %eax
    ret
LFE87:
    .align 4,0x90
    .globl __Z5sign1ff
__Z5sign1ff:
LFB88:
    mulss    %xmm1, %xmm0
    movss    LC0(%rip), %xmm2
    andps    %xmm2, %xmm1
    divss    %xmm1, %xmm0
    cvttss2si    %xmm0, %eax
    ret
LFE88:
    .align 4,0x90
    .globl __Z5sign2ff
__Z5sign2ff:
LFB89:
    movss    LC0(%rip), %xmm2
    andps    %xmm1, %xmm2
    divss    %xmm2, %xmm1
    mulss    %xmm0, %xmm1
    cvttss2si    %xmm1, %eax
    ret


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

end of thread, other threads:[~2021-08-10 19:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-09  7:46 [Bug tree-optimization/55912] New: missing optimization of x/x and x/std::abs(x) vincenzo.innocente at cern dot ch
2013-01-09  8:59 ` [Bug tree-optimization/55912] " glisse at gcc dot gnu.org
2013-01-09  9:27 ` rguenth at gcc dot gnu.org
2013-10-12 18:35 ` glisse at gcc dot gnu.org
2021-08-10 19:06 ` pinskia 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).