[Mono-bugs] [Bug 54917][Wis] New - We miss some optimizations with callvirt
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Thu, 26 Feb 2004 17:52:29 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by bmaurer@users.sf.net.
http://bugzilla.ximian.com/show_bug.cgi?id=54917
--- shadow/54917 2004-02-26 17:52:29.000000000 -0500
+++ shadow/54917.tmp.29314 2004-02-26 17:52:29.000000000 -0500
@@ -0,0 +1,66 @@
+Bug#: 54917
+Product: Mono/Compilers
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: C#
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: bmaurer@users.sf.net
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: We miss some optimizations with callvirt
+
+Callvirt not only does vtable lookups, but also does checking for null
+values. It is what generates NullReferenceExceptions. However, the checks
+obviously come at a cost. Right now, we do not avoid callvirt in some
+situations when we can.
+
+Take the code:
+
+class T {
+ static void Main () {
+ new T ().Foo ();
+ }
+
+ void Foo () { Bar (); }
+ void Bar () {}
+}
+
+csc emits the following code:
+
+Main:
+ IL_0000: newobj instance void class 'T'::.ctor()
+ IL_0005: call instance void class 'T'::'Foo'()
+ IL_000a: ret
+
+
+Foo:
+ IL_0000: ldarg.0
+ IL_0001: call instance void class 'T'::'Bar'()
+ IL_0006: ret
+
+We emit callvirt for the two call instructions. the case for emitting call
+in Foo is pretty clear. the implicit this argument is never going to be
+null, so you dont need to do the null check.
+
+The Main case is a bit more fuzzy. I am guessing the rationale is that a
+ctor always generates a non-null value.
+
+If i use the code:
+ static void Main () {
+ T t = new T ();
+ t.Foo ();
+ }
+
+csc emits:
+ IL_0000: newobj instance void class 'T'::.ctor()
+ IL_0005: stloc.0
+ IL_0006: ldloc.0
+ IL_0007: callvirt instance void class 'T'::'Foo'()
+ IL_000c: ret