KEMBAR78
Avoid duplicate cmp instruction, avoid boolean zero extension · Issue #70003 · dotnet/runtime · GitHub
Skip to content

Avoid duplicate cmp instruction, avoid boolean zero extension #70003

@thinkbeforecoding

Description

@thinkbeforecoding

I'm working on comparison optimization for the F# compiler to implement branchless compare dotnet/fsharp#13098

The following implementation improves average performance, using only a cgt - clt:

image

image

However, I noticed that the same cmp ecx edx instruction is issued twice, and this is unnecessary as setg and movzx don't change flags.

I also thought that the following version would be even shorter:

image

image

but it's actually longer. The result from cgt/clt is zero extended with movzx even if we use only the lower byte part for the subtraction, then is sign extended to 32bits.

The result code could be:

image

If someone is ok to guide me through this kind of JIT optimization, I'd happily implement it.

category:cq
theme:codegen
skill-level:intermediate
cost:medium
impact:medium

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions