See discussion in dotnet/corefx#26087.
using System;
using System.Runtime.CompilerServices;
public class Program
{
private static int[] _array = new int[3];
static Program() {}
public static void Main(string[] args)
{
int index = 3;
MoveNext1(ref index);
MoveNext2(ref index);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void MoveNext1(ref int index)
{
int tmp = index + 1;
index = (tmp == _array.Length) ? 0 : tmp;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void MoveNext2(ref int index)
{
int tmp = index + 1;
if (tmp == _array.Length) tmp = 0;
index = tmp;
}
}
The code for MoveNext1 contains the following branch-around branch sequence:
394108 cmp dword ptr [rcx+8], eax
7402 je SHORT G_M38324_IG03
EB02 jmp SHORT G_M38324_IG04
G_M38324_IG03:
33C0 xor eax, eax
G_M38324_IG04:
8902 mov dword ptr [rdx], eax
category:cq
theme:flowgraph
skill-level:expert
cost:small
See discussion in dotnet/corefx#26087.
The code for
MoveNext1contains the following branch-around branch sequence:category:cq
theme:flowgraph
skill-level:expert
cost:small