[Mono-devel-list] First CIL Regex performance result

Ben Maurer bmaurer at users.sourceforge.net
Sun Feb 29 13:34:48 EST 2004


On Sun, 2004-02-29 at 12:41, Eric Durand Tremblay wrote:
> 		blt IL_0096
> 		br  IL_0075
> 	  You can do a simple jump optimization, and change that to:
> 		bge IL_0075
> 
> These two line of IL are independent (One is from emitBranch, the
> other by emitCharacter)  For exemple, a character matching is'nt
> necessary called by a branch.  It can be called directly by an anchor
> or anything else.

Hrm, maybe we can catch this in the JIT. I think MCS emits code like
this sometimes. For example, when we have:

> while (true) {
> 	i ++;
> 	if (a < b)
> 		continue;
> 	...
> }

MCS emits
> // i++
>         IL_0006:  ldloc.0
>         IL_0007:  ldc.i4.1
>         IL_0008:  add
>         IL_0009:  stloc.0
> // if (a < b)
>         IL_000a:  ldloc.1
>         IL_000b:  ldloc.2
>         IL_000c:  bge IL_0016
> // continue
>         IL_0011:  br IL_0006
> // ...

I think this would be easier to get in the JIT.


> 	* In 0xba, you do something similar:
> 
> 		IL_00ba:  beq IL_00c4
> 		IL_00bf:  br IL_0075
> 		IL_00c4:  br IL_012d

> From Ben :
> 
> Ok, lemme add some of my own:
> > > 	IL_000d:  ldc.i4 0
> > > 	IL_0012:  add 
> x + 0 = x
> The peace of code you this refer to resolve to (int anch_end =
> text_end - match_min + anch_offset)  
> The 0 is anch_offset... You are right, I can test this (anch_offset is
> almost always 0)
Now that I think of it, we should be catching this in the JIT.


> For debugging purposes, some of your code is really complex and hard
> to
> understand. I realize it is not designed to be read, but you are going
> ot make it hard on yourself if you emit code like:
> 
> Yeah, we taught that Dup was more efficient than reloading the value. 
Why think? Why not just look at the code:


> case CEE_DUP: {
> 	/* ... */
> 		
> 	/* 
> 	 * small optimization: if the loaded value was from a local already,
> 	 * just load it twice.
> 	 */
> 	if (ins->ssa_op == MONO_SSA_LOAD && 
> 	    (ins->inst_i0->opcode == OP_LOCAL || ins->inst_i0->opcode == OP_ARG)) {


> > > IL_00da:  br IL_0128
> > > ...
> > > IL_0128:  br IL_005f
> >   
> That can be simplified.
> > > 	IL_002a:  blt IL_0068
> > > 	IL_0063:  br IL_0028
> > > 
> > > 	IL_0068:  ldc.i4.0 
> > > 	IL_0069:  ret
> >   
> The only branch to 68 is the one in 2a. So you can just move the code
> up there.

Actually, this one could also get caught by the jit. MCS emits this one
too sometimes:


> 		string s = "foo";
> 		char lastletter = ' ';
> 		foreach (char c in s) {
> 			if (char.IsLetter (c))
> 				lastletter = c;
> 		}

gives:


>         IL_0000:  ldstr "foo"
>         IL_0005:  stloc.0
>         IL_0006:  ldc.i4.s 0x20
>         IL_0008:  stloc.1
>         IL_0009:  ldloc.0
>         IL_000a:  callvirt instance class [mscorlib]'System.CharEnumerator' valuetype [mscorlib]'System.String'::'GetEnumerator'()
>         IL_000f:  stloc.3
>         IL_0010:  ldloc.3
>         IL_0011:  callvirt instance bool class [mscorlib]'System.CharEnumerator'::'MoveNext'()
>         IL_0016:  brfalse IL_0034
>  
>         IL_001b:  ldloc.3
>         IL_001c:  callvirt instance char class [mscorlib]'System.CharEnumerator'::'get_Current'()
>         IL_0021:  stloc.2
>         IL_0022:  ldloc.2
>         IL_0023:  call bool valuetype [mscorlib]'System.Char'::'IsLetter'(char)
>         IL_0028:  brfalse IL_002f
>  
>         IL_002d:  ldloc.2
>         IL_002e:  stloc.1
>         IL_002f:  br IL_0010





More information about the Mono-devel-list mailing list