[X86] Add intrinsics for reading and writing to the flags register
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 1 Jan 2016 06:50:01 +0000 (06:50 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 1 Jan 2016 06:50:01 +0000 (06:50 +0000)
commit19d1ebc725d69dd55a9113fdba1e529553a17e96
treecc706a104c7ec180189c31b6416f033c98a55b72
parente193ff319c736fa0eaeefb8a6dfc900545324faa
[X86] Add intrinsics for reading and writing to the flags register

LLVM's targets need to know if stack pointer adjustments occur after the
prologue.  This is needed to correctly determine if the red-zone is
appropriate to use or if a frame pointer is required.

Normally, LLVM can figure this out very precisely by reasoning about the
contents of the MachineFunction.  There is an interesting corner case:
inline assembly.

The vast majority of inline assembly which will perform a push or pop is
done so to pair up with pushf or popf as appropriate.  Unfortunately,
this inline assembly doesn't mark the stack pointer as clobbered
because, well, it isn't.  The stack pointer is decremented and then
immediately incremented.  Because of this, LLVM was changed in r256456
to conservatively assume that inline assembly contain a sequence of
stack operations.  This is unfortunate because the vast majority of
inline assembly will not end up manipulating the stack pointer in any
way at all.

Instead, let's provide a more principled solution: an intrinsic.
FWIW, other compilers (MSVC and GCC among them) also provide this
functionality as an intrinsic.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256685 91177308-0d34-0410-b5e6-96231b3b80d8
12 files changed:
include/llvm/IR/IntrinsicsX86.td
lib/Target/X86/X86FrameLowering.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86InstrInfo.td
test/CodeGen/X86/2009-06-03-Win64SpillXMM.ll
test/CodeGen/X86/inline-sse.ll
test/CodeGen/X86/pr11415.ll
test/CodeGen/X86/win64_frame.ll
test/CodeGen/X86/x86-64-flags-intrinsics.ll [new file with mode: 0644]
test/CodeGen/X86/x86-flags-intrinsics.ll [new file with mode: 0644]
test/CodeGen/X86/x86-win64-shrink-wrapping.ll
test/DebugInfo/COFF/asm.ll