[llvm-commits] [llvm] r47938 - in /llvm/trunk: lib/CodeGen/SelectionDAG/SelectionDAG.cpp test/CodeGen/X86/shrink-fp-const2.ll

Chris Lattner sabre at nondot.org
Tue Mar 4 22:48:14 PST 2008


Author: lattner
Date: Wed Mar  5 00:48:13 2008
New Revision: 47938

URL: http://llvm.org/viewvc/llvm-project?rev=47938&view=rev
Log:
Generalize FP constant shrinking optimization to apply to any vt
except ppc long double.  This allows us to shrink constant pool
entries for x86 long double constants, which in turn allows us to
use flds/fldl instead of fldt.

Added:
    llvm/trunk/test/CodeGen/X86/shrink-fp-const2.ll
Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=47938&r1=47937&r2=47938&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Wed Mar  5 00:48:13 2008
@@ -44,6 +44,17 @@
   return Res;
 }
 
+static const fltSemantics *MVTToAPFloatSemantics(MVT::ValueType VT) {
+  switch (VT) {
+  default: assert(0 && "Unknown FP format");
+  case MVT::f32:     return &APFloat::IEEEsingle;
+  case MVT::f64:     return &APFloat::IEEEdouble;
+  case MVT::f80:     return &APFloat::x87DoubleExtended;
+  case MVT::f128:    return &APFloat::IEEEquad;
+  case MVT::ppcf128: return &APFloat::PPCDoubleDouble;
+  }
+}
+
 SelectionDAG::DAGUpdateListener::~DAGUpdateListener() {}
 
 //===----------------------------------------------------------------------===//
@@ -60,28 +71,20 @@
 
 bool ConstantFPSDNode::isValueValidForType(MVT::ValueType VT, 
                                            const APFloat& Val) {
+  assert(MVT::isFloatingPoint(VT) && "Can only convert between FP types");
+  
+  // Anything can be extended to ppc long double.
+  if (VT == MVT::ppcf128)
+    return true;
+  
+  // PPC long double cannot be shrunk to anything though.
+  if (&Val.getSemantics() == &APFloat::PPCDoubleDouble)
+    return false;
+  
   // convert modifies in place, so make a copy.
   APFloat Val2 = APFloat(Val);
-  switch (VT) {
-  default:
-    return false;         // These can't be represented as floating point!
-
-  // FIXME rounding mode needs to be more flexible
-  case MVT::f32:
-    return &Val2.getSemantics() == &APFloat::IEEEsingle ||
-           Val2.convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven) == 
-              APFloat::opOK;
-  case MVT::f64:
-    return &Val2.getSemantics() == &APFloat::IEEEsingle || 
-           &Val2.getSemantics() == &APFloat::IEEEdouble ||
-           Val2.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven) == 
-             APFloat::opOK;
-  // TODO: Figure out how to test if we can use a shorter type instead!
-  case MVT::f80:
-  case MVT::f128:
-  case MVT::ppcf128:
-    return true;
-  }
+  return Val2.convert(*MVTToAPFloatSemantics(VT),
+                      APFloat::rmNearestTiesToEven) == APFloat::opOK;
 }
 
 //===----------------------------------------------------------------------===//
@@ -1786,12 +1789,8 @@
       case ISD::FP_EXTEND:
         // This can return overflow, underflow, or inexact; we don't care.
         // FIXME need to be more flexible about rounding mode.
-        (void) V.convert(VT==MVT::f32 ? APFloat::IEEEsingle : 
-                         VT==MVT::f64 ? APFloat::IEEEdouble :
-                         VT==MVT::f80 ? APFloat::x87DoubleExtended :
-                         VT==MVT::f128 ? APFloat::IEEEquad :
-                         APFloat::Bogus,
-                         APFloat::rmNearestTiesToEven);
+        (void)V.convert(*MVTToAPFloatSemantics(VT),
+                        APFloat::rmNearestTiesToEven);
         return getConstantFP(V, VT);
       case ISD::FP_TO_SINT:
       case ISD::FP_TO_UINT: {

Added: llvm/trunk/test/CodeGen/X86/shrink-fp-const2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/shrink-fp-const2.ll?rev=47938&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/shrink-fp-const2.ll (added)
+++ llvm/trunk/test/CodeGen/X86/shrink-fp-const2.ll Wed Mar  5 00:48:13 2008
@@ -0,0 +1,7 @@
+; RUN: llvm-as < %s | llc -march=x86 | grep flds
+; This should be a flds, not fldt.
+define x86_fp80 @test2() nounwind  {
+entry:
+	ret x86_fp80 0xK3FFFC000000000000000
+}
+





More information about the llvm-commits mailing list