public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/56355] New: abs and multiplication
@ 2013-02-16 12:00 glisse at gcc dot gnu.org
2013-02-16 12:07 ` [Bug tree-optimization/56355] " glisse at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-02-16 12:00 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56355
Bug #: 56355
Summary: abs and multiplication
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: glisse@gcc.gnu.org
#include <cmath>
#include <cstdlib>
typedef double T;
// typedef int T;
T f(T a, T b){
return std::abs(a)*std::abs(b);
}
T g(T a){
return std::abs(a)*std::abs(a);
}
T h(T a){
return std::abs(a*a);
}
Compiled with g++ -O3 (-ffast-math doesn't help), g is properly optimized to
a*a but only at the RTL level, and the other 2 are not optimized at all. If I
make T a typedef for int, nothing is optimized.
For the first one, I would expect abs(a*b), and for the others just a*a.
Related to PR 31548.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/56355] abs and multiplication
2013-02-16 12:00 [Bug tree-optimization/56355] New: abs and multiplication glisse at gcc dot gnu.org
@ 2013-02-16 12:07 ` glisse at gcc dot gnu.org
2013-02-18 10:45 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-02-16 12:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56355
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> 2013-02-16 12:07:28 UTC ---
Actually, for g/h with double, using __builtin_fabs instead of std::abs does
it, so it is just the usual lack of combine at the tree level. But there is
still f, and the builtin approach doesn't help for int.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/56355] abs and multiplication
2013-02-16 12:00 [Bug tree-optimization/56355] New: abs and multiplication glisse at gcc dot gnu.org
2013-02-16 12:07 ` [Bug tree-optimization/56355] " glisse at gcc dot gnu.org
@ 2013-02-18 10:45 ` rguenth at gcc dot gnu.org
2013-03-20 15:40 ` glisse at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-02-18 10:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56355
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-02-18
Ever Confirmed|0 |1
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> 2013-02-18 10:45:23 UTC ---
We lack gimple-level standard math function combining (basically all of
fold_* in builtins.c needs to be replicated by GIMPLE functionality).
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/56355] abs and multiplication
2013-02-16 12:00 [Bug tree-optimization/56355] New: abs and multiplication glisse at gcc dot gnu.org
2013-02-16 12:07 ` [Bug tree-optimization/56355] " glisse at gcc dot gnu.org
2013-02-18 10:45 ` rguenth at gcc dot gnu.org
@ 2013-03-20 15:40 ` glisse at gcc dot gnu.org
2013-03-20 16:19 ` glisse at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-03-20 15:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56355
--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> 2013-03-20 15:40:30 UTC ---
Jeff Law mentions that it would be good to add this "squares are nonnegative"
information to VRP, not just tree_binary_nonnegative_warnv_p.
http://gcc.gnu.org/ml/gcc-patches/2013-03/msg00690.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/56355] abs and multiplication
2013-02-16 12:00 [Bug tree-optimization/56355] New: abs and multiplication glisse at gcc dot gnu.org
` (2 preceding siblings ...)
2013-03-20 15:40 ` glisse at gcc dot gnu.org
@ 2013-03-20 16:19 ` glisse at gcc dot gnu.org
2021-12-25 8:45 ` pinskia at gcc dot gnu.org
2023-05-03 6:12 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-03-20 16:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56355
--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> 2013-03-20 16:19:33 UTC ---
(In reply to comment #3)
> Jeff Law mentions that it would be good to add this "squares are nonnegative"
> information to VRP, not just tree_binary_nonnegative_warnv_p.
> http://gcc.gnu.org/ml/gcc-patches/2013-03/msg00690.html
Er, actually, since my patch, VRP does manage to deduce a non-negative range
for squares, although, sadly, when computing x*x, it doesn't manage to merge
the information from the interval of x and this non-negative property.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/56355] abs and multiplication
2013-02-16 12:00 [Bug tree-optimization/56355] New: abs and multiplication glisse at gcc dot gnu.org
` (3 preceding siblings ...)
2013-03-20 16:19 ` glisse at gcc dot gnu.org
@ 2021-12-25 8:45 ` pinskia at gcc dot gnu.org
2023-05-03 6:12 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-25 8:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56355
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2016-07-24 00:00:00 |2021-12-25
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The only one which I think is missing is:
(if (FLOAT_TYPE_P (type))
(simplify
(mult (abs @0) (abs @1))
(abs (mult @0 @1)))
But I do think we can only do it for FLOAT_TYPE_P as
((unsigned)INT_MIN)*((unsigned)-1) will be different when using abs I think.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/56355] abs and multiplication
2013-02-16 12:00 [Bug tree-optimization/56355] New: abs and multiplication glisse at gcc dot gnu.org
` (4 preceding siblings ...)
2021-12-25 8:45 ` pinskia at gcc dot gnu.org
@ 2023-05-03 6:12 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-03 6:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56355
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note g has been optimized since GCC 6, r6-4098-g5d3498b4e03c in fact.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-05-03 6:12 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-16 12:00 [Bug tree-optimization/56355] New: abs and multiplication glisse at gcc dot gnu.org
2013-02-16 12:07 ` [Bug tree-optimization/56355] " glisse at gcc dot gnu.org
2013-02-18 10:45 ` rguenth at gcc dot gnu.org
2013-03-20 15:40 ` glisse at gcc dot gnu.org
2013-03-20 16:19 ` glisse at gcc dot gnu.org
2021-12-25 8:45 ` pinskia at gcc dot gnu.org
2023-05-03 6:12 ` 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).