public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/48092] New: associative property of sqrt
@ 2011-03-12 14:57 vincenzo.innocente at cern dot ch
  2011-08-05  8:17 ` [Bug rtl-optimization/48092] missing optimization (associative property of sqrt) vincenzo.innocente at cern dot ch
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2011-03-12 14:57 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: associative property of sqrt
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vincenzo.innocente@cern.ch


Is there any reason why (with -Ofast or -ffast-math) associative properties of
sqrt are not exploited as for instance those of division?

examples
division (ok)

float div1(float a, float x, float y) {
   return a/x/y;
   0:   f3 0f 59 ca             mulss  %xmm2,%xmm1
   4:   f3 0f 5e c1             divss  %xmm1,%xmm0
}

sqrt

float sqrt1(float a, float x, float y) {
   return a*std::sqrt(x)*std::sqrt(y);
  10:   f3 0f 51 d2             sqrtss %xmm2,%xmm2
  14:   f3 0f 51 c9             sqrtss %xmm1,%xmm1
  18:   f3 0f 59 ca             mulss  %xmm2,%xmm1
  1c:   f3 0f 59 c8             mulss  %xmm0,%xmm1
}
  20:   0f 28 c1                movaps %xmm1,%xmm0

and


float rsqrt1(float a, float x, float y) {
   return a/std::sqrt(x)/std::sqrt(y);
  30:   f3 0f 51 c9             sqrtss %xmm1,%xmm1
  34:   f3 0f 51 d2             sqrtss %xmm2,%xmm2
  38:   f3 0f 59 d1             mulss  %xmm1,%xmm2
  3c:   f3 0f 5e c2             divss  %xmm2,%xmm0
}

in this second case I would have at least expected the use of 
"rsqrtss" to take precedence above the associative property of "div"
emitting the same code as below

float rsqrt2(float a, float x, float y) {
   return a/sqrtf(x*y);
  70:   f3 0f 59 ca             mulss  %xmm2,%xmm1
  74:   f3 0f 52 d9             rsqrtss %xmm1,%xmm3
  78:   f3 0f 59 cb             mulss  %xmm3,%xmm1
  7c:   f3 0f 59 cb             mulss  %xmm3,%xmm1
  80:   f3 0f 59 1d 00 00 00    mulss  0(%rip),%xmm3        # 88 <rsqrt2(float,
float, float)+0x18>
  87:   00 
                        84: R_X86_64_PC32       .LC1+0xfffffffffffffffc
  88:   f3 0f 58 0d 00 00 00    addss  0(%rip),%xmm1        # 90 <rsqrt2(float,
float, float)+0x20>
  8f:   00 
                        8c: R_X86_64_PC32       .LC0+0xfffffffffffffffc
  90:   f3 0f 59 cb             mulss  %xmm3,%xmm1
  94:   f3 0f 59 c8             mulss  %xmm0,%xmm1
}
  98:   0f 28 c1                movaps %xmm1,%xmm0


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

* [Bug rtl-optimization/48092] missing optimization (associative property of sqrt)
  2011-03-12 14:57 [Bug tree-optimization/48092] New: associative property of sqrt vincenzo.innocente at cern dot ch
@ 2011-08-05  8:17 ` vincenzo.innocente at cern dot ch
  2011-08-05  8:35 ` [Bug tree-optimization/48092] associative property of builtins is not exploited on GIMPLE rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2011-08-05  8:17 UTC (permalink / raw)
  To: gcc-bugs

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

vincenzo Innocente <vincenzo.innocente at cern dot ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |rtl-optimization
            Version|4.6.0                       |4.7.0
            Summary|associative property of     |missing optimization
                   |sqrt                        |(associative property of
                   |                            |sqrt)

--- Comment #1 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2011-08-05 08:16:17 UTC ---
it is still not optimized in 4.7


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

* [Bug tree-optimization/48092] associative property of builtins is not exploited on GIMPLE
  2011-03-12 14:57 [Bug tree-optimization/48092] New: associative property of sqrt vincenzo.innocente at cern dot ch
  2011-08-05  8:17 ` [Bug rtl-optimization/48092] missing optimization (associative property of sqrt) vincenzo.innocente at cern dot ch
@ 2011-08-05  8:35 ` rguenth at gcc dot gnu.org
  2011-09-08 10:14 ` vincenzo.innocente at cern dot ch
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-08-05  8:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.08.05 08:33:59
                 CC|                            |rguenth at gcc dot gnu.org
          Component|rtl-optimization            |tree-optimization
            Summary|missing optimization        |associative property of
                   |(associative property of    |builtins is not exploited
                   |sqrt)                       |on GIMPLE
     Ever Confirmed|0                           |1

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-05 08:33:59 UTC ---
The reason is we handle this only from the frontend folder which doesn't see
builtins when using std::sqrt.  A C testcase like

double foo (double x, double y)
{
  return __builtin_sqrt (x) * __builtin_sqrt (y);
}

is optimized.

For C++ (thus, optimizing the above when wrapping the sqrt inside an
inline function) these optimizations have to be replicated at the 
GIMPLE level.  Which today means in, for example, tree-ssa-forwprop.c.

Same issue for std::exp and other associative builtins.


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

* [Bug tree-optimization/48092] associative property of builtins is not exploited on GIMPLE
  2011-03-12 14:57 [Bug tree-optimization/48092] New: associative property of sqrt vincenzo.innocente at cern dot ch
  2011-08-05  8:17 ` [Bug rtl-optimization/48092] missing optimization (associative property of sqrt) vincenzo.innocente at cern dot ch
  2011-08-05  8:35 ` [Bug tree-optimization/48092] associative property of builtins is not exploited on GIMPLE rguenth at gcc dot gnu.org
@ 2011-09-08 10:14 ` vincenzo.innocente at cern dot ch
  2011-09-08 11:59 ` rguenther at suse dot de
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2011-09-08 10:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2011-09-08 10:01:48 UTC ---
btw even in C  with -Ofast
 a*exp(x)*exp(y) (same for sqrt) is NOT optimized. compare

double exp0(double x, double y) {
   return exp(x)*exp(y);
}

double exp1(double a, double x, double y) {
   return a*exp(x)*exp(y);
}

double exp02(double a, double x, double y) {
  return a*(exp(x)*exp(y));
}


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

* [Bug tree-optimization/48092] associative property of builtins is not exploited on GIMPLE
  2011-03-12 14:57 [Bug tree-optimization/48092] New: associative property of sqrt vincenzo.innocente at cern dot ch
                   ` (2 preceding siblings ...)
  2011-09-08 10:14 ` vincenzo.innocente at cern dot ch
@ 2011-09-08 11:59 ` rguenther at suse dot de
  2021-07-21  2:46 ` pinskia at gcc dot gnu.org
  2023-05-12  5:46 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenther at suse dot de @ 2011-09-08 11:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from rguenther at suse dot de <rguenther at suse dot de> 2011-09-08 10:50:46 UTC ---
On Thu, 8 Sep 2011, vincenzo.innocente at cern dot ch wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48092
> 
> --- Comment #3 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2011-09-08 10:01:48 UTC ---
> btw even in C  with -Ofast
>  a*exp(x)*exp(y) (same for sqrt) is NOT optimized. compare
> 
> double exp0(double x, double y) {
>    return exp(x)*exp(y);
> }
> 
> double exp1(double a, double x, double y) {
>    return a*exp(x)*exp(y);
> }

Yes, that's because those simplification all are implemented in
fold-const.c.  Compare

double exp03(double a, double x, double y) {
  double tmp1 = exp(x);
  double tmp2 = exp(y);
      return a*(tmp1*tmp2);
}

and in fold-const.c we don't associate FP math.  tree-ssa-reassoc.c
re-associates exp1, but then the simplification is missing - see
my exp03 example.


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

* [Bug tree-optimization/48092] associative property of builtins is not exploited on GIMPLE
  2011-03-12 14:57 [Bug tree-optimization/48092] New: associative property of sqrt vincenzo.innocente at cern dot ch
                   ` (3 preceding siblings ...)
  2011-09-08 11:59 ` rguenther at suse dot de
@ 2021-07-21  2:46 ` pinskia at gcc dot gnu.org
  2023-05-12  5:46 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-21  2:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement

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

* [Bug tree-optimization/48092] associative property of builtins is not exploited on GIMPLE
  2011-03-12 14:57 [Bug tree-optimization/48092] New: associative property of sqrt vincenzo.innocente at cern dot ch
                   ` (4 preceding siblings ...)
  2021-07-21  2:46 ` pinskia at gcc dot gnu.org
@ 2023-05-12  5:46 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-12  5:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |6.0
             Status|NEW                         |RESOLVED

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
exp and sqrt were both fixed in GCC 6 by r6-2973-g354016403304

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

end of thread, other threads:[~2023-05-12  5:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-12 14:57 [Bug tree-optimization/48092] New: associative property of sqrt vincenzo.innocente at cern dot ch
2011-08-05  8:17 ` [Bug rtl-optimization/48092] missing optimization (associative property of sqrt) vincenzo.innocente at cern dot ch
2011-08-05  8:35 ` [Bug tree-optimization/48092] associative property of builtins is not exploited on GIMPLE rguenth at gcc dot gnu.org
2011-09-08 10:14 ` vincenzo.innocente at cern dot ch
2011-09-08 11:59 ` rguenther at suse dot de
2021-07-21  2:46 ` pinskia at gcc dot gnu.org
2023-05-12  5:46 ` 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).