Skip to content

Perf: JIT does not optimize pattern "~x + 1" #69003

@GrabYourPitchforks

Description

@GrabYourPitchforks

Based on a comment at #68964 (comment).

In main, current JIT compiles this method:

static uint Negate(uint value) => ~value + 1;

To this in release mode:

; Method ConsoleApp106.Program:Negate(int):int
G_M48540_IG01:
						;; size=0 bbWeight=1    PerfScore 0.00

G_M48540_IG02:
       mov      eax, ecx
       not      eax
       inc      eax
						;; size=6 bbWeight=1    PerfScore 0.75

G_M48540_IG03:
       ret      
						;; size=1 bbWeight=1    PerfScore 1.00
; Total bytes of code: 7

JIT should be taught to recognize the pattern ~x + 1 and turn it into a two's-complement neg instruction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIhelp wanted[up-for-grabs] Good issue for external contributorstenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions