[PATCH] D141074: [X86] Avoid converting 64-bit integers to floating point using x87 on Windows

icedrocket via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 19:34:12 PST 2023


icedrocket updated this revision to Diff 487649.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141074/new/

https://reviews.llvm.org/D141074

Files:
  llvm/lib/Target/X86/X86ISelLowering.cpp


Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -21368,6 +21368,10 @@
   if (VT == MVT::f128 || !Subtarget.hasX87())
     return SDValue();
 
+  // On Windows, the default precision control on x87 is only 53-bit.
+  if (SrcVT == MVT::i64 && UseSSEReg && Subtarget.isOSWindows())
+    return SDValue();
+
   SDValue ValueToStore = Src;
   if (SrcVT == MVT::i64 && Subtarget.hasSSE2() && !Subtarget.is64Bit())
     // Bitcasting to f64 here allows us to do a single 64-bit store from
@@ -21824,7 +21828,9 @@
   if (SDValue Extract = vectorizeExtractedCast(Op, DAG, Subtarget))
     return Extract;
 
-  if (Subtarget.hasAVX512() && isScalarFPTypeInSSEReg(DstVT) &&
+  bool UseSSEReg = isScalarFPTypeInSSEReg(DstVT);
+
+  if (Subtarget.hasAVX512() && UseSSEReg &&
       (SrcVT == MVT::i32 || (SrcVT == MVT::i64 && Subtarget.is64Bit()))) {
     // Conversions from unsigned i32 to f32/f64 are legal,
     // using VCVTUSI2SS/SD.  Same for i64 in 64-bit mode.
@@ -21859,6 +21865,9 @@
       (DstVT == MVT::f32 || DstVT == MVT::f64))
     return SDValue();
 
+  if (!Subtarget.hasX87())
+    return SDValue();
+
   // Make a 64-bit buffer, and use it to build an FILD.
   SDValue StackSlot = DAG.CreateStackTemporary(MVT::i64, 8);
   int SSFI = cast<FrameIndexSDNode>(StackSlot)->getIndex();
@@ -21880,6 +21889,11 @@
   }
 
   assert(SrcVT == MVT::i64 && "Unexpected type in UINT_TO_FP");
+
+  // On Windows, the default precision control on x87 is only 53-bit.
+  if (UseSSEReg && Subtarget.isOSWindows())
+    return SDValue();
+
   SDValue ValueToStore = Src;
   if (isScalarFPTypeInSSEReg(Op.getValueType()) && !Subtarget.is64Bit()) {
     // Bitcasting to f64 here allows us to do a single 64-bit store from


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141074.487649.patch
Type: text/x-patch
Size: 1866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230110/7b642d14/attachment.bin>


More information about the llvm-commits mailing list