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

gcc optimizations



Hello,

I am an beginner with optimizing techniques from gcc. I have an example
code  compiled with the gcc (v. egcs-2.91.57) with options 

-S 	generate assembler code
and alternately
-O0	no optimizing
-O3	full optimizing.

My problem is, that I don't know which of the optimization options are the
reason for the optimization. I tried the option -fverbose-asm of gcc. With
this option the compiler includes, which optimization options are enabled,
if I take the -O3 option. I tried it again with the enabled options
without the -O3 option but in this case the compiler doesn't optimize.
Is there anybody, who is be able to give an answer or an pointer to this
problem.

Thank you very much in advance.

Fuat Özdemir


The source code looks like this :

#include <stdio.h>

int main () {

 int a=0, b=0, zero=120;

   if(zero >= 50) {

     a=10;

   } else if (zero >= 100) { 		// unreachable !!

     b=20;

   }

   printf("a = %d   b = %d\n", a, b);

  return 1;
}


The else-if part is unreachable because zero is set to 120 and the first
if-expression is always true.

The result of gcc with -O3 option is the following :

.file "test.c"
gcc2_compiled.:
___gnu_compiled_c:
   .def  ___main; .scl  2; .type 32;   .endef
.text
LC0:
   .ascii "a = %d   b = %d\12\0"
   .align 4
.globl _main
   .def  _main;   .scl  2; .type 32;   .endef
_main:
   pushl %ebp
   movl %esp,%ebp
   call ___main
   pushl $0
   pushl $10
   pushl $LC0
   call _printf
   movl $1,%eax
   movl %ebp,%esp
   popl %ebp
   ret
   .def  _printf; .scl  2; .type 32;   .endef


I am not sure about approach of every assembler command, but it looks like
so, that the content of the main-function is optimized to one
printf-function and the values of the variable 'a' to 10 and 'b' to 0. 

 
--------------------------------------------------------------

E-Mail : fuat@cs.tu-berlin.de
          


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