Skip to content

SelectionDAG: 32 byte aligned store to 16 byte aligned stack generated for no-realign-stack functions #77730

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

Closed
Nirhar opened this issue Jan 11, 2024 · 5 comments · Fixed by #78422
Assignees
Labels
llvm:SelectionDAG SelectionDAGISel as well

Comments

@Nirhar
Copy link
Contributor

Nirhar commented Jan 11, 2024

Example IR:

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
target triple = "x86_64-unknown-linux-gnu"

define i32 @foo(i32 %arg1) #0 {
entry:
  %a = extractelement <32 x i8> zeroinitializer, i32 %arg1
  %b = zext i8 %a to i32
  ret i32 %b
}

attributes #0 = { "no-realign-stack" "target-cpu"="skylake-avx512" }

And here is the corresponding Assembly :

foo:                                    # @foo
        vxorps  %xmm0, %xmm0, %xmm0
        vmovaps %ymm0, -40(%rsp)
        andl    $31, %edi
        movzbl  -40(%rsp,%rdi), %eax
        vzeroupper
        retq

with the stack slot generated:

Frame Objects:
  fi#0: size=32, align=16, at location [SP+8]

Here is the link to the same example on godbolt: Link

The vmovaps instruction can generate a fault for this example.

@Nirhar
Copy link
Contributor Author

Nirhar commented Jan 11, 2024

Perhaps replacing vmovaps with vmovups is a viable solution.

@llvmbot
Copy link
Member

llvmbot commented Jan 11, 2024

@llvm/issue-subscribers-backend-x86

Author: Manish Kausik H (Nirhar)

Example IR: ``` target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2" target triple = "x86_64-unknown-linux-gnu"

define i32 @foo(i32 %arg1) #0 {
bci_0:
%a = extractelement <32 x i8> zeroinitializer, i32 %arg1
%b = zext i8 %a to i32
ret i32 %b
}

attributes #0 = { "no-realign-stack" "target-cpu"="skylake-avx512" }

And here is the corresponding Assembly :

foo: # @foo
vxorps %xmm0, %xmm0, %xmm0
vmovaps %ymm0, -40(%rsp)
andl $31, %edi
movzbl -40(%rsp,%rdi), %eax
vzeroupper
retq

with the stack slot generated:

Frame Objects:
fi#0: size=32, align=16, at location [SP+8]


Here is the link to the same example on godbolt: [Link](https://godbolt.org/z/cYqcPMrYT)

The `vmovaps` instruction can generate a fault for this example.
</details>

@RKSimon
Copy link
Collaborator

RKSimon commented Jan 11, 2024

SelectionDAGLegalize::ExpandExtractFromVectorThroughStack doesn't look to be setting a suitable alignment, so gets the default for the type

@KanRobert
Copy link
Contributor

cc @HaohaiWen

@danilaml
Copy link
Collaborator

@RKSimon probably needs a fix similar to 511be2a

Nirhar added a commit to Nirhar/llvm-project that referenced this issue Jan 18, 2024
…or `extractelement`

Prior to this patch, SelectionDAG generated aligned move onto stacks for AVX registers
when the function was marked as a no-realign-stack function. This lead to misalignment
between the stack and the instruction generated. This patch fixes the issue.

Fixes llvm#77730
Nirhar added a commit to Nirhar/llvm-project that referenced this issue Jan 22, 2024
…or `extractelement`

Prior to this patch, SelectionDAG generated aligned move onto stacks for AVX registers
when the function was marked as a no-realign-stack function. This lead to misalignment
between the stack and the instruction generated. This patch fixes the issue.

Fixes llvm#77730
Nirhar added a commit to Nirhar/llvm-project that referenced this issue Jan 23, 2024
…or `extractelement`

Prior to this patch, SelectionDAG generated aligned move onto stacks for AVX registers
when the function was marked as a no-realign-stack function. This lead to misalignment
between the stack and the instruction generated. This patch fixes the issue.

Fixes llvm#77730
Nirhar added a commit to Nirhar/llvm-project that referenced this issue Jan 25, 2024
…or `extractelement`

Prior to this patch, SelectionDAG generated aligned move onto stacks for AVX registers
when the function was marked as a no-realign-stack function. This lead to misalignment
between the stack and the instruction generated. This patch fixes the issue.

Fixes llvm#77730
Nirhar added a commit to Nirhar/llvm-project that referenced this issue Jan 28, 2024
…or `extractelement`

Prior to this patch, SelectionDAG generated aligned move onto stacks for AVX registers
when the function was marked as a no-realign-stack function. This lead to misalignment
between the stack and the instruction generated. This patch fixes the issue.

Fixes llvm#77730
Nirhar added a commit to Nirhar/llvm-project that referenced this issue Feb 2, 2024
…or `extractelement`

Prior to this patch, SelectionDAG generated aligned move onto stacks for AVX registers
when the function was marked as a no-realign-stack function. This lead to misalignment
between the stack and the instruction generated. This patch fixes the issue.

Fixes llvm#77730
Nirhar added a commit to Nirhar/llvm-project that referenced this issue Feb 2, 2024
…or `extractelement`

Prior to this patch, SelectionDAG generated aligned move onto stacks for AVX registers
when the function was marked as a no-realign-stack function. This lead to misalignment
between the stack and the instruction generated. This patch fixes the issue.

Fixes llvm#77730
arsenm pushed a commit that referenced this issue Feb 2, 2024
…or `extractelement` (#78422)

Prior to this patch, SelectionDAG generated aligned move onto stacks for
AVX registers when the function was marked as a no-realign-stack
function. This lead to misalignment between the stack and the
instruction generated. This patch fixes the issue.

Fixes #77730
agozillon pushed a commit to agozillon/llvm-project that referenced this issue Feb 5, 2024
…or `extractelement` (llvm#78422)

Prior to this patch, SelectionDAG generated aligned move onto stacks for
AVX registers when the function was marked as a no-realign-stack
function. This lead to misalignment between the stack and the
instruction generated. This patch fixes the issue.

Fixes llvm#77730
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
6 participants