public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/8872: Constant propagation and conditional statements
@ 2002-12-08 2:56 s.chauveau
0 siblings, 0 replies; 2+ messages in thread
From: s.chauveau @ 2002-12-08 2:56 UTC (permalink / raw)
To: gcc-gnats
>Number: 8872
>Category: optimization
>Synopsis: Constant propagation and conditional statements
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Dec 08 02:56:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: s.chauveau@chello.nl
>Release: gcc 3.2.1
>Organization:
>Environment:
Debian ix86
>Description:
Gcc seems to have problem propagating constants
when they are defined within a condition. Only a
few levels of constants are propagated.
Consider the following code:
int foo(void)
{
int a = 0 ;
if (a==0) a=1 ; else if (a==1) a=0 ;
if (a==0) a=1 ; else if (a==1) a=0 ;
if (a==0) a=1 ; else if (a==1) a=0 ;
if (a==0) a=1 ; else if (a==1) a=0 ;
if (a==0) a=1 ; else if (a==1) a=0 ;
if (a==0) a=1 ; else if (a==1) a=0 ;
if (a==0) a=1 ; else if (a==1) a=0 ;
if (a==0) a=1 ; else if (a==1) a=0 ;
if (a==0) a=1 ; else if (a==1) a=0 ;
return a ;
}
A good optimiser should be able to reduce this code
to a single constant (0 or 1). Gcc manages to reduce
the first 4 conditional statements. The rest is not
simplified and so generates a very poor assembly code
(with tests and jumps).
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: optimization/8872: Constant propagation and conditional statements
@ 2002-12-08 13:40 reichelt
0 siblings, 0 replies; 2+ messages in thread
From: reichelt @ 2002-12-08 13:40 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, s.chauveau
Synopsis: Constant propagation and conditional statements
State-Changed-From-To: open->closed
State-Changed-By: reichelt
State-Changed-When: Sun Dec 8 13:40:21 2002
State-Changed-Why:
Fixed in mainline.
With gcc 3.3-20021118 I get the following assembler output,
when optimizing with -O2:
foo:
pushl %ebp
movl $1, %eax
movl %esp, %ebp
popl %ebp
ret
That's what you expected, right?
Since the bad optimization in gcc 3.2.1 is no regression,
the fix will most likely not be backported for gcc 3.2.2.
But thanks for spotting this problem.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8872
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-12-08 21:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-08 2:56 optimization/8872: Constant propagation and conditional statements s.chauveau
2002-12-08 13:40 reichelt
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).