Skip to content

JIT Optimization: Merge multiple inc into one add #65025

Closed
@deeprobin

Description

@deeprobin

https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBLANgHwAEAmARgFgAoQgZgAIS6BhOgbyrs4fuwDsM6AQQAUfAQEMAlGw5c54gNQKA3LLmdFKtesIB2OuNWU5AX23badMXQBCo/gentj6jXQUBeOsSOvOeg18uM0oTIA

The codegen of B is better (less cpu cycles).

    public int A(int a) {
        a++; // inc edx
        a++; // inc edx
        return a;
    }
    
    public int B(int a) {
        a += 2; // add edx, 2
        return a;
    }

Expected result

- inc edx
- inc edx
+ add edx, 2
  mov eax, edx
  ret

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions