[Mono-devel-list] Performance of leave vs. br
Ben Maurer
bmaurer at users.sourceforge.net
Tue Jan 20 20:45:40 EST 2004
Hello,
Today I noted that for the code:
> using System;
>
> class T {
> static void Main ()
> {
> bool a = false, b = false, c = true;
> try {
> while (a)
> if (b) break;
>
> Console.WriteLine (c);
> } catch {
> }
> }
> }
That we emit:
> .try { // 0
> IL_0006: br IL_0016
>
> IL_000b: ldloc.2
> IL_000c: brfalse IL_0016
>
> IL_0011: leave IL_001c
>
> IL_0016: ldloc.1
> IL_0017: brtrue IL_000b
>
> IL_001c: ldloc.0
> IL_001d: call void class [mscorlib]'System.Console'::'WriteLine'(bool)
> IL_0022: leave IL_002d
>
> } // end .try 0
In IL_0011, the op code could just as well be a `br' because it is not
leaving the try statement.
I was wondering if there is enough of a difference in the code we
generate to justify an optimization in MCS.
(Another interesting point is the brfalse. really, we could just write
for this loop:
> IL_0006: br IL_0016
>
> IL_000b: ldloc.2
> IL_000c: brtrue IL_001
>
> IL_0016: ldloc.1
> IL_0017: brtrue IL_000b
>
> IL_001c: ldloc.0
> IL_001d: call void class [mscorlib]'System.Console'::'WriteLine'(bool)
> IL_0022: leave IL_002d
Can the JIT optimize this sort of case today? If not, should we
implement it in the JIT or the Compiler?
-- Ben
More information about the Mono-devel-list
mailing list