Skip to content

RyuJIT SIMD: Test for equality against zero can be optimized on AVX #6719

@sivarv

Description

@sivarv

As per Intel TechEmPower benchmark analysis, Kestrel.Internal.Infrastructure.MemoryPoolIterator.Seek() is one of the hot methods. This method uses equality against Vector.Zero

var data = new Vector<byte>(array, index);
var byte0Equals = Vector.Equals(data, byte0Vector);
var byte1Equals = Vector.Equals(data, byte1Vector);
var byte2Equals = Vector.Equals(data, byte2Vector);

if (!byte0Equals.Equals(Vector<byte>.Zero))
{
        byte0Index = FindFirstEqualByte(ref byte0Equals);
}

if (!byte1Equals.Equals(Vector<byte>.Zero))
{
        byte1Index = FindFirstEqualByte(ref byte1Equals);
}
if (!byte2Equals.Equals(Vector<byte>.Zero))
{
        byte2Index = FindFirstEqualByte(ref byte2Equals);
}

That is, SIMD API used is

bool Vector<T>.Equals(Vector<T> v)

Right now RyuJIT backend is generating the following

// Assume that byte0Equals in ymm0 reg
byte0Equals.Equals(Vector<byte>.Zero)

image

RyuJIT backend should be able to detect equality check against is Vector.Zero and generate the following optimal code

ptest ymm0, ymm0
setz dil
movzx edx, dil

Similarly for in-equality check against zero, we can generate

ptest ymm0, ymm0
setnz dil
movzx edx, dil

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions