This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

optimization/8872: Constant propagation and conditional statements


>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]