[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Evan Cheng evan.cheng at apple.com
Tue Dec 12 14:19:43 PST 2006



Changes in directory llvm/lib/CodeGen/SelectionDAG:

LegalizeDAG.cpp updated: 1.435 -> 1.436
---
Log message:

Expand FP constant to integers if FP types are not legal.

---
Diffs of the changes:  (+13 -7)

 LegalizeDAG.cpp |   20 +++++++++++++-------
 1 files changed, 13 insertions(+), 7 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.435 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.436
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.435	Tue Dec 12 15:51:17 2006
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp	Tue Dec 12 16:19:28 2006
@@ -488,10 +488,10 @@
   }
 }
 
-/// ExpandConstantFP - Expands the ConstantFP node by spilling the constant to
-/// memory.
-static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, SelectionDAG &DAG,
-                                  TargetLowering &TLI) {
+/// ExpandConstantFP - Expands the ConstantFP node by either converting it to
+/// integer constant or spilling the constant to memory.
+static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool ToMem,
+                                  SelectionDAG &DAG, TargetLowering &TLI) {
   bool Extend = false;
 
   // If a FP immediate is precise when represented as a float and if the
@@ -502,6 +502,13 @@
   bool isDouble = VT == MVT::f64;
   ConstantFP *LLVMC = ConstantFP::get(isDouble ? Type::DoubleTy :
                                       Type::FloatTy, CFP->getValue());
+  if (!ToMem) {
+    double Val = LLVMC->getValue();
+    return isDouble
+      ? DAG.getConstant(DoubleToBits(Val), MVT::i64)
+      : DAG.getConstant(FloatToBits(Val), MVT::i32);
+  }
+
   if (isDouble && CFP->isExactlyValue((float)CFP->getValue()) &&
       // Only do this if the target has a native EXTLOAD instruction from f32.
       TLI.isLoadXLegal(ISD::EXTLOAD, MVT::f32)) {
@@ -806,7 +813,7 @@
       }
       // FALLTHROUGH
     case TargetLowering::Expand:
-      Result = ExpandConstantFP(CFP, DAG, TLI);
+      Result = ExpandConstantFP(CFP, true, DAG, TLI);
     }
     break;
   }
@@ -4405,8 +4412,7 @@
   }
   case ISD::ConstantFP: {
     ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Node);
-    SDOperand Tmp = ExpandConstantFP(CFP, DAG, TLI);
-    ExpandOp(Tmp, Lo, Hi);
+    Lo = ExpandConstantFP(CFP, false, DAG, TLI);
     break;
   }
   case ISD::BUILD_PAIR:






More information about the llvm-commits mailing list