public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/4046: redundant comparison introduced with gcc-3.0 (regression from gcc 2)
@ 2001-08-17 8:06 niemayer
0 siblings, 0 replies; only message in thread
From: niemayer @ 2001-08-17 8:06 UTC (permalink / raw)
To: gcc-gnats
>Number: 4046
>Category: optimization
>Synopsis: redundant comparison introduced with gcc-3.0 (regression from gcc 2)
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: pessimizes-code
>Submitter-Id: net
>Arrival-Date: Fri Aug 17 08:06:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Peter Niemayer
>Release: gcc-3.0, x86
>Organization:
>Environment:
linux (but this doesn't matter)
>Description:
The optimizer wasn't perfect in eliminating
redundant comparisons in gcc-2 (who's perfect anyway? :-) -
but it seems to have become worse with gcc-3.0...
>How-To-Repeat:
take a look at the assembler output of this code:
#define compi2(x, y) \
( \
((x) < (y))? -1 : \
(((x) > (y))? 1 : 0 ) \
)
int testcomp(void) {
int r = 0;
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) {
if (1 == compi(x,y)) {
r++;
}
}
}
return r;
}
You'll find that the resulting assmbler code of the inner
if-clause contains a redundant jump when using gcc-2.x
(with -O3 and any other great optimizer switch I tried :-)
e.g.:
cmpl %edx,%ecx
jl .L1137
jle .L1137
incl %ebx
.L1137
With gcc-3.0 the same case becomes even worse, now there's
an addition redundant comparison:
cmpl %edx, %ecx
jl .L13
cmpl %edx, %ecx
jle .L13
incl %eax
.L13
When using an inline function like this
inline int compi(const int x, const int y) {
if (x < y) return -1;
if (x > y) return 1;
return 0;
}
instead of the macro, the code gets even worse.
This is somehow a tragedy as it forbids us to just implement
one comparison function instead of operator<, operator> etc.
for each class...
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2001-08-17 8:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-17 8:06 optimization/4046: redundant comparison introduced with gcc-3.0 (regression from gcc 2) niemayer
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).