Skip to content

Bound Check for arr[(X & 0x3) << 4] pattern #122150

@EgorBo

Description

@EgorBo

Another minimal repro from base64 encoder:

byte Foo(byte inData)
{
    ReadOnlySpan<byte> base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="u8;
    return base64[(inData & 0x03) << 4];
}

(X & 3) means X is [0..3] and << 4 means the max value is 48 while the array has 65 elements => the bound check should be elided.

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIreduce-unsafe

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions