Skip to content

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

Closed

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.

Activity

  1. added
    tenet-performance
    area-CodeGen-coreclr
    on May 7, 2022
  2. ghost added
    untriaged
    on May 7, 2022
  3. added
    help wanted
    on May 9, 2022
  4. removed
    untriaged
    on May 14, 2022
  5. added this to the Future milestone on May 14, 2022
  6. EgorBo commented on Jun 9, 2022

    @EgorBo
    Member

    Closed via #69600

  7. ghost locked as resolved and limited conversation to collaborators on Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrhelp wantedtenet-performance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions