dotnet/runtime

NativeAOT: Run-time simd checking

Open

#68,110 opened on Apr 16, 2022

View on GitHub
 (7 comments) (0 reactions) (0 assignees)C# (5,445 forks)batch import
area-CodeGen-coreclrhelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (Avg merge 12d 11h) (661 merged PRs in 30d)

Description

Run-time simd checks can be beneficial in long-running cases (SpanHelpers.SequenceEqual for example)

Run-time simd checks can hurt performance because of redundant checks...

Could it be fixed? Eg;

void Method(){
    if(Avx2.IsSupported) avx2path();
    else softwarepath();
}
Method();
Method();
Method();

Can be transformed into:

if(Avx2.IsSupported){
    Method_avx2path();
    Method_avx2path();
    Method_avx2path();
} else {
    Method_softwarepath();
    Method_softwarepath();
    Method_softwarepath();
}

This could be done by inlining, but it won't work for the most part...

Compiler somehow should produce an unique codegen for every simd for every subsequent method:

void Start(){
    if(Avx2.IsSupported) ...;
    else ...;
    Continue();
}
void Continue(){
    End()
}
void End(){
    if(Avx2.IsSupported) ...;
    else ...;
}

Will produce

Start_Avx2
Start
Continue_Avx2
Continue
End_Avx2
End

But this unbiased codegeneration will cause dramatic size increase. Could PGO be possibly used to know where checks are actually useful?

category:cq theme:ready-to-run skill-level:expert cost:medium impact:small

Contributor guide