Skip to content

Double constants usage in a loop can be CSEed #35257

Description

@kunalspathak

Doubles present in a loop are reloaded repeatedly. Instead they can be set just once out of loop and use it inside the loop.

privatestaticdoubleProcess(doublen){doubleres;res=1;while(n>0.0){res*=n;// User might not write such code, but here it is written merely to show that same constants are re-loaded in assembly code.n-=1.0;n-=2.0;n-=1.0;n-=2.0;}returnres;}
G_M15653_IG03: 1E600A10 fmul d16, d16, d0 1E6E1011 fmov d17, #1.0000 1E713800 fsub d0, d0, d17 1E601011 fmov d17, #2.0000 1E713800 fsub d0, d0, d17 1E6E1011 fmov d17, #1.0000 1E713800 fsub d0, d0, d17 1E601011 fmov d17, #2.0000 1E713800 fsub d0, d0, d17 4F00E411 movi v17.16b, #0x00 1E712000 fcmp d0, d17 54FFFEAC bgt G_M15653_IG03

category:cq
theme:cse
skill-level:expert
cost:medium
impact:medium

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions