Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / July 2006

Tip: Looking for answers? Try searching our database.

Pointless IL Instructions?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben R. - 26 Jul 2006 20:07 GMT
Thought this was a better forum for this question:

I've got a simple console app which just assigns 6 to an int and prints out
the value. The IL looks like:

.method public static void  Main() cil managed
{
 .entrypoint
 .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01
00 00 00 )
 // Code size       12 (0xc)
 .maxstack  1
 .locals init ([0] int32 x)
 IL_0000:  nop
 IL_0001:  ldc.i4.6
 IL_0002:  stloc.0
 IL_0003:  ldloc.0
 IL_0004:  call       void [mscorlib]System.Console::Write(int32)
 IL_0009:  nop
 IL_000a:  nop
 IL_000b:  ret
} // end of method Module1::Main

What is the point of these:
 IL_0002:  stloc.0
 IL_0003:  ldloc.0

Why store something in a variable just to put the exact thing right back on
the stack where it was? The proper value was on the stack before that anway,
right? Couldn't these two lines be taken out?

-Ben
Michael Nemtsev - 26 Jul 2006 20:48 GMT
Hello Ben R.,

Don't crosspost.
I've replied in framework group

B> Thought this was a better forum for this question:
B>
B> I've got a simple console app which just assigns 6 to an int and
B> prints out the value. The IL looks like:
B>
B> .method public static void  Main() cil managed
B> {
B> .entrypoint
B> .custom instance void [mscorlib]System.STAThreadAttribute::.ctor()
B> = ( 01
B> 00 00 00 )
B> // Code size       12 (0xc)
B> .maxstack  1
B> .locals init ([0] int32 x)
B> IL_0000:  nop
B> IL_0001:  ldc.i4.6
B> IL_0002:  stloc.0
B> IL_0003:  ldloc.0
B> IL_0004:  call       void [mscorlib]System.Console::Write(int32)
B> IL_0009:  nop
B> IL_000a:  nop
B> IL_000b:  ret
B> } // end of method Module1::Main
B> What is the point of these:
B> IL_0002:  stloc.0
B> IL_0003:  ldloc.0
B> Why store something in a variable just to put the exact thing right
B> back on the stack where it was? The proper value was on the stack
B> before that anway, right? Couldn't these two lines be taken out?
B>
B> -Ben
B>
---
WBR,
Michael  Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
Barry Kelly - 27 Jul 2006 00:24 GMT
> What is the point of these:
>   IL_0002:  stloc.0
>   IL_0003:  ldloc.0

The CLI isn't a machine - it's a serialization format for semantics.
When viewing the stack machine code, think 'serialized expression
graph', not 'CPU opcodes'.

-- Barry

Signature

http://barrkel.blogspot.com/

Jon Shemitz - 27 Jul 2006 16:33 GMT
> > What is the point of these:
> >   IL_0002:  stloc.0
[quoted text clipped - 3 lines]
> When viewing the stack machine code, think 'serialized expression
> graph', not 'CPU opcodes'.

Or, to translate that into language the OP may understand: CIL is a
program that the jitter will compile, and the jitter is perfectly
capable of optimizing out the unnecessary use of a local variable.

Signature

.NET 2.0 for Delphi Programmers        www.midnightbeach.com/.net
Delphi skills make .NET easy to learn  In print, in stores.

Barry Kelly - 27 Jul 2006 16:48 GMT
> > The CLI isn't a machine - it's a serialization format for semantics.
> > When viewing the stack machine code, think 'serialized expression
> > graph', not 'CPU opcodes'.
>
> Or, to translate that into language the OP may understand:

Is it that bad :) I am spending too much time in compiler-land...

-- Barry

Signature

http://barrkel.blogspot.com/


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.