public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: web/2281: Bug in the "Suboptimal code for complex conditionals" proposal
@ 2002-09-18 14:11 zack
0 siblings, 0 replies; 2+ messages in thread
From: zack @ 2002-09-18 14:11 UTC (permalink / raw)
To: cbouchon, gcc-bugs, gcc-prs, zack
Synopsis: Bug in the "Suboptimal code for complex conditionals" proposal
State-Changed-From-To: open->closed
State-Changed-By: zack
State-Changed-When: Wed Sep 18 14:11:48 2002
State-Changed-Why:
This was corrected some time ago.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=2281
^ permalink raw reply [flat|nested] 2+ messages in thread
* web/2281: Bug in the "Suboptimal code for complex conditionals" proposal
@ 2001-04-01 0:00 cbouchon
0 siblings, 0 replies; 2+ messages in thread
From: cbouchon @ 2001-04-01 0:00 UTC (permalink / raw)
To: gcc-gnats
>Number: 2281
>Category: web
>Synopsis: Bug in the "Suboptimal code for complex conditionals" proposal
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: gerald
>State: open
>Class: doc-bug
>Submitter-Id: net
>Arrival-Date: Tue Mar 13 13:36:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Christophe Bouchon
>Release: unknown-1.0
>Organization:
>Environment:
>Description:
On the http://gcc.gnu.org/projects/optimize.html page (Deficiencies of GCC's optimizer), the "Suboptimal code for complex conditionals" section contains faulty code proposals (the 2 code samples at the bottom of the section). It assumes that for any given a and b integers, (a & b) == (a && b) is always true, and that's wrong: (1 & 2) == 0 but (1 && 2) == 1 !
The proposed translation for a && b is:
movl 4(%esp), %edx
movl 8(%esp), %ecx
xorl %eax, %eax
testl %ecx, %edx
setne %al
ret
Then the proposed translation for a || b using the boolean equivalence (!((!a) && (!b))) == (a || b) is worse because it also assume that (!a) == (~a) and that's also wrong:
!1 == 0 but ~1 != 0 (the two notl instructions in the "or" sample are like the ~ C operator).
Just assembly the samples and test them with some integers not having 1 bits at the same position (like 1 and 2) and you can verify this.
>How-To-Repeat:
>Fix:
This tranlation for (a || b) is correct:
movl 4(%esp), %edx
xorl %eax, %eax
movl 8(%esp), %ecx
orl %ecx, %edx
setne %al
ret
this destroys the edx register content but the result is always correct. By the way, I tried to interleave register writes for speed.
For "and", I can still optimize the GCC generated code (with -mbranch-cost=2 option):
and:
movl 4(%esp), %edx
xorl %eax, %eax
testl %edx, %edx
movl 8(%esp), %edx
setne %al
testl %edx, %edx
setne %dl
andl %dl, %al
ret
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-09-18 21:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-18 14:11 web/2281: Bug in the "Suboptimal code for complex conditionals" proposal zack
-- strict thread matches above, loose matches on Subject: below --
2001-04-01 0:00 cbouchon
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).