[PATCH] D113335: [X86] Preserve FPSW when popping x87 stack

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 6 01:19:50 PDT 2021


sepavloff created this revision.
sepavloff added reviewers: craig.topper, pengfei, LiuChen3.
Herald added a subscriber: hiraditya.
sepavloff requested review of this revision.
Herald added a project: LLVM.

When compiler converts x87 operations to stack model, it may insert
instructions that pop top stack element. To do it the compiler inserts
instruction FSTP right after the instruction that calculates value on
the stack. It can break the code that uses FPSW set by the last
instruction. For example, an instruction FXAM is usually followed by
FNSTSW, but FSTP is inserted after FXAM. As FSTP leaves condition code
in FPSW undefined, the compiler produces incorrect code.

With this change FSTP in inserted after the FPSW consumer if the last
instruction sets FPSW.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113335

Files:
  llvm/lib/Target/X86/X86FloatingPoint.cpp
  llvm/lib/Target/X86/X86InsertWait.cpp
  llvm/lib/Target/X86/X86InstrFPStack.td
  llvm/lib/Target/X86/X86InstrInfo.h
  llvm/test/CodeGen/X86/x87-stack-pop.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113335.385246.patch
Type: text/x-patch
Size: 6827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211106/6d931075/attachment.bin>


More information about the llvm-commits mailing list