Skip to content

Commit 0d4798d

Browse files
author
Manish Kausik H
committed
[SelectionDAG] Use unaligned store to legalize EXTRACT_VECTOR_ELT type when Stack is non-realignable
This patch sets the alignment of store instructions generated during type legalization of extractelement instruction, after considering stack alignment, if the stack is not realignable. Fixes #98044
1 parent 5c2bdc5 commit 0d4798d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,6 +2481,11 @@ Align SelectionDAG::getReducedAlign(EVT VT, bool UseABI) {
24812481
Align RedAlign2 = UseABI ? DL.getABITypeAlign(Ty) : DL.getPrefTypeAlign(Ty);
24822482
if (RedAlign2 < RedAlign)
24832483
RedAlign = RedAlign2;
2484+
2485+
if (!getMachineFunction().getFrameInfo().isStackRealignable())
2486+
// If the stack is not realignable, the alignment should be limited to the
2487+
// StackAlignment
2488+
RedAlign = std::min(RedAlign, StackAlign);
24842489
}
24852490

24862491
return RedAlign;

llvm/test/CodeGen/X86/unaligned_extract_from_vector_through_stack.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,22 @@ entry:
1717
ret i32 %b
1818
}
1919

20+
define i32 @foo2(i32 %arg1) #1 {
21+
; CHECK-LABEL: foo2:
22+
; CHECK: # %bb.0: # %entry
23+
; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
24+
; CHECK-NEXT: vxorps %xmm0, %xmm0, %xmm0
25+
; CHECK-NEXT: vmovups %ymm0, -{{[0-9]+}}(%rsp)
26+
; CHECK-NEXT: vmovups %ymm0, -{{[0-9]+}}(%rsp)
27+
; CHECK-NEXT: andl $31, %edi
28+
; CHECK-NEXT: movzwl -72(%rsp,%rdi,2), %eax
29+
; CHECK-NEXT: vzeroupper
30+
; CHECK-NEXT: retq
31+
entry:
32+
%a = extractelement <32 x i16> zeroinitializer, i32 %arg1
33+
%b = zext i16 %a to i32
34+
ret i32 %b
35+
}
36+
2037
attributes #0 = { "no-realign-stack" "target-cpu"="skylake-avx512" }
38+
attributes #1 = { "no-realign-stack" "target-cpu"="skylake" }

0 commit comments

Comments
 (0)