KEMBAR78
JIT can generate redundant TEST operations · Issue #10742 · dotnet/runtime · GitHub
Skip to content

JIT can generate redundant TEST operations #10742

@Zhentar

Description

@Zhentar

The following C# code generates assembly which has what I understand to be a redundant test instruction:

private static int PopulatedByte(uint bytes, uint delimMask)
{
	var checkDelim = bytes ^ delimMask; //zero out matches, all others non-zero
	uint onlyDelimHasSign = Bmi1.AndNot( /*notted*/ checkDelim, checkDelim - INDEXOF_BYTEMULT32) & 0x80808080u;
	return onlyDelimHasSign == 0 ? -1 : ByteIndexThatIsntZero(onlyDelimHasSign);
}

private static int ByteIndexThatIsntZero(uint value)
{
	return (int)(Bmi1.TrailingZeroCount(value) >> 3);
}
	xor     r9d,0A0A0A0Ah
	lea     r10d,[r9-1010101h]
	andn    r9d,r9d,r10d
	and     r9d,80808080h
	test    r9d,r9d   ;not needed because  flags have already been set by preceding and
	je      M04_L07
	tzcnt   r9d,r9d
	shr     r9d,3
	jmp     M04_L08
M04_L07
	mov     r9d,0FFFFFFFFh
M04_L08

category:cq
theme:optimization
skill-level:beginner
cost:small

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionshelp wanted[up-for-grabs] Good issue for external contributorsoptimization

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions