aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2006-12-12 22:19:28 +0000
committerEvan Cheng <evan.cheng@apple.com>2006-12-12 22:19:28 +0000
commit279101eb1ac61e2d5b83d5bdcc5be56e710d2cd7 (patch)
treef2ab380612533207f63e9f4ad763f219274dec00
parentdff33ef8e863241193463fd0129657c5ebce4d58 (diff)
Expand FP constant to integers if FP types are not legal.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32497 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/SelectionDAG/LegalizeDAG.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index 481aad66aa..2079259a5f 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -488,10 +488,10 @@ void SelectionDAGLegalize::HandleOp(SDOperand Op) {
}
}
-/// 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 @@ static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, SelectionDAG &DAG,
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 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
}
// FALLTHROUGH
case TargetLowering::Expand:
- Result = ExpandConstantFP(CFP, DAG, TLI);
+ Result = ExpandConstantFP(CFP, true, DAG, TLI);
}
break;
}
@@ -4405,8 +4412,7 @@ void SelectionDAGLegalize::ExpandOp(SDOperand Op, SDOperand &Lo, SDOperand &Hi){
}
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: