dotnet/runtime

F# typeof comparison suboptimal codegen

Open

#82 394 ouverte le 20 févr. 2023

Voir sur GitHub
 (13 commentaires) (1 réaction) (0 assignés)C# (5 445 forks)batch import
area-CodeGen-coreclrhelp wanted

Métriques du dépôt

Stars
 (17 886 stars)
Métriques de merge PR
 (Merge moyen 12j 11h) (661 PRs mergées en 30 j)

Description

The following F# snippet:

let test() = typeof<float> = typeof<bool>

Emits this IL:

ldtoken !!a
call class [netstandard]System.Type [netstandard]System.Type::GetTypeFromHandle(valuetype [netstandard]System.RuntimeTypeHandle)
ldtoken [System.Runtime]System.Boolean
call class [netstandard]System.Type [netstandard]System.Type::GetTypeFromHandle(valuetype [netstandard]System.RuntimeTypeHandle)
tail.
call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityIntrinsic<class [System.Runtime]System.Type>(!!0, !!0)
ret

and this codegen:

_.test()
    L0000: push rsi
    L0001: sub rsp, 0x20
    L0005: mov rcx, 0x7ff9f93c77a8
    L000f: call 0x00007ffa58e77670
    L0014: mov rsi, rax
    L0017: mov rcx, 0x7ff9f934b3c0
    L0021: call 0x00007ffa58e77670
    L0026: mov r8, rax
    L0029: mov rdx, rsi
    L002c: mov rcx, 0x7ff9febc1e88
    L0036: mov rax, 0x7ff9feb43be8
    L0040: add rsp, 0x20
    L0044: pop rsi
    L0045: jmp qword ptr [rax]

expected codegen:

_.test()
    L0000: xor eax, eax
    L0002: ret

Guide contributeur