G
Guest
Where can one find a discussion of the current and future optimizations that the C# compilers do? When I see things like the following I question my faith in csc being good at optimizing. The same kind of thing shows up in cordbg when looking at the JIT code for a similar example
% cat y.c
using System
class A
bool On { get { return true; }
public void Print()
if (On)
Console.WriteLine("On")
class ConditionalTest
static void Main(
A a = new A()
a.Print()
% csc /optimize+ y.c
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.
for Microsoft (R) .NET Framework version 1.1.432
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved
% ildasm y.ex
..method public hidebysig instance void Print() cil manage
// Code size 19 (0x13
..maxstack
IL_0000: ldarg.
IL_0001: call instance bool A::get_On(
IL_0006: brfalse.s IL_001
IL_0008: ldstr "On
IL_000d: call void [mscorlib]System.Console::WriteLine(string
IL_0012: re
} // end of method A:rin
At least the compiler eliminates the "if" test when "On" is replaced with "true" in the test
% cat y.c
using System
class A
bool On { get { return true; }
public void Print()
if (On)
Console.WriteLine("On")
class ConditionalTest
static void Main(
A a = new A()
a.Print()
% csc /optimize+ y.c
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.
for Microsoft (R) .NET Framework version 1.1.432
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved
% ildasm y.ex
..method public hidebysig instance void Print() cil manage
// Code size 19 (0x13
..maxstack
IL_0000: ldarg.
IL_0001: call instance bool A::get_On(
IL_0006: brfalse.s IL_001
IL_0008: ldstr "On
IL_000d: call void [mscorlib]System.Console::WriteLine(string
IL_0012: re
} // end of method A:rin
At least the compiler eliminates the "if" test when "On" is replaced with "true" in the test