Optimization is removing wanted branches

Smith, Stephen P (AZ75) smith_stephen@htc.honeywell.com
Thu Aug 30 13:15:00 GMT 2001


Several of us are using gcc 2.95.2-6 (from the cygnus distribution) built as
a cross compiler for the powerpc.

The other day one of us noticed that the following code is emitted from cc1
without a branch when optimization is turned on.  Is there a way to use
optimization (-O1, -O2, -O3) and have the assembly branch instuction in the
ouput?

Command line:
    powerpc-motorola-elf-gcc -O1 -S t.c -o t.i ; cat t.i

C source: 

int adjusted_value(int adjust_pred, int adjustment_value)
{
 int value=5;
 if (adjust_pred) {
         value += adjustment_value;
 }
 return value;
}

Output:

	.file	"t.c"
gcc2_compiled.:
	.section	".text"
	.align 2
	.globl adjusted_value
	.type	 adjusted_value,@function
adjusted_value:
	addic 3,3,-1
	subfe 3,3,3
	addi 4,4,5
	andi. 0,3,5
	andc 3,4,3
	or 3,0,3
	blr
.Lfe1:
	.size	 adjusted_value,.Lfe1-adjusted_value
	.ident	"GCC: (GNU) 2.95.2-6 19991024 (cygwin experimental)"




More information about the Gcc mailing list