[Mono-bugs] [Bug 53012][Wis] New - Optimize loops

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sun, 18 Jan 2004 01:36:20 -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=53012

--- shadow/53012	2004-01-18 01:36:20.000000000 -0500
+++ shadow/53012.tmp.25599	2004-01-18 01:36:20.000000000 -0500
@@ -0,0 +1,81 @@
+Bug#: 53012
+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: Optimize loops
+
+Ok, a few items for discuession (thanks miguel, for getting me thinking
+abou this).
+
+class Test {
+	static void Main ()
+	{
+		bool b = true;
+		bool c = true;
+		while (c) {
+			if (b)
+				break;
+		}
+	}
+}
+
+We generate:
+        IL_0000:  ldc.i4.1
+        IL_0001:  stloc.0
+        IL_0002:  ldc.i4.1
+        IL_0003:  stloc.1
+        IL_0004:  br IL_0014
+ 
+        IL_0009:  ldloc.0
+        IL_000a:  brfalse IL_0014
+ 
+        IL_000f:  br IL_001a
+ 
+        IL_0014:  ldloc.1
+        IL_0015:  brtrue IL_0009
+ 
+        IL_001a:  ret
+
+We could just replace IL_000a with
+   brtrue IL_001a
+and remove 000f. This saves us a branch.
+
+class Test {
+	static void Main ()
+	{
+		bool b = true;
+		while (true) {
+			if (b)
+				continue;
+			
+			b = ! b;
+		}
+	}
+}
+
+We generate:
+        IL_0000:  ldc.i4.1
+        IL_0001:  stloc.0
+        IL_0002:  ldloc.0
+        IL_0003:  brfalse IL_000d
+ 
+        IL_0008:  br IL_0002
+ 
+        IL_000d:  ldloc.0
+        IL_000e:  ldc.i4.0
+        IL_000f:  ceq
+        IL_0011:  stloc.0
+        IL_0012:  br IL_0002
+Again, we can replace brfalse with brtrue, and remove the unconditional branch.