Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Struct promotion should promote 32-byte SIMD on 16-byte alignment #12623

Open
CarolEidt opened this issue May 3, 2019 · 6 comments
Open

Struct promotion should promote 32-byte SIMD on 16-byte alignment #12623

CarolEidt opened this issue May 3, 2019 · 6 comments
Assignees
Labels
arch-x64 arch-x86 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI enhancement Product code improvement that does NOT require public API changes/additions tenet-performance Performance related issue
Milestone

Comments

@CarolEidt
Copy link
Contributor

CarolEidt commented May 3, 2019

This code in Compiler::StructPromotionHelper:

        if ((fieldInfo.fldOffset % fieldInfo.fldSize) != 0)
        {
            // The code in Compiler::genPushArgList that reconstitutes
            // struct values on the stack from promoted fields expects
            // those fields to be at their natural alignment.
            return false;
        }

Won't allow promotion of a TYP_SIMD32 field unless it's on a 32-byte-aligned offset. However, since the stack is not 32-byte aligned this is not a useful condition.
This should probably either use genTypeAlignments[] or perhaps the minimum of the type size and STACK_ALIGN.

category:cq
theme:structs
skill-level:beginner
cost:small
impact:small

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@CarolEidt CarolEidt modified the milestones: Future, 6.0.0 Oct 17, 2020
@JulieLeeMSFT JulieLeeMSFT added the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Mar 23, 2021
@JulieLeeMSFT JulieLeeMSFT removed the needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration label Jun 7, 2021
@sandreenko sandreenko modified the milestones: 6.0.0, 7.0.0 Jul 19, 2021
@anthonycanino
Copy link
Contributor

Hi @sandreenko , can you provide a little clarification on this issue if you know the details? I spent some time this morning trying to reproduce a situation where a TYP_SIMD32 field wouldn't get promoted per the code snippet above, but since struct fields are aligned based on the size of the largest field, I can't seem get something like...

public struct Simd32
{
  public Vector128<int> V0;
  public Vector256<int> V1;
  public Vector128<int> V2;
  // ...
}
  
[MethodImpl(MethodImplOptions.NoInlining)]
public static int RunSimd32Stack()
{
  Simd32 s = new Simd32();
  if (s.V0.GetElement(0) < s.V1.GetElement(0))
  {
    return s.V0.GetElement(0) + s.V1.GetElement(0);
  }
  else
  {
    return s.V1.GetElement(0) + s.V2.GetElement(0);
  }
}

to not promote the fields V0, V1, and V2, unless I preference the struct with [StructLayout(LayoutKind.Sequential, Pack=16)].

Moreover, it looks like the function mentioned in the comment above Compiler::genPushArgList is not in the codebase any longer (unless it has been renamed or I have missed it with grep).

@anthonycanino
Copy link
Contributor

Hi @JulieLeeMSFT , do you know if anyone can help me investigate/understand this issue?

@JulieLeeMSFT
Copy link
Member

Adding @kunalspathak if he has a quick answer.

Hi @JulieLeeMSFT , do you know if anyone can help me investigate/understand this issue?

@sandreenko
Copy link
Contributor

the code from the header is here:

if ((fieldInfo.fldOffset % fieldInfo.fldSize) != 0)

to not promote the fields V0, V1, and V2, unless I preference the struct with [StructLayout(LayoutKind.Sequential, Pack=16)].

it is what I did to repro it.

@kunalspathak
Copy link
Member

I don't know much about this issue at the top of my head. I will have to spend some time in understanding the surrounding feature logic and I don't think I will get time for at least next few weeks.

@anthonycanino
Copy link
Contributor

@kunalspathak ok, please let me know if you do plan to investigate and I will be happy to help dig further as well.

@kunalspathak kunalspathak modified the milestones: 7.0.0, Future Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-x64 arch-x86 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI enhancement Product code improvement that does NOT require public API changes/additions tenet-performance Performance related issue
Projects
None yet
Development

No branches or pull requests

6 participants