public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug regression/21463] New: min/max and references
@ 2005-05-09 8:37 tbptbp at gmail dot com
2005-05-09 8:50 ` [Bug regression/21463] " tbptbp at gmail dot com
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: tbptbp at gmail dot com @ 2005-05-09 8:37 UTC (permalink / raw)
To: gcc-bugs
I don't quite know how to characterize this one, so i'll let it up to those in
the know to fix the summary/description.
Primo, AFAIK, gcc has always struggled to get this right but 4.1 is setting a
new record; so i'll qualify that as a regression vs 3.3/3.4.
Secundo, i haven't found any related bugreports but one about PPC.
So here we go.
Consider this testcase:
#include <algorithm>
template<class T> static inline T max(const T a, const T b) { return a<b ? b : a; }
template<class T> static inline T min(const T a, const T b) { return a<b ? a : b; }
template<class T> static inline const T &ref_max(const T &a, const T &b) {
return a<b ? b : a; }
template<class T> static inline const T &ref_min(const T &a, const T &b) {
return a<b ? a : b; }
template<class T> struct foo_t {
T a0, a1;
T bar(const T b, const T c) {
return max(min(a0, c), min(max(a1, c), b));
}
T bar_ref(const T b, const T c) {
return ref_max(ref_min(a0, c), ref_min(ref_max(a1, c), b));
}
T bar_stl(const T b, const T c) {
return std::max(std::min(a0, c), std::min(std::max(a1, c), b));
}
};
template struct foo_t<int>;
template struct foo_t<float>;
int main() { return 0; }
With g++-4120050501 -O3 i get such creative & entertaining code as:
0000000000400610 <foo_t<float>::bar_ref(float, float)>:
400610: ucomiss 0x4(%rdi),%xmm1
400614: lea 0x4(%rdi),%rax
400618: lea 0xfffffffffffffff8(%rsp),%rdx
40061d: movss %xmm0,0xfffffffffffffffc(%rsp)
400623: movss %xmm1,0xfffffffffffffff8(%rsp)
400629: movaps %xmm1,%xmm2
40062c: cmova %rdx,%rax
400630: movss (%rax),%xmm1
400634: ucomiss %xmm1,%xmm0
400637: ja 400641 <foo_t<float>::bar_ref(float, float)+0x31>
400639: lea 0xfffffffffffffffc(%rsp),%rax
40063e: movaps %xmm0,%xmm1
400641: ucomiss (%rdi),%xmm2
400644: cmova %rdi,%rdx
400648: movss (%rdx),%xmm0
40064c: ucomiss %xmm0,%xmm1
40064f: jbe 400655 <foo_t<float>::bar_ref(float, float)+0x45>
400651: movss (%rax),%xmm0
400655: repz retq
Compare that to what g++-3.4.4-20050314 gives (g++ 3.3.6 is similar):
0000000000400610 <foo_t<float>::bar_ref(float, float)>:
400610: ucomiss (%rdi),%xmm1
400613: lea 0xfffffffffffffffc(%rsp),%rsi
400618: mov %rdi,%rcx
40061b: lea 0x4(%rdi),%rdx
40061f: movss %xmm0,0xfffffffffffffff8(%rsp)
400625: lea 0xfffffffffffffff8(%rsp),%rax
40062a: movss %xmm1,0xfffffffffffffffc(%rsp)
400630: cmovbe %rsi,%rcx
400634: ucomiss 0x4(%rdi),%xmm1
400638: cmova %rsi,%rdx
40063c: ucomiss (%rdx),%xmm0
40063f: cmova %rdx,%rax
400643: movss (%rax),%xmm0
400647: ucomiss (%rcx),%xmm0
40064a: cmovbe %rcx,%rax
40064e: movss (%rax),%xmm0
400652: retq
Certainly not optimal, and in fact quite ugly, but at least there's no branch.
Happens as soon as references are used and enough min/max are piled up, and that
means that unless you use your own min/max instead of the STL version, you're
doomed.
--
Summary: min/max and references
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: regression
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tbptbp at gmail dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: x86*
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21463
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug regression/21463] min/max and references
2005-05-09 8:37 [Bug regression/21463] New: min/max and references tbptbp at gmail dot com
@ 2005-05-09 8:50 ` tbptbp at gmail dot com
2005-05-09 21:33 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: tbptbp at gmail dot com @ 2005-05-09 8:50 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From tbptbp at gmail dot com 2005-05-09 08:50 -------
I forgot to say that using ternary operators or if/else while changing the
codegen slightly doesn't make much difference.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21463
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug regression/21463] min/max and references
2005-05-09 8:37 [Bug regression/21463] New: min/max and references tbptbp at gmail dot com
2005-05-09 8:50 ` [Bug regression/21463] " tbptbp at gmail dot com
@ 2005-05-09 21:33 ` pinskia at gcc dot gnu dot org
2005-05-09 21:34 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-09 21:33 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-09 21:33 -------
*** This bug has been marked as a duplicate of 21462 ***
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21463
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug regression/21463] min/max and references
2005-05-09 8:37 [Bug regression/21463] New: min/max and references tbptbp at gmail dot com
2005-05-09 8:50 ` [Bug regression/21463] " tbptbp at gmail dot com
2005-05-09 21:33 ` pinskia at gcc dot gnu dot org
@ 2005-05-09 21:34 ` pinskia at gcc dot gnu dot org
2005-05-09 21:36 ` [Bug middle-end/21463] " pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-09 21:34 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-09 21:34 -------
Actually I take that back.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|DUPLICATE |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21463
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/21463] min/max and references
2005-05-09 8:37 [Bug regression/21463] New: min/max and references tbptbp at gmail dot com
` (2 preceding siblings ...)
2005-05-09 21:34 ` pinskia at gcc dot gnu dot org
@ 2005-05-09 21:36 ` pinskia at gcc dot gnu dot org
2005-05-09 22:20 ` tbptbp at gmail dot com
2005-09-24 17:38 ` [Bug tree-optimization/21463] " pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-09 21:36 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-05-09 21:36 -------
Confirmed, the problem here is slightly different from 21462 but closely related.
--
What |Removed |Added
----------------------------------------------------------------------------
BugsThisDependsOn| |21462
Status|UNCONFIRMED |NEW
Component|regression |middle-end
Ever Confirmed| |1
Keywords| |missed-optimization
Last reconfirmed|0000-00-00 00:00:00 |2005-05-09 21:36:00
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21463
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug middle-end/21463] min/max and references
2005-05-09 8:37 [Bug regression/21463] New: min/max and references tbptbp at gmail dot com
` (3 preceding siblings ...)
2005-05-09 21:36 ` [Bug middle-end/21463] " pinskia at gcc dot gnu dot org
@ 2005-05-09 22:20 ` tbptbp at gmail dot com
2005-09-24 17:38 ` [Bug tree-optimization/21463] " pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: tbptbp at gmail dot com @ 2005-05-09 22:20 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From tbptbp at gmail dot com 2005-05-09 22:20 -------
Additional note, using -fno-gcse slightly reduce the cruft (this one is my new
pet peeve :).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21463
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tree-optimization/21463] min/max and references
2005-05-09 8:37 [Bug regression/21463] New: min/max and references tbptbp at gmail dot com
` (4 preceding siblings ...)
2005-05-09 22:20 ` tbptbp at gmail dot com
@ 2005-09-24 17:38 ` pinskia at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-24 17:38 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-09-24 17:38 -------
On the mainline we get:
_ZN5foo_tIfE7bar_refEff:
.LFB661:
ucomiss 4(%rdi), %xmm1
leaq -8(%rsp), %rdx
leaq 4(%rdi), %rax
movss %xmm0, -4(%rsp)
movss %xmm1, -8(%rsp)
cmova %rdx, %rax
ucomiss (%rdi), %xmm1
movss (%rax), %xmm0
minss -4(%rsp), %xmm0
cmova %rdi, %rdx
movss (%rdx), %xmm1
maxss %xmm1, %xmm0
ret
But on the tree level, there are a couple of issues.
The first is that, we have
a_1 = &b_2->c;
temp_3 = *a_1;
...
use a_1
Which really should be converted to
temp_3 = b_2->c;
Which will help.
--
What |Removed |Added
----------------------------------------------------------------------------
Component|middle-end |tree-optimization
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21463
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-09-24 17:38 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-09 8:37 [Bug regression/21463] New: min/max and references tbptbp at gmail dot com
2005-05-09 8:50 ` [Bug regression/21463] " tbptbp at gmail dot com
2005-05-09 21:33 ` pinskia at gcc dot gnu dot org
2005-05-09 21:34 ` pinskia at gcc dot gnu dot org
2005-05-09 21:36 ` [Bug middle-end/21463] " pinskia at gcc dot gnu dot org
2005-05-09 22:20 ` tbptbp at gmail dot com
2005-09-24 17:38 ` [Bug tree-optimization/21463] " pinskia at gcc dot gnu dot 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).