private void TryOptimizeBranch(MsilInstruction instruction)
{
MsilInstruction operand = instruction.Operand as MsilInstruction;
int relativeOperand = operand.Offset - (instruction.Offset + 2);
if (operand == null || relativeOperand < sbyte.MinValue || relativeOperand > sbyte.MaxValue)
return;
switch (instruction.OpCode.Code)
{
case MsilCode.Br:
instruction.OpCode = MsilOpCodes.Br_S;
break;
case MsilCode.Leave:
instruction.OpCode = MsilOpCodes.Leave_S;
break;
case MsilCode.Brfalse:
instruction.OpCode = MsilOpCodes.Brfalse_S;
break;
case MsilCode.Brtrue:
instruction.OpCode = MsilOpCodes.Brtrue_S;
break;
case MsilCode.Beq:
instruction.OpCode = MsilOpCodes.Beq_S;
break;
case MsilCode.Bge:
instruction.OpCode = MsilOpCodes.Bge_S;
break;
case MsilCode.Bge_Un:
instruction.OpCode = MsilOpCodes.Bge_Un_S;
break;
case MsilCode.Bgt:
instruction.OpCode = MsilOpCodes.Bgt_S;
break;
case MsilCode.Bgt_Un:
instruction.OpCode = MsilOpCodes.Bgt_Un_S;
break;
case MsilCode.Ble:
instruction.OpCode = MsilOpCodes.Ble_S;
break;
case MsilCode.Ble_Un:
instruction.OpCode = MsilOpCodes.Ble_Un_S;
break;
case MsilCode.Blt:
instruction.OpCode = MsilOpCodes.Blt_S;
break;
case MsilCode.Blt_Un:
instruction.OpCode = MsilOpCodes.Blt_Un_S;
break;
case MsilCode.Bne_Un:
instruction.OpCode = MsilOpCodes.Bne_Un_S;
break;
}
}