Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
MichalPetryka opened this issue Mar 21, 2023 · 2 comments · Fixed by #84122
Closed

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

MichalPetryka opened this issue Mar 21, 2023 · 2 comments · Fixed by #84122
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI Priority:2 Work that is important, but not critical for the release tenet-performance Performance related issue
Milestone

Comments

@MichalPetryka
Copy link
Contributor

MichalPetryka commented Mar 21, 2023

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

@MichalPetryka MichalPetryka added the tenet-performance Performance related issue label Mar 21, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 21, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 21, 2023
@ghost
Copy link

ghost commented Mar 21, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak
See info in area-owners.md if you want to be subscribed.

Issue Details

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.
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

Author: MichalPetryka
Assignees: -
Labels:

tenet-performance, area-CodeGen-coreclr, untriaged

Milestone: -

@jakobbotsch
Copy link
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.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 30, 2023
@JulieLeeMSFT JulieLeeMSFT removed the untriaged New issue has not been triaged by the area owner label Apr 4, 2023
@JulieLeeMSFT JulieLeeMSFT added this to the 8.0.0 milestone Apr 4, 2023
@ghost ghost added in-pr There is an active PR which will close this issue when it is merged and removed in-pr There is an active PR which will close this issue when it is merged labels Jun 1, 2023
@jakobbotsch jakobbotsch added the Priority:2 Work that is important, but not critical for the release label Jun 20, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 5, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 5, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI Priority:2 Work that is important, but not critical for the release tenet-performance Performance related issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants