public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: pms <pmshiva@gmail.com>
Cc: gcc@gcc.gnu.org
Subject: Re: regarding optimization options in phase ordering
Date: Mon, 10 Aug 2009 13:08:00 -0000	[thread overview]
Message-ID: <m3skfz99ol.fsf@google.com> (raw)
In-Reply-To: <24898021.post@talk.nabble.com> (pms's message of "Mon\, 10 Aug 2009 04\:20\:35 -0700 \(PDT\)")

pms <pmshiva@gmail.com> writes:

> My question is as follwos
>
> We've a problem here. we were trying to use cc1 with & without -O option to
> verify the optimizations happening in our sample code. 
> the sample code is given below
> file name : 1.c
>  #include
>  int main() 
> { int a=5; 
> int b; 
> b=a; 
> printf("the number is :%d",b); }
> Here, in 1.c.026t.copyrename1, we get the following output
>
> 1.c.026t.copyrename1
>  ;; Function main (main) 
> main ()
>  { int b; int a; : a_2 = b_1(D); return; }
>  but in 1.c.027t.ccp1, the output does not contain the actual assignment
> b=a. 
> ;; Function main (main)
>  main () 
> { int b; int a; : return; }
>  We want to know, without b=a, how is it generating the following final code
> for b=a 
> pushl   %ebp
>>         movl    %esp, %ebp
>>         andl    $-16, %esp
>>         subl    $16, %esp
>>         movl    $5, 4(%esp)
>>         movl    $.LC0, (%esp)
>>         call    printf

No code is generated for the statement "b=a".  In effect, the program is
optimized into
  printf("the number is :%d",5);
as that is equivalent to the original program.

This is a very simple compiler optimization.  Please consider taking
future questions about code generation to the mailing list
gcc-help@gcc.gnu.org.  The mailing list gcc@gcc.gnu.org is for gcc
developers.  Thanks.

Ian


>> thanks, But b=a is a assignment statement. It is doing some memory
>> operations
>> isn't it. Assuming b=a is a dead statement, how r the following i386
>> assembly statements generated
>>  pushl   %ebp
>>         movl    %esp, %ebp
>>         andl    $-16, %esp
>>         subl    $16, %esp
>>         movl    $5, 4(%esp)
>>         movl    $.LC0, (%esp)
>>         call    printf
>
> The first four statements set up the stack.  The last three do the
> printf statement.
>
> What is your real question?
>
> Ian

      reply	other threads:[~2009-08-10 11:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-07 11:53 pms
2009-08-07 12:34 ` Richard Guenther
2009-08-07 13:11   ` pms
2009-08-10 11:20     ` Ian Lance Taylor
2009-08-10 13:00       ` pms
2009-08-10 13:08         ` Ian Lance Taylor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3skfz99ol.fsf@google.com \
    --to=iant@google.com \
    --cc=gcc@gcc.gnu.org \
    --cc=pmshiva@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).