[X86] Align stack to 16-bytes on 32-bit with X86_INTR call convention
authorAntonio Abbatangelo <contact@antangelo.com>
Thu, 1 Jun 2023 08:18:12 +0000 (16:18 +0800)
committerPhoebe Wang <phoebe.wang@intel.com>
Thu, 1 Jun 2023 09:00:34 +0000 (17:00 +0800)
commitb7e110fcfe22a1f887507dbaa6fdb001630e223d
treeff08c894f475367c67823c6156a6af83c44c9bb3
parent710749f78695b0e00026e5ff7c9f94e08e7b482a
[X86] Align stack to 16-bytes on 32-bit with X86_INTR call convention

Adds a dynamic stack alignment to functions under the interrupt call
convention on x86-32. This fixes the issue where the stack can be
misaligned on entry, since x86-32 makes no guarantees about the stack
pointer position when the interrupt service routine is called.

The alignment is done by overriding X86RegisterInfo::shouldRealignStack,
and by setting the correct alignment in X86FrameLowering::calculateMaxStackAlign.
This forces the interrupt handler to be dynamically aligned, generating
the appropriate `and` instruction in the prologue and `lea` in the
epilogue. The `no-realign-stack` attribute can be used as an opt-out.

Fixes #26851

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D151400
llvm/lib/Target/X86/X86FrameLowering.cpp
llvm/lib/Target/X86/X86RegisterInfo.cpp
llvm/lib/Target/X86/X86RegisterInfo.h
llvm/test/CodeGen/X86/x86-32-intrcc.ll
llvm/test/CodeGen/X86/x86-interrupt_cc.ll