Skip to content

Inefficient codegen with struct consisting of 2 SIMD vectors. #83749

Closed

Description

@MichalPetryka

Description

CoreCLR emits inefficient codegen when working with structs consisting of 2 SIMD vectors, for example custom structs with 2xVector128 or Vector512 on platforms without AVX512.

If you compare the codegen for methods A and B in the reproduction, you can notice the JIT spilling the custom structs instead of promoting them in B. The goal here would be to have B emit the same codegen as A does.
If you look at Memmove there, you'll notice that the JIT does not spill them, but introduces a lot of redundant adds and leas in the codegen.

Reproduction

Configuration

Windows x64 .Net 8 preview 2

Regression?

Probably not, checked just stack spilling and it occurs on .Net 7

Activity

  1. ghost added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Mar 21, 2023
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Mar 21, 2023
  3. jakobbotsch commented on Mar 30, 2023

    @jakobbotsch
    Member

    The problem is here:

    #ifdef FEATURE_SIMD
    // Check to see if this is a SIMD type.
    // We will only check this if we have already found a SIMD type, which will be true if
    // we have encountered any SIMD intrinsics.
    if (compiler->usesSIMDTypes() && (fieldInfo.fldSize == 0) && compiler->isSIMDorHWSIMDClass(fieldInfo.fldTypeHnd))
    {
    unsigned simdSize;
    CorInfoType simdBaseJitType = compiler->getBaseJitTypeAndSizeOfSIMDType(fieldInfo.fldTypeHnd, &simdSize);
    // We will only promote fields of SIMD types that fit into a SIMD register.
    if (simdBaseJitType != CORINFO_TYPE_UNDEF)
    {
    if ((simdSize >= compiler->minSIMDStructBytes()) && (simdSize <= compiler->maxSIMDStructBytes()))
    {
    fieldInfo.fldType = compiler->getSIMDTypeForSize(simdSize);
    fieldInfo.fldSize = simdSize;
    }
    }
    }
    #endif // FEATURE_SIMD

    Since B uses no SIMD intrinsics the JIT assumes the fields of Vector2x128 are not SIMD types and we end up skipping promotion due to that.

  4. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Mar 30, 2023
  5. removed
    untriagedNew issue has not been triaged by the area owner
    on Apr 4, 2023
  6. added this to the 8.0.0 milestone on Apr 4, 2023
  7. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jun 1, 2023
  8. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jun 6, 2023
  9. added
    Priority:2Work that is important, but not critical for the release
    on Jun 20, 2023
  10. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 5, 2023
  11. ghost locked as resolved and limited conversation to collaborators on Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:2Work that is important, but not critical for the releasearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions