[PATCH] D57788: [X86] Don't set exception mask bits when modifying FPCW to change rounding mode for fp->int conversion

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 5 14:01:08 PST 2019


craig.topper created this revision.
craig.topper added reviewers: andrew.w.kaylor, efriedma, RKSimon, spatel.
Herald added a subscriber: eraman.

When we need to do an fp->int conversion using x87 instructions, we need to temporarily change the rounding mode to 0b11 and perform a store. To do this we save the old value of the fpcw to the stack, then set the fpcw to 0xc7f, do the store, then restore fpcw. But the 0xc7f value forces the exception mask bits 1. While this is what they would be in the default FP environment, as we move to support changing the FP environments, we shouldn't make this assumption.

This patch changes the code to explicitly OR 0xc00 with the old value so that only the rounding mode is changed. Unfortunately, this requires an additional stack temporaries one to hold the old value and one to hold the new value. Without two stack temporaries we would need an additional GPR. We already need one to do the OR operation in. This is similar to what gcc and icc do for this operation. Though they are both better at reusing the stack temporaries when there are multiple truncates in a function(or at least in a basic block)


https://reviews.llvm.org/D57788

Files:
  lib/Target/X86/X86ISelLowering.cpp
  test/CodeGen/X86/bswap_tree2.ll
  test/CodeGen/X86/fp-cvt.ll
  test/CodeGen/X86/inline-asm-fpstack.ll
  test/CodeGen/X86/pr34080-2.ll
  test/CodeGen/X86/pr34080.ll
  test/CodeGen/X86/pr40529.ll
  test/CodeGen/X86/scalar-fp-to-i64.ll
  test/CodeGen/X86/trunc-to-bool.ll
  test/CodeGen/X86/vec_fp_to_int-widen.ll
  test/CodeGen/X86/vec_fp_to_int.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57788.185395.patch
Type: text/x-patch
Size: 52674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190205/577f5fb3/attachment.bin>


More information about the llvm-commits mailing list