[X86] Don't set exception mask bits when modifying FPCW to change rounding mode for...
authorCraig Topper <craig.topper@intel.com>
Fri, 15 Feb 2019 21:59:33 +0000 (21:59 +0000)
committerCraig Topper <craig.topper@intel.com>
Fri, 15 Feb 2019 21:59:33 +0000 (21:59 +0000)
commitdb2f084aa9dc062f95c9d630be9acfa7b8394b35
treee84896e61d77c9e7952ee268ac3e4ef737f8711f
parent1c29801615427fe07927f1179ee017e2351c09e0
[X86] Don't set exception mask bits when modifying FPCW to change rounding mode for fp->int conversion

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 two stack temporaries instead of one. 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)

Differential Revision: https://reviews.llvm.org/D57788

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