Skip to content

JIT fails to constant fold multiplies, and/or merge shifts #43551

@AndyAyersMS

Description

@AndyAyersMS
    [MethodImpl(MethodImplOptions.NoInlining)]
    static int Y(int x) => x * 2 * 2;

produces

; Assembly listing for method X:Y(int):int
; Emitting BLENDED_CODE for X64 CPU with AVX - Windows
; optimized code
; rsp based frame
; partially interruptible
; Final local variable assignments
;
;  V00 arg0         [V00,T00] (  3,  3   )     int  ->  rcx
;# V01 OutArgs      [V01    ] (  1,  1   )  lclBlk ( 0) [rsp+0x00]   "OutgoingArgSpace"
;
; Lcl frame size = 0

G_M5754_IG01:              ;; offset=0000H
                                                ;; bbWeight=1    PerfScore 0.00
G_M5754_IG02:              ;; offset=0000H
       8D0409               lea      eax, [rcx+rcx]
       03C0                 add      eax, eax
                                                ;; bbWeight=1    PerfScore 0.75
G_M5754_IG03:              ;; offset=0005H
       C3                   ret
                                                ;; bbWeight=1    PerfScore 1.00

; Total bytes of code 6, prolog size 0, PerfScore 2.35, instruction count 3 (MethodHash=7c40e985) for method X:Y(int):int

Should be simple enough to handle this in morph. Or we could re-associate better.

category:cq
theme:expression-opts
skill-level:intermediate
cost:medium

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 contributors

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions