diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 79f90bae1d8d6..b576f4d82201e 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2481,6 +2481,11 @@ Align SelectionDAG::getReducedAlign(EVT VT, bool UseABI) { Align RedAlign2 = UseABI ? DL.getABITypeAlign(Ty) : DL.getPrefTypeAlign(Ty); if (RedAlign2 < RedAlign) RedAlign = RedAlign2; + + if (!getMachineFunction().getFrameInfo().isStackRealignable()) + // If the stack is not realignable, the alignment should be limited to the + // StackAlignment + RedAlign = std::min(RedAlign, StackAlign); } return RedAlign; diff --git a/llvm/test/CodeGen/X86/unaligned_extract_from_vector_through_stack.ll b/llvm/test/CodeGen/X86/unaligned_extract_from_vector_through_stack.ll index 52d0c2b509128..629f44b52bc05 100644 --- a/llvm/test/CodeGen/X86/unaligned_extract_from_vector_through_stack.ll +++ b/llvm/test/CodeGen/X86/unaligned_extract_from_vector_through_stack.ll @@ -17,4 +17,22 @@ entry: ret i32 %b } +define i32 @foo2(i32 %arg1) #1 { +; CHECK-LABEL: foo2: +; CHECK: # %bb.0: # %entry +; CHECK-NEXT: # kill: def $edi killed $edi def $rdi +; CHECK-NEXT: vxorps %xmm0, %xmm0, %xmm0 +; CHECK-NEXT: vmovups %ymm0, -{{[0-9]+}}(%rsp) +; CHECK-NEXT: vmovups %ymm0, -{{[0-9]+}}(%rsp) +; CHECK-NEXT: andl $31, %edi +; CHECK-NEXT: movzwl -72(%rsp,%rdi,2), %eax +; CHECK-NEXT: vzeroupper +; CHECK-NEXT: retq +entry: + %a = extractelement <32 x i16> zeroinitializer, i32 %arg1 + %b = zext i16 %a to i32 + ret i32 %b +} + attributes #0 = { "no-realign-stack" "target-cpu"="skylake-avx512" } +attributes #1 = { "no-realign-stack" "target-cpu"="skylake" }