Skip to content

Code a little larger when cast omitted that could be inferred #42056

Description

@danmoseley

In this code,

using System;
public class C {
    public bool M1(float f) {
        return (Math.Abs(f) >= 0.5);
    }
    
    public bool M2(float f) {
        return (Math.Abs(f) >= (float)0.5);
    }  
}

ideally the code generated would be the same, as so far as I know the behavior is the same, but the code without the explicit cast is a little longer.

C.M1(Single)
    L0000: vzeroupper
    L0003: vmovss xmm1, [esp+4]
    L0009: vmovss xmm0, [C.M1(Single)]
    L0011: vandps xmm1, xmm1, xmm0
    L0015: vcvtss2sd xmm0, xmm0, xmm1
    L0019: vucomisd xmm0, [C.M1(Single)]
    L0021: setae al
    L0024: movzx eax, al
    L0027: ret 4

C.M2(Single)
    L0000: vzeroupper
    L0003: vmovss xmm1, [esp+4]
    L0009: vmovss xmm0, [C.M2(Single)]
    L0011: vandps xmm1, xmm1, xmm0
    L0015: vucomiss xmm1, [C.M2(Single)]
    L001d: setae al
    L0020: movzx eax, al
    L0023: ret 4

https://sharplab.io/#v2:EYLgtghgzgLgpgJwDQxNMAfAAgJgIwCwAUFgMwAEu5AwuQN7HlOUXAD2bANuQLJ4AUAM05sIMcoICU9RszlYA7OX48xACwB0AQWBQh0gHwBecgAYNAVkkBuWUwC+d8k7Ll2XXjiEixE6QyI5eSUVdW1dfXJjZWFRGElzK1tA5nsmYnsgA===

was mentioned in #41140 (comment)

category:cq
theme:floating-point
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 SuperPMI

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions