Compiler produced IL code 
Author Message
 Compiler produced IL code

I am currently working with C# and like to find the best way to write code
that is the most efficient so I have been studying the IL code produced from
compiling C# and cam across this which I am struggling to understand.
With the method:-
private int test()

{

return 10;

Quote:
}

this produces the following IL code

.method private hidebysig instance int32
        test() cil managed
{
  // Code size       7 (0x7)
  .maxstack  1
  .locals init ([0] int32 CS$00000003$00000000)
  IL_0000:  ldc.i4.s   10
  IL_0002:  stloc.0
  IL_0003:  br.s       IL_0005 // What is the point of this instruction?
  IL_0005:  ldloc.0
  IL_0006:  ret

Quote:
} // end of method TestClassDerived::test

As you can see at line IL_0003 there is a explicit branch to the next line
of code can anyone shed any light on why this line is required. Also will
this code be optimized out in the final compile before running of this code.

John Davis



Sat, 26 Feb 2005 05:15:05 GMT  
 Compiler produced IL code
John,

Quote:
>As you can see at line IL_0003 there is a explicit branch to the next line
>of code can anyone shed any light on why this line is required.

I think it's there to make it easier to debug the code. You'll see
better, more compact code if you turn on optimizations.

Quote:
>Also will
>this code be optimized out in the final compile before running of this code.

Yes, it most likely would (in a Release build).

Mattias

===

http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.



Sat, 26 Feb 2005 05:40:33 GMT  
 Compiler produced IL code
Try compiling in release build, although I doubt anything will change. From
what I observed the debug/release generate virtually identical IL code for
C#. After running tests, it seems that C# produces shortest, yet least
efficient, code followed by VB.NET which produces longer yet more efficient
code, followed by MC++ which produces much longest instruction sequence, yet
highly efficient code. There will be some optimizations done during JIT but
those will never be as substantial as during compile time.

From what I understand from C# compiler team is that they will address
optimization issues in the next version.

From some test I've done a while back, C# was about 30% slower then VB.NET,
which in turn was about 10% slower then MC++. But that was only for my
specific case.

Mark


Quote:
> I am currently working with C# and like to find the best way to write code
> that is the most efficient so I have been studying the IL code produced
from
> compiling C# and cam across this which I am struggling to understand.
> With the method:-
> private int test()

> {

> return 10;

> }

> this produces the following IL code

> .method private hidebysig instance int32
>         test() cil managed
> {
>   // Code size       7 (0x7)
>   .maxstack  1
>   .locals init ([0] int32 CS$00000003$00000000)
>   IL_0000:  ldc.i4.s   10
>   IL_0002:  stloc.0
>   IL_0003:  br.s       IL_0005 // What is the point of this instruction?
>   IL_0005:  ldloc.0
>   IL_0006:  ret
> } // end of method TestClassDerived::test

> As you can see at line IL_0003 there is a explicit branch to the next line
> of code can anyone shed any light on why this line is required. Also will
> this code be optimized out in the final compile before running of this
code.

> John Davis



Sat, 26 Feb 2005 05:57:53 GMT  
 Compiler produced IL code
Mark,
Can you list your specific case? I'm interested in seeing how/when VB
compiler generates more efficient IL. Under what circumstances are you
talking about? IL has been tackled by a few but rarely documented so I try
to get bits and pieces where I can.

thanks,
Ian Stallings


Quote:
> Try compiling in release build, although I doubt anything will change.
From
> what I observed the debug/release generate virtually identical IL code for
> C#. After running tests, it seems that C# produces shortest, yet least
> efficient, code followed by VB.NET which produces longer yet more
efficient
> code, followed by MC++ which produces much longest instruction sequence,
yet
> highly efficient code. There will be some optimizations done during JIT
but
> those will never be as substantial as during compile time.

> From what I understand from C# compiler team is that they will address
> optimization issues in the next version.

> From some test I've done a while back, C# was about 30% slower then
VB.NET,
> which in turn was about 10% slower then MC++. But that was only for my
> specific case.

> Mark



> > I am currently working with C# and like to find the best way to write
code
> > that is the most efficient so I have been studying the IL code produced
> from
> > compiling C# and cam across this which I am struggling to understand.
> > With the method:-
> > private int test()

> > {

> > return 10;

> > }

> > this produces the following IL code

> > .method private hidebysig instance int32
> >         test() cil managed
> > {
> >   // Code size       7 (0x7)
> >   .maxstack  1
> >   .locals init ([0] int32 CS$00000003$00000000)
> >   IL_0000:  ldc.i4.s   10
> >   IL_0002:  stloc.0
> >   IL_0003:  br.s       IL_0005 // What is the point of this instruction?
> >   IL_0005:  ldloc.0
> >   IL_0006:  ret
> > } // end of method TestClassDerived::test

> > As you can see at line IL_0003 there is a explicit branch to the next
line
> > of code can anyone shed any light on why this line is required. Also
will
> > this code be optimized out in the final compile before running of this
> code.

> > John Davis



Sun, 27 Feb 2005 01:00:50 GMT  
 Compiler produced IL code
I found the example in google groups, disregard this, thanks.


Quote:
> Mark,
> Can you list your specific case? I'm interested in seeing how/when VB
> compiler generates more efficient IL. Under what circumstances are you
> talking about? IL has been tackled by a few but rarely documented so I try
> to get bits and pieces where I can.

> thanks,
> Ian Stallings



> > Try compiling in release build, although I doubt anything will change.
> From
> > what I observed the debug/release generate virtually identical IL code
for
> > C#. After running tests, it seems that C# produces shortest, yet least
> > efficient, code followed by VB.NET which produces longer yet more
> efficient
> > code, followed by MC++ which produces much longest instruction sequence,
> yet
> > highly efficient code. There will be some optimizations done during JIT
> but
> > those will never be as substantial as during compile time.

> > From what I understand from C# compiler team is that they will address
> > optimization issues in the next version.

> > From some test I've done a while back, C# was about 30% slower then
> VB.NET,
> > which in turn was about 10% slower then MC++. But that was only for my
> > specific case.

> > Mark



> > > I am currently working with C# and like to find the best way to write
> code
> > > that is the most efficient so I have been studying the IL code
produced
> > from
> > > compiling C# and cam across this which I am struggling to understand.
> > > With the method:-
> > > private int test()

> > > {

> > > return 10;

> > > }

> > > this produces the following IL code

> > > .method private hidebysig instance int32
> > >         test() cil managed
> > > {
> > >   // Code size       7 (0x7)
> > >   .maxstack  1
> > >   .locals init ([0] int32 CS$00000003$00000000)
> > >   IL_0000:  ldc.i4.s   10
> > >   IL_0002:  stloc.0
> > >   IL_0003:  br.s       IL_0005 // What is the point of this
instruction?
> > >   IL_0005:  ldloc.0
> > >   IL_0006:  ret
> > > } // end of method TestClassDerived::test

> > > As you can see at line IL_0003 there is a explicit branch to the next
> line
> > > of code can anyone shed any light on why this line is required. Also
> will
> > > this code be optimized out in the final compile before running of this
> > code.

> > > John Davis



Mon, 28 Feb 2005 00:04:04 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. C# produces better IL than C++

2. Compiler produces bad code

3. Simple Code Produce "INTERNAL COMPILER ERROR"

4. Compiler producing smaller code than gcc ?

5. Need a C compiler to produce stand-alone code

6. how to hide IL code ?

7. Need Help!!Convert IL code to C#

8. C# COM objects and IL code question

9. transform IL code to C#

10. Way to convert IL code to C#

11. How to get the JIT result native code of IL

12. modifying IL or source code

 

 
Powered by phpBB® Forum Software