I expected the entire computation leading up to mask to be moved inside the branch. Currently it's doing all these computations unconditionally.
https://godbolt.org/z/hbadsraxd
void BitArrayIndex(int index, bool value, uint[] data)
{
const int BITS_PER_ELEMENT = sizeof(uint) * 8;
uint arrIndex = (uint)index / BITS_PER_ELEMENT;
uint bitIndex = (uint)index % BITS_PER_ELEMENT;
uint mask = 1u << (int)bitIndex;
if (value)
{
data[arrIndex] |= mask;
}
}
G_M000_IG01: ;; offset=0x0000
sub rsp, 40
G_M000_IG02: ;; offset=0x0004
mov eax, edx
shr eax, 5
mov ecx, 1
shlx ecx, ecx, edx
test r8b, r8b
je SHORT G_M000_IG04
G_M000_IG03: ;; offset=0x0018
cmp eax, dword ptr [r9+0x08]
jae SHORT G_M000_IG05
mov eax, eax
lea rax, bword ptr [r9+4*rax+0x10]
or dword ptr [rax], ecx
G_M000_IG04: ;; offset=0x0027
add rsp, 40
ret
G_M000_IG05: ;; offset=0x002C
call CORINFO_HELP_RNGCHKFAIL
int3
I expected the entire computation leading up to
maskto be moved inside the branch. Currently it's doing all these computations unconditionally.https://godbolt.org/z/hbadsraxd