This is the mail archive of the 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]

Re: jump optimizations

In message <>, Danish Samad wr
 > --0-79893525-1015495227=:2845
 > Content-Type: text/plain; charset=us-ascii
 > Content-Disposition: inline
 > hello,
 > how do you tell gcc, through the machine dexcription,
 > to do jump optimization as shown in the sample code
 > below:
 > c code:             assembly code
 >  i=3; 
 >  j=3;
 >  if (i > j)         cmp	r3, r2	[length = 4]
 > 	            ble	.L3
 >    k=i+j;
 >  else
 >    k=i-j;
 > In the c code above it checks if i>j but when
 > converting to assembly it checks if it is <= and
 > branches to the label corresponding to else
This is usually an indicator that the RTL you generate is exposing too
much of the target machine too early to the compiler.  The compiler has
generic code which should be able to determine that the conditional is
compile-time computable.

Take your fragment and turn it into a usable C function such as:

 int i=3; 
 int j=3;
 int k;
 if (i > j) 
return k;

Compile it with -O2 -dap.

The first CSE pass should determine that the jump is a compile-time constant
and remove it.  It should also determine that the value of "k" is a compile
time constant and eliminate the subtraction completely.

If this is not happening, it is likely because you've exposed too many
target details too early which in turn can confuse the optimizers.

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