From ef12057737229452c17983faa20857dba441ef05 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Tue, 4 Mar 2008 08:05:30 +0000 Subject: [PATCH] Refactor ExpandConstantFP so it can optimize load from constpool of types larger than f64 into extload from smaller types. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47883 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 35 +++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 0dc4447343f..4686753a3ae 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -488,34 +488,37 @@ static SDOperand ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, // 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(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(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); } -- 2.34.1