public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* optimization options not working
@ 2010-02-18 12:08 rohitgeek
  2010-02-18 13:46 ` Andrew Haley
  0 siblings, 1 reply; 20+ messages in thread
From: rohitgeek @ 2010-02-18 12:08 UTC (permalink / raw)
  To: gcc-help


Hi ,

I am a newbie in compilers, recently came across a problem that when i try
to use optimization options( -O_   ) during compilation , i do not get the
asembly for the processor that i am porting gcc to. Is there a simple thing
i am missing somewhere? 
Secondly, are there some macros i need to define in regard with
optimization.

Kindly clarify the doubts and provide any other basic information that i
need to have regarding optimizations, specifically peephole.

Thanks
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27637400.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-18 12:08 optimization options not working rohitgeek
@ 2010-02-18 13:46 ` Andrew Haley
  2010-02-19 19:07   ` rohitgeek
  0 siblings, 1 reply; 20+ messages in thread
From: Andrew Haley @ 2010-02-18 13:46 UTC (permalink / raw)
  To: gcc-help

On 02/18/2010 12:03 PM, rohitgeek wrote:

> I am a newbie in compilers, recently came across a problem that when i try
> to use optimization options( -O_   ) during compilation , i do not get the
> asembly for the processor that i am porting gcc to. Is there a simple thing
> i am missing somewhere? 

Probably.  Tell us exactly what you did, with full details.

http://catb.org/~esr/faqs/smart-questions.html

> Secondly, are there some macros i need to define in regard with
> optimization.

No.

Andrew.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-18 13:46 ` Andrew Haley
@ 2010-02-19 19:07   ` rohitgeek
  2010-02-23 18:19     ` Ian Lance Taylor
  0 siblings, 1 reply; 20+ messages in thread
From: rohitgeek @ 2010-02-19 19:07 UTC (permalink / raw)
  To: gcc-help



hi 

this is what i am doing :-

1. Created the machine description files
2. Build my target (successful)
3. Compile 
       Now this step works correctly i.e. generate correct assembly if i do
not put any optimization option.
   
     command : ----    ./target-gcc -S test.c     -> works
                              ./target-gcc -O1/2/3 -S test.c    -> no
assembly corresponding to the variable assignment and all other operations
i.e. it generates only prologue and epilogue(if i am correct for later
part).

Give me some insight into working of peephole optimizations, how do i start
doing that.

Rohit




 

Andrew Haley wrote:
> 
> On 02/18/2010 12:03 PM, rohitgeek wrote:
> 
>> I am a newbie in compilers, recently came across a problem that when i
>> try
>> to use optimization options( -O_   ) during compilation , i do not get
>> the
>> asembly for the processor that i am porting gcc to. Is there a simple
>> thing
>> i am missing somewhere? 
> 
> Probably.  Tell us exactly what you did, with full details.
> 
> http://catb.org/~esr/faqs/smart-questions.html
> 
>> Secondly, are there some macros i need to define in regard with
>> optimization.
> 
> No.
> 
> Andrew.
> 
> 

-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27650186.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-19 19:07   ` rohitgeek
@ 2010-02-23 18:19     ` Ian Lance Taylor
  2010-02-24  5:21       ` rohitgeek
                         ` (6 more replies)
  0 siblings, 7 replies; 20+ messages in thread
From: Ian Lance Taylor @ 2010-02-23 18:19 UTC (permalink / raw)
  To: rohitgeek; +Cc: gcc-help

rohitgeek <rohit23taneja@gmail.com> writes:

> 1. Created the machine description files
> 2. Build my target (successful)
> 3. Compile 
>        Now this step works correctly i.e. generate correct assembly if i do
> not put any optimization option.
>    
>      command : ----    ./target-gcc -S test.c     -> works
>                               ./target-gcc -O1/2/3 -S test.c    -> no
> assembly corresponding to the variable assignment and all other operations
> i.e. it generates only prologue and epilogue(if i am correct for later
> part).

You didn't show us test.c.  You have to tell us what you did if you
expect a good answer to your question.

Without seeing test.c, I would guess that the variables are not used,
and were removed by the optimizers.


> Give me some insight into working of peephole optimizations, how do i start
> doing that.

Peephole optimization is a specific type of optimization.  See
define_peephole and define_peephole2 in the internals documentation.
See many examples in the existing backends.


Ian

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-23 18:19     ` Ian Lance Taylor
@ 2010-02-24  5:21       ` rohitgeek
  2010-02-24 14:11         ` rohitgeek
                           ` (4 more replies)
  2010-02-24  5:23       ` rohitgeek
                         ` (5 subsequent siblings)
  6 siblings, 5 replies; 20+ messages in thread
From: rohitgeek @ 2010-02-24  5:21 UTC (permalink / raw)
  To: gcc-help




Ian Lance Taylor-3 wrote:
> 
> rohitgeek <rohit23taneja@gmail.com> writes:
> 
>> 1. Created the machine description files
>> 2. Build my target (successful)
>> 3. Compile 
>>        Now this step works correctly i.e. generate correct assembly if i
>> do
>> not put any optimization option.
>>    
>>      command : ----    ./target-gcc -S test.c     -> works
>>                               ./target-gcc -O1/2/3 -S test.c    -> no
>> assembly corresponding to the variable assignment and all other
>> operations
>> i.e. it generates only prologue and epilogue(if i am correct for later
>> part).
> 
> You didn't show us test.c.  You have to tell us what you did if you
> expect a good answer to your question.
> 
> Without seeing test.c, I would guess that the variables are not used,
> and were removed by the optimizers.
> 
> 
>> Give me some insight into working of peephole optimizations, how do i
>> start
>> doing that.
> 
> Peephole optimization is a specific type of optimization.  See
> define_peephole and define_peephole2 in the internals documentation.
> See many examples in the existing backends.
> 
> 
> Ian
> 
> 




I will try to be descriptive this time .

This is test.c

 main()
  {
  int a,b,c;
   a= 5;
   b=10;
   d=30;
  c=  a*b + 30 ;
}

now , suppose i build gcc for an ARM processor.
After build, compile stage ---

with no optimization options as mentioned above, this is what i get in
assembly.

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        sub     sp, sp, #16
        mov     r3, #5
        str     r3, [fp, #-28]
        mov     r3, #10
        str     r3, [fp, #-24]
        mov     r3, #30
        str     r3, [fp, #-16]
        ldr     r2, [fp, #-28]
        ldr     r3, [fp, #-24]
        mul     r1, r3, r2
        mov     r3, r1
        mov     r2, r3, asl #2
        mov     r3, r2, asl #5
        rsb     r3, r2, r3
        add     r3, r3, r1
        mov     r2, r3, asl #2
        add     r3, r3, r2
        mov     r3, r3, asl #4
        add     r3, r3, #299008
        add     r3, r3, #992
        str     r3, [fp, #-20]
        sub     sp, fp, #12
        ldmfd   sp, {fp, sp, pc}
        .size   main, .-main


 with optimization option turned on (mentioned in command line) 
  
assembly :- 

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        bx      lr
        .size   main, .-main


Did i missed something during building time?

Also bringing into notice the point of single instruction generation instead
of 2 instructions (multiply and accumulate), what part of gcc will do it and
how to proceed regarding that.


Thanks
   
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27714100.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-23 18:19     ` Ian Lance Taylor
  2010-02-24  5:21       ` rohitgeek
  2010-02-24  5:23       ` rohitgeek
@ 2010-02-24  5:23       ` rohitgeek
  2010-02-24  5:26       ` rohitgeek
                         ` (3 subsequent siblings)
  6 siblings, 0 replies; 20+ messages in thread
From: rohitgeek @ 2010-02-24  5:23 UTC (permalink / raw)
  To: gcc-help



Ian Lance Taylor-3 wrote:
> 
> rohitgeek <rohit23taneja@gmail.com> writes:
> 
>> 1. Created the machine description files
>> 2. Build my target (successful)
>> 3. Compile 
>>        Now this step works correctly i.e. generate correct assembly if i
>> do
>> not put any optimization option.
>>    
>>      command : ----    ./target-gcc -S test.c     -> works
>>                               ./target-gcc -O1/2/3 -S test.c    -> no
>> assembly corresponding to the variable assignment and all other
>> operations
>> i.e. it generates only prologue and epilogue(if i am correct for later
>> part).
> 
> You didn't show us test.c.  You have to tell us what you did if you
> expect a good answer to your question.
> 
> Without seeing test.c, I would guess that the variables are not used,
> and were removed by the optimizers.
> 
> 
>> Give me some insight into working of peephole optimizations, how do i
>> start
>> doing that.
> 
> Peephole optimization is a specific type of optimization.  See
> define_peephole and define_peephole2 in the internals documentation.
> See many examples in the existing backends.
> 
> 
> Ian
> 
> 




I will try to be descriptive this time .

This is test.c

 main()
  {
  int a,b,c;
   a= 5;
   b=10;
   d=30;
  c=  a*b + 30 ;
}

now , suppose i build gcc for an ARM processor.
After build, compile stage ---

with no optimization options as mentioned above, this is what i get in
assembly.

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        sub     sp, sp, #16
        mov     r3, #5
        str     r3, [fp, #-28]
        mov     r3, #10
        str     r3, [fp, #-24]
        mov     r3, #30
        str     r3, [fp, #-16]
        ldr     r2, [fp, #-28]
        ldr     r3, [fp, #-24]
        mul     r1, r3, r2
        mov     r3, r1
        mov     r2, r3, asl #2
        mov     r3, r2, asl #5
        rsb     r3, r2, r3
        add     r3, r3, r1
        mov     r2, r3, asl #2
        add     r3, r3, r2
        mov     r3, r3, asl #4
        add     r3, r3, #299008
        add     r3, r3, #992
        str     r3, [fp, #-20]
        sub     sp, fp, #12
        ldmfd   sp, {fp, sp, pc}
        .size   main, .-main


 with optimization option turned on (mentioned in command line) 
  
assembly :- 

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        bx      lr
        .size   main, .-main


Did i missed something during building time?

Also bringing into notice the point of single instruction generation instead
of 2 instructions (multiply and accumulate), what part of gcc will do it and
how to proceed regarding that.


Thanks
   
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27714102.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-23 18:19     ` Ian Lance Taylor
  2010-02-24  5:21       ` rohitgeek
@ 2010-02-24  5:23       ` rohitgeek
  2010-02-24  5:23       ` rohitgeek
                         ` (4 subsequent siblings)
  6 siblings, 0 replies; 20+ messages in thread
From: rohitgeek @ 2010-02-24  5:23 UTC (permalink / raw)
  To: gcc-help




Ian Lance Taylor-3 wrote:
> 
> rohitgeek <rohit23taneja@gmail.com> writes:
> 
>> 1. Created the machine description files
>> 2. Build my target (successful)
>> 3. Compile 
>>        Now this step works correctly i.e. generate correct assembly if i
>> do
>> not put any optimization option.
>>    
>>      command : ----    ./target-gcc -S test.c     -> works
>>                               ./target-gcc -O1/2/3 -S test.c    -> no
>> assembly corresponding to the variable assignment and all other
>> operations
>> i.e. it generates only prologue and epilogue(if i am correct for later
>> part).
> 
> You didn't show us test.c.  You have to tell us what you did if you
> expect a good answer to your question.
> 
> Without seeing test.c, I would guess that the variables are not used,
> and were removed by the optimizers.
> 
> 
>> Give me some insight into working of peephole optimizations, how do i
>> start
>> doing that.
> 
> Peephole optimization is a specific type of optimization.  See
> define_peephole and define_peephole2 in the internals documentation.
> See many examples in the existing backends.
> 
> 
> Ian
> 
> 




I will try to be descriptive this time .

This is test.c

 main()
  {
  int a,b,c;
   a= 5;
   b=10;
   d=30;
  c=  a*b + 30 ;
}

now , suppose i build gcc for an ARM processor.
After build, compile stage ---

with no optimization options as mentioned above, this is what i get in
assembly.

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        sub     sp, sp, #16
        mov     r3, #5
        str     r3, [fp, #-28]
        mov     r3, #10
        str     r3, [fp, #-24]
        mov     r3, #30
        str     r3, [fp, #-16]
        ldr     r2, [fp, #-28]
        ldr     r3, [fp, #-24]
        mul     r1, r3, r2
        mov     r3, r1
        mov     r2, r3, asl #2
        mov     r3, r2, asl #5
        rsb     r3, r2, r3
        add     r3, r3, r1
        mov     r2, r3, asl #2
        add     r3, r3, r2
        mov     r3, r3, asl #4
        add     r3, r3, #299008
        add     r3, r3, #992
        str     r3, [fp, #-20]
        sub     sp, fp, #12
        ldmfd   sp, {fp, sp, pc}
        .size   main, .-main


 with optimization option turned on (mentioned in command line) 
  
assembly :- 

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        bx      lr
        .size   main, .-main


Did i missed something during building time?

Also bringing into notice the point of single instruction generation instead
of 2 instructions (multiply and accumulate), what part of gcc will do it and
how to proceed regarding that.


Thanks
   
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27714101.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-23 18:19     ` Ian Lance Taylor
                         ` (2 preceding siblings ...)
  2010-02-24  5:23       ` rohitgeek
@ 2010-02-24  5:26       ` rohitgeek
  2010-02-24  5:27       ` rohitgeek
                         ` (2 subsequent siblings)
  6 siblings, 0 replies; 20+ messages in thread
From: rohitgeek @ 2010-02-24  5:26 UTC (permalink / raw)
  To: gcc-help


I will try to be descriptive this time .

This is test.c

 main()
  {
  int a,b,c;
   a= 5;
   b=10;
   d=30;
  c=  a*b + 30 ;
}

now , suppose i build gcc for an ARM processor.
After build, compile stage ---

with no optimization options as mentioned above, this is what i get in
assembly.

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        sub     sp, sp, #16
        mov     r3, #5
        str     r3, [fp, #-28]
        mov     r3, #10
        str     r3, [fp, #-24]
        mov     r3, #30
        str     r3, [fp, #-16]
        ldr     r2, [fp, #-28]
        ldr     r3, [fp, #-24]
        mul     r1, r3, r2
        mov     r3, r1
        mov     r2, r3, asl #2
        mov     r3, r2, asl #5
        rsb     r3, r2, r3
        add     r3, r3, r1
        mov     r2, r3, asl #2
        add     r3, r3, r2
        mov     r3, r3, asl #4
        add     r3, r3, #299008
        add     r3, r3, #992
        str     r3, [fp, #-20]
        sub     sp, fp, #12
        ldmfd   sp, {fp, sp, pc}
        .size   main, .-main


 with optimization option turned on (mentioned in command line) 
  
assembly :- 

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        bx      lr
        .size   main, .-main


Did i missed something during building time?

Also bringing into notice the point of single instruction generation instead
of 2 instructions (multiply and accumulate), what part of gcc will do it and
how to proceed regarding that.


Thanks
   
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27714103.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-23 18:19     ` Ian Lance Taylor
                         ` (3 preceding siblings ...)
  2010-02-24  5:26       ` rohitgeek
@ 2010-02-24  5:27       ` rohitgeek
  2010-02-24  5:32       ` rohitgeek
  2010-02-24  9:18       ` rohitgeek
  6 siblings, 0 replies; 20+ messages in thread
From: rohitgeek @ 2010-02-24  5:27 UTC (permalink / raw)
  To: gcc-help


I will try to be descriptive this time .

This is test.c

 main()
  {
  int a,b,c;
   a= 5;
   b=10;
   d=30;
  c=  a*b + 30 ;
}

now , suppose i build gcc for an ARM processor.
After build, compile stage ---

with no optimization options as mentioned above, this is what i get in
assembly.

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        sub     sp, sp, #16
        mov     r3, #5
        str     r3, [fp, #-28]
        mov     r3, #10
        str     r3, [fp, #-24]
        mov     r3, #30
        str     r3, [fp, #-16]
        ldr     r2, [fp, #-28]
        ldr     r3, [fp, #-24]
        mul     r1, r3, r2
        mov     r3, r1
        mov     r2, r3, asl #2
        mov     r3, r2, asl #5
        rsb     r3, r2, r3
        add     r3, r3, r1
        mov     r2, r3, asl #2
        add     r3, r3, r2
        mov     r3, r3, asl #4
        add     r3, r3, #299008
        add     r3, r3, #992
        str     r3, [fp, #-20]
        sub     sp, fp, #12
        ldmfd   sp, {fp, sp, pc}
        .size   main, .-main


 with optimization option turned on (mentioned in command line) 
  
assembly :- 

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        bx      lr
        .size   main, .-main


Did i missed something during building time?

Also bringing into notice the point of single instruction generation instead
of 2 instructions (multiply and accumulate), what part of gcc will do it and
how to proceed regarding that.


Thanks
   
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27714104.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-23 18:19     ` Ian Lance Taylor
                         ` (4 preceding siblings ...)
  2010-02-24  5:27       ` rohitgeek
@ 2010-02-24  5:32       ` rohitgeek
  2010-02-24  9:30         ` rohitgeek
  2010-02-24  9:18       ` rohitgeek
  6 siblings, 1 reply; 20+ messages in thread
From: rohitgeek @ 2010-02-24  5:32 UTC (permalink / raw)
  To: gcc-help


I will try to be descriptive this time .

This is test.c

 main()
  {
  int a,b,c;
   a= 5;
   b=10;
   d=30;
  c=  a*b + 30 ;
}

now , suppose i build gcc for an ARM processor.
After build, compile stage ---

with no optimization options as mentioned above, this is what i get in
assembly.

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        sub     sp, sp, #16
        mov     r3, #5
        str     r3, [fp, #-28]
        mov     r3, #10
        str     r3, [fp, #-24]
        mov     r3, #30
        str     r3, [fp, #-16]
        ldr     r2, [fp, #-28]
        ldr     r3, [fp, #-24]
        mul     r1, r3, r2
        mov     r3, r1
        mov     r2, r3, asl #2
        mov     r3, r2, asl #5
        rsb     r3, r2, r3
        add     r3, r3, r1
        mov     r2, r3, asl #2
        add     r3, r3, r2
        mov     r3, r3, asl #4
        add     r3, r3, #299008
        add     r3, r3, #992
        str     r3, [fp, #-20]
        sub     sp, fp, #12
        ldmfd   sp, {fp, sp, pc}
        .size   main, .-main


   
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27714105.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-23 18:19     ` Ian Lance Taylor
                         ` (5 preceding siblings ...)
  2010-02-24  5:32       ` rohitgeek
@ 2010-02-24  9:18       ` rohitgeek
  6 siblings, 0 replies; 20+ messages in thread
From: rohitgeek @ 2010-02-24  9:18 UTC (permalink / raw)
  To: gcc-help


I will try to be descriptive this time .

This is test.c

 main()
  {
  int a,b,c;
   a= 5;
   b=10;
   d=30;
  c=  a*b + 30 ;
}

now , suppose i build gcc for an ARM processor.
After build, compile stage ---

with no optimization options as mentioned above, this is what i get in
assembly.

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        sub     sp, sp, #16
        mov     r3, #5
        str     r3, [fp, #-28]
        mov     r3, #10
        str     r3, [fp, #-24]
        mov     r3, #30
        str     r3, [fp, #-16]
        ldr     r2, [fp, #-28]
        ldr     r3, [fp, #-24]
        mul     r1, r3, r2
        mov     r3, r1
        mov     r2, r3, asl #2
        mov     r3, r2, asl #5
        rsb     r3, r2, r3
        add     r3, r3, r1
        mov     r2, r3, asl #2
        add     r3, r3, r2
        mov     r3, r3, asl #4
        add     r3, r3, #299008
        add     r3, r3, #992
        str     r3, [fp, #-20]
        sub     sp, fp, #12
        ldmfd   sp, {fp, sp, pc}
        .size   main, .-main


   
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27714106.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-24  5:32       ` rohitgeek
@ 2010-02-24  9:30         ` rohitgeek
  0 siblings, 0 replies; 20+ messages in thread
From: rohitgeek @ 2010-02-24  9:30 UTC (permalink / raw)
  To: gcc-help



-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27714105.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-24  5:21       ` rohitgeek
@ 2010-02-24 14:11         ` rohitgeek
  2010-02-24 18:28         ` Andrew Haley
                           ` (3 subsequent siblings)
  4 siblings, 0 replies; 20+ messages in thread
From: rohitgeek @ 2010-02-24 14:11 UTC (permalink / raw)
  To: gcc-help






I will try to be descriptive this time .

This is test.c

 main()
  {
  int a,b,c;
   a= 5;
   b=10;
   d=30;
  c=  a*b + 30 ;
}

now , suppose i build gcc for an ARM processor.
After build, compile stage ---

with no optimization options as mentioned above, this is what i get in
assembly.

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        sub     sp, sp, #16
        mov     r3, #5
        str     r3, [fp, #-28]
        mov     r3, #10
        str     r3, [fp, #-24]
        mov     r3, #30
        str     r3, [fp, #-16]
        ldr     r2, [fp, #-28]
        ldr     r3, [fp, #-24]
        mul     r1, r3, r2
        mov     r3, r1
        mov     r2, r3, asl #2
        mov     r3, r2, asl #5
        rsb     r3, r2, r3
        add     r3, r3, r1
        mov     r2, r3, asl #2
        add     r3, r3, r2
        mov     r3, r3, asl #4
        add     r3, r3, #299008
        add     r3, r3, #992
        str     r3, [fp, #-20]
        sub     sp, fp, #12
        ldmfd   sp, {fp, sp, pc}
        .size   main, .-main


 with optimization option turned on (mentioned in command line) 
  
assembly :- 

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        bx      lr
        .size   main, .-main


Did i missed something during building time?

Also bringing into notice the point of single instruction generation instead
of 2 instructions (multiply and accumulate), what part of gcc will do it and
how to proceed regarding that.


Thanks
   
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27714100.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-24  5:21       ` rohitgeek
  2010-02-24 14:11         ` rohitgeek
@ 2010-02-24 18:28         ` Andrew Haley
  2010-03-01  5:09         ` rohitgeek
                           ` (2 subsequent siblings)
  4 siblings, 0 replies; 20+ messages in thread
From: Andrew Haley @ 2010-02-24 18:28 UTC (permalink / raw)
  To: gcc-help

On 02/24/2010 05:19 AM, rohitgeek wrote:
> 
> 
> This is test.c
> 
>  main()
>   {
>   int a,b,c;
>    a= 5;
>    b=10;
>    d=30;
>   c=  a*b + 30 ;
> }
> 
> now , suppose i build gcc for an ARM processor.
> After build, compile stage ---
> 
> with no optimization options as mentioned above, this is what i get in
> assembly.
> 
>         .file   "test1234.c"
>         .text
>         .align  2
>         .global main
>         .type   main, %function
> main:
>         @ args = 0, pretend = 0, frame = 16
>         @ frame_needed = 1, uses_anonymous_args = 0
>         mov     ip, sp
>         stmfd   sp!, {fp, ip, lr, pc}
>         sub     fp, ip, #4
>         sub     sp, sp, #16
>         mov     r3, #5
>         str     r3, [fp, #-28]
>         mov     r3, #10
>         str     r3, [fp, #-24]
>         mov     r3, #30
>         str     r3, [fp, #-16]
>         ldr     r2, [fp, #-28]
>         ldr     r3, [fp, #-24]
>         mul     r1, r3, r2
>         mov     r3, r1
>         mov     r2, r3, asl #2
>         mov     r3, r2, asl #5
>         rsb     r3, r2, r3
>         add     r3, r3, r1
>         mov     r2, r3, asl #2
>         add     r3, r3, r2
>         mov     r3, r3, asl #4
>         add     r3, r3, #299008
>         add     r3, r3, #992
>         str     r3, [fp, #-20]
>         sub     sp, fp, #12
>         ldmfd   sp, {fp, sp, pc}
>         .size   main, .-main
> 
> 
>  with optimization option turned on (mentioned in command line) 
>   
> assembly :- 
> 
>         .file   "test1234.c"
>         .text
>         .align  2
>         .global main
>         .type   main, %function
> main:
>         @ args = 0, pretend = 0, frame = 0
>         @ frame_needed = 0, uses_anonymous_args = 0
>         @ link register save eliminated.
>         bx      lr
>         .size   main, .-main
> 
> 
> Did i missed something during building time?

No.  It looks to me like the optimizer is working really well.  The
function doesn't do anything, so gcc has optimized away all its
statmements.

Andrew.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-24  5:21       ` rohitgeek
  2010-02-24 14:11         ` rohitgeek
  2010-02-24 18:28         ` Andrew Haley
@ 2010-03-01  5:09         ` rohitgeek
  2010-03-01 15:27         ` John S. Fine
  2010-03-01 21:21         ` Ian Lance Taylor
  4 siblings, 0 replies; 20+ messages in thread
From: rohitgeek @ 2010-03-01  5:09 UTC (permalink / raw)
  To: gcc-help





I will try to be descriptive this time .

This is test.c

 main()
  {
  int a,b,c;
   a= 5;
   b=10;
   d=30;
  c=  a*b + 30 ;
}

now , suppose i build gcc for an ARM processor.
After build, compile stage ---

with no optimization options as mentioned above, this is what i get in
assembly.

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 16
        @ frame_needed = 1, uses_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        sub     fp, ip, #4
        sub     sp, sp, #16
        mov     r3, #5
        str     r3, [fp, #-28]
        mov     r3, #10
        str     r3, [fp, #-24]
        mov     r3, #30
        str     r3, [fp, #-16]
        ldr     r2, [fp, #-28]
        ldr     r3, [fp, #-24]
        mul     r1, r3, r2
        mov     r3, r1
        mov     r2, r3, asl #2
        mov     r3, r2, asl #5
        rsb     r3, r2, r3
        add     r3, r3, r1
        mov     r2, r3, asl #2
        add     r3, r3, r2
        mov     r3, r3, asl #4
        add     r3, r3, #299008
        add     r3, r3, #992
        str     r3, [fp, #-20]
        sub     sp, fp, #12
        ldmfd   sp, {fp, sp, pc}
        .size   main, .-main


 with optimization option turned on (mentioned in command line) 
  
assembly :- 

        .file   "test1234.c"
        .text
        .align  2
        .global main
        .type   main, %function
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        bx      lr
        .size   main, .-main


Did i missed something during building time?

Also bringing into notice the point of single instruction generation instead
of 2 instructions (multiply and accumulate), what part of gcc will do it and
how to proceed regarding that.


Thanks
   
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27714100.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-24  5:21       ` rohitgeek
                           ` (2 preceding siblings ...)
  2010-03-01  5:09         ` rohitgeek
@ 2010-03-01 15:27         ` John S. Fine
  2010-03-01 21:21         ` Ian Lance Taylor
  4 siblings, 0 replies; 20+ messages in thread
From: John S. Fine @ 2010-03-01 15:27 UTC (permalink / raw)
  To: rohitgeek; +Cc: gcc-help

Andrew Haley gave you a perfectly good and correct answer the previous 
time you asked that question.

If you don't understand his answer, you should ask about it.  You seem 
to be assuming he didn't understand your question.  If that were true 
(unlikely) you really haven't improved the question enough to change 
anything.

I assume you want to test a specific optimization.  You are failing 
because you didn't construct the example carefully enough.  You allowed 
the optimizer to know the result of the computation at compile time and 
you allowed it to know that the result will be ignored.  So the 
optimizer can remove the whole computation.

If you want to examine the results of a specific optimization, you must 
keep the optimizer from knowing the input values at compile time and you 
must make the optimizer think the result could be used.

If you just want to see (not benchmark) the resulting asm code, you 
don't need a complete program, just a complete function.  If the 
inputs/outputs of your computation are inputs/outputs of the function 
(that you compile separate from any call) then the optimizer can't short 
circuit the computation.


rohitgeek wrote:
>
>
> I will try to be descriptive this time .
>
>
>   
...
> Also bringing into notice the point of single instruction generation instead
> of 2 instructions (multiply and accumulate), what part of gcc will do it and
> how to proceed regarding that.
>
>
>   

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-02-24  5:21       ` rohitgeek
                           ` (3 preceding siblings ...)
  2010-03-01 15:27         ` John S. Fine
@ 2010-03-01 21:21         ` Ian Lance Taylor
  2010-03-02  4:57           ` rohitgeek
  4 siblings, 1 reply; 20+ messages in thread
From: Ian Lance Taylor @ 2010-03-01 21:21 UTC (permalink / raw)
  To: rohitgeek; +Cc: gcc-help

rohitgeek <rohit23taneja@gmail.com> writes:

> This is test.c
>
>  main()
>   {
>   int a,b,c;
>    a= 5;
>    b=10;
>    d=30;
>   c=  a*b + 30 ;
> }

What everyone is trying to tell you is that that program is precisely
equivalent to this one:

main() { }

The optimizer is smart enough to reduce the former to the latter.

Ian

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-03-01 21:21         ` Ian Lance Taylor
@ 2010-03-02  4:57           ` rohitgeek
  2010-03-02  8:32             ` Cedric Roux
  0 siblings, 1 reply; 20+ messages in thread
From: rohitgeek @ 2010-03-02  4:57 UTC (permalink / raw)
  To: gcc-help




Thanks John and Ian. 

@John  
Until you posted this, i never thought like that. I get what you have
mentioned in post and when tried with function rather than in main {} as
mentioned by Ian too, i get what i expect. But why does optimizer does so?
Where is the assembly or data gone when doing the earlier way, because if we
put some data into registers and done some manipulations, then where are
they gone from assembly. I think my question has answer in your post ( "
optimizer ignores the data and computation") , but i am still not getting it
correctly.
-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27752183.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-03-02  4:57           ` rohitgeek
@ 2010-03-02  8:32             ` Cedric Roux
  2010-03-02 12:44               ` rohitgeek
  0 siblings, 1 reply; 20+ messages in thread
From: Cedric Roux @ 2010-03-02  8:32 UTC (permalink / raw)
  To: rohitgeek; +Cc: gcc-help

rohitgeek wrote:
> mentioned by Ian too, i get what i expect. But why does optimizer does so?

because it can with respect to the semantics of the compiled language.
Your statements assign values to local variables.
There is no side effect.
The values you assign are not used later on.
So they are completely useless. Computing them or not won't change
the semantics of your program. At all.
It's cool that gcc finds that out for cases where your code actually
does something, where optimization is useful. No?

> Where is the assembly or data gone when doing the earlier way, because if we

You write programs in C, not in assembly language. The C compiler
can compile the way it wants as long as the C semantics is
respected.

> put some data into registers and done some manipulations, then where are

This is what you don't understand I guess. Your program doesn't "put some data into
registers and [does] some manipulations." Your program assigns values to C variables.
This is another world.
C is not assembly language.

So in short, as others said, if you want the code to stay there
after optimization, be sure it does real stuff, like returning
the computed value. The computed value has to "escape" the local
scope for it to be "respected" by the optimization.

My .2 euros.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: optimization options not working
  2010-03-02  8:32             ` Cedric Roux
@ 2010-03-02 12:44               ` rohitgeek
  0 siblings, 0 replies; 20+ messages in thread
From: rohitgeek @ 2010-03-02 12:44 UTC (permalink / raw)
  To: gcc-help



Your .2 euros turned into  high value , i got the point. And yes, gcc got
the hidden talent.


Cedric Roux-4 wrote:
> 
> rohitgeek wrote:
>> mentioned by Ian too, i get what i expect. But why does optimizer does
>> so?
> 
> because it can with respect to the semantics of the compiled language.
> Your statements assign values to local variables.
> There is no side effect.
> The values you assign are not used later on.
> So they are completely useless. Computing them or not won't change
> the semantics of your program. At all.
> It's cool that gcc finds that out for cases where your code actually
> does something, where optimization is useful. No?
> 
>> Where is the assembly or data gone when doing the earlier way, because if
>> we
> 
> You write programs in C, not in assembly language. The C compiler
> can compile the way it wants as long as the C semantics is
> respected.
> 
>> put some data into registers and done some manipulations, then where are
> 
> This is what you don't understand I guess. Your program doesn't "put some
> data into
> registers and [does] some manipulations." Your program assigns values to C
> variables.
> This is another world.
> C is not assembly language.
> 
> So in short, as others said, if you want the code to stay there
> after optimization, be sure it does real stuff, like returning
> the computed value. The computed value has to "escape" the local
> scope for it to be "respected" by the optimization.
> 
> My .2 euros.
> 
> 

-- 
View this message in context: http://old.nabble.com/optimization-options-not-working-tp27637400p27755423.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2010-03-02 12:44 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-18 12:08 optimization options not working rohitgeek
2010-02-18 13:46 ` Andrew Haley
2010-02-19 19:07   ` rohitgeek
2010-02-23 18:19     ` Ian Lance Taylor
2010-02-24  5:21       ` rohitgeek
2010-02-24 14:11         ` rohitgeek
2010-02-24 18:28         ` Andrew Haley
2010-03-01  5:09         ` rohitgeek
2010-03-01 15:27         ` John S. Fine
2010-03-01 21:21         ` Ian Lance Taylor
2010-03-02  4:57           ` rohitgeek
2010-03-02  8:32             ` Cedric Roux
2010-03-02 12:44               ` rohitgeek
2010-02-24  5:23       ` rohitgeek
2010-02-24  5:23       ` rohitgeek
2010-02-24  5:26       ` rohitgeek
2010-02-24  5:27       ` rohitgeek
2010-02-24  5:32       ` rohitgeek
2010-02-24  9:30         ` rohitgeek
2010-02-24  9:18       ` rohitgeek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).