[llvm-commits] [llvm] r47883 - /llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
Evan Cheng
evan.cheng at apple.com
Tue Mar 4 00:05:30 PST 2008
Author: evancheng
Date: Tue Mar 4 02:05:30 2008
New Revision: 47883
URL: http://llvm.org/viewvc/llvm-project?rev=47883&view=rev
Log:
Refactor ExpandConstantFP so it can optimize load from constpool of types larger than f64 into extload from smaller types.
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=47883&r1=47882&r2=47883&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Tue Mar 4 02:05:30 2008
@@ -488,34 +488,37 @@
// the constant pool as a float, even if it's is statically typed as a
// double.
MVT::ValueType VT = CFP->getValueType(0);
- bool isDouble = VT == MVT::f64;
ConstantFP *LLVMC = ConstantFP::get(MVT::getTypeForValueType(VT),
CFP->getValueAPF());
if (!UseCP) {
if (VT!=MVT::f64 && VT!=MVT::f32)
assert(0 && "Invalid type expansion");
return DAG.getConstant(LLVMC->getValueAPF().convertToAPInt().getZExtValue(),
- isDouble ? MVT::i64 : MVT::i32);
+ (VT == MVT::f64) ? MVT::i64 : MVT::i32);
}
- if (isDouble && CFP->isValueValidForType(MVT::f32, CFP->getValueAPF()) &&
- // Only do this if the target has a native EXTLOAD instruction from f32.
- // Do not try to be clever about long doubles (so far)
- TLI.isLoadXLegal(ISD::EXTLOAD, MVT::f32)) {
- LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC,Type::FloatTy));
- VT = MVT::f32;
- Extend = true;
+ MVT::ValueType OrigVT = VT;
+ MVT::ValueType SVT = VT;
+ while (SVT != MVT::f32) {
+ SVT = (unsigned)SVT - 1;
+ if (CFP->isValueValidForType(SVT, CFP->getValueAPF()) &&
+ // Only do this if the target has a native EXTLOAD instruction from
+ // smaller type.
+ TLI.isLoadXLegal(ISD::EXTLOAD, SVT)) {
+ const Type *SType = MVT::getTypeForValueType(SVT);
+ LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType));
+ VT = SVT;
+ Extend = true;
+ }
}
SDOperand CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy());
- if (Extend) {
- return DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(),
+ if (Extend)
+ return DAG.getExtLoad(ISD::EXTLOAD, OrigVT, DAG.getEntryNode(),
CPIdx, PseudoSourceValue::getConstantPool(),
- 0, MVT::f32);
- } else {
- return DAG.getLoad(VT, DAG.getEntryNode(), CPIdx,
- PseudoSourceValue::getConstantPool(), 0);
- }
+ 0, VT);
+ return DAG.getLoad(OrigVT, DAG.getEntryNode(), CPIdx,
+ PseudoSourceValue::getConstantPool(), 0);
}
More information about the llvm-commits
mailing list