This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/8872: Constant propagation and conditional statements
- From: s dot chauveau at chello dot nl
- To: gcc-gnats at gcc dot gnu dot org
- Date: 8 Dec 2002 10:46:50 -0000
- Subject: optimization/8872: Constant propagation and conditional statements
- Reply-to: s dot chauveau at chello dot nl
>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: