llvm.org GIT mirror llvm / ac6cece
It is pointless to turn a UINT_TO_FP into an SINT_TO_FP libcall plus additional operations: it might as well be a direct UINT_TO_FP libcall. So only turn it into an SINT_TO_FP if the target has special handling for SINT_TO_FP. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53461 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 12 years ago
4 changed file(s) with 130 addition(s) and 83 deletion(s). Raw diff Collapse all Expand all
136136 SINTTOFP_I128_PPCF128,
137137 UINTTOFP_I32_F32,
138138 UINTTOFP_I32_F64,
139 UINTTOFP_I32_F80,
140 UINTTOFP_I32_PPCF128,
139141 UINTTOFP_I64_F32,
140142 UINTTOFP_I64_F64,
143 UINTTOFP_I64_F80,
144 UINTTOFP_I64_PPCF128,
145 UINTTOFP_I128_F32,
146 UINTTOFP_I128_F64,
147 UINTTOFP_I128_F80,
148 UINTTOFP_I128_PPCF128,
141149
142150 // COMPARISON
143151 OEQ_F32,
17261726
17271727 case ISD::TRUNCATE: Res = ExpandIntOp_TRUNCATE(N); break;
17281728
1729 case ISD::SINT_TO_FP:
1730 Res = ExpandIntOp_SINT_TO_FP(N->getOperand(0), N->getValueType(0));
1731 break;
1732 case ISD::UINT_TO_FP:
1733 Res = ExpandIntOp_UINT_TO_FP(N->getOperand(0), N->getValueType(0));
1734 break;
1729 case ISD::SINT_TO_FP: Res = ExpandIntOp_SINT_TO_FP(N); break;
1730 case ISD::UINT_TO_FP: Res = ExpandIntOp_UINT_TO_FP(N); break;
17351731
17361732 case ISD::BR_CC: Res = ExpandIntOp_BR_CC(N); break;
17371733 case ISD::SELECT_CC: Res = ExpandIntOp_SELECT_CC(N); break;
17691765 return DAG.getNode(ISD::TRUNCATE, N->getValueType(0), InL);
17701766 }
17711767
1772 SDOperand DAGTypeLegalizer::ExpandIntOp_SINT_TO_FP(SDOperand Source,
1773 MVT DestTy) {
1774 // We know the destination is legal, but that the input needs to be expanded.
1775 MVT SourceVT = Source.getValueType();
1776
1777 // Check to see if the target has a custom way to lower this. If so, use it.
1778 // This can trigger when called from ExpandIntOp_UINT_TO_FP.
1779 switch (TLI.getOperationAction(ISD::SINT_TO_FP, SourceVT)) {
1780 default: assert(0 && "This action not implemented for this operation!");
1781 case TargetLowering::Legal:
1782 case TargetLowering::Expand:
1783 break; // This case is handled below.
1784 case TargetLowering::Custom:
1785 SDOperand NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy,
1786 Source), DAG);
1787 if (NV.Val) return NV;
1788 break; // The target lowered this.
1789 }
1768 SDOperand DAGTypeLegalizer::ExpandIntOp_SINT_TO_FP(SDNode *N) {
1769 SDOperand Op = N->getOperand(0);
1770 MVT SrcVT = Op.getValueType();
1771 MVT DstVT = N->getValueType(0);
17901772
17911773 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
1792 if (SourceVT == MVT::i32) {
1793 if (DestTy == MVT::f32)
1774 if (SrcVT == MVT::i32) {
1775 if (DstVT == MVT::f32)
17941776 LC = RTLIB::SINTTOFP_I32_F32;
1795 else if (DestTy == MVT::f64)
1777 else if (DstVT == MVT::f64)
17961778 LC = RTLIB::SINTTOFP_I32_F64;
1797 else if (DestTy == MVT::f80)
1779 else if (DstVT == MVT::f80)
17981780 LC = RTLIB::SINTTOFP_I32_F80;
1799 else if (DestTy == MVT::ppcf128)
1781 else if (DstVT == MVT::ppcf128)
18001782 LC = RTLIB::SINTTOFP_I32_PPCF128;
1801 } else if (SourceVT == MVT::i64) {
1802 if (DestTy == MVT::f32)
1783 } else if (SrcVT == MVT::i64) {
1784 if (DstVT == MVT::f32)
18031785 LC = RTLIB::SINTTOFP_I64_F32;
1804 else if (DestTy == MVT::f64)
1786 else if (DstVT == MVT::f64)
18051787 LC = RTLIB::SINTTOFP_I64_F64;
1806 else if (DestTy == MVT::f80)
1788 else if (DstVT == MVT::f80)
18071789 LC = RTLIB::SINTTOFP_I64_F80;
1808 else if (DestTy == MVT::ppcf128)
1790 else if (DstVT == MVT::ppcf128)
18091791 LC = RTLIB::SINTTOFP_I64_PPCF128;
1810 } else if (SourceVT == MVT::i128) {
1811 if (DestTy == MVT::f32)
1792 } else if (SrcVT == MVT::i128) {
1793 if (DstVT == MVT::f32)
18121794 LC = RTLIB::SINTTOFP_I128_F32;
1813 else if (DestTy == MVT::f64)
1795 else if (DstVT == MVT::f64)
18141796 LC = RTLIB::SINTTOFP_I128_F64;
1815 else if (DestTy == MVT::f80)
1797 else if (DstVT == MVT::f80)
18161798 LC = RTLIB::SINTTOFP_I128_F80;
1817 else if (DestTy == MVT::ppcf128)
1799 else if (DstVT == MVT::ppcf128)
18181800 LC = RTLIB::SINTTOFP_I128_PPCF128;
18191801 }
18201802 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
18211803 "Don't know how to expand this SINT_TO_FP!");
18221804
1823 return MakeLibCall(LC, DestTy, &Source, 1, true);
1824 }
1825
1826 SDOperand DAGTypeLegalizer::ExpandIntOp_UINT_TO_FP(SDOperand Source,
1827 MVT DestTy) {
1828 // We know the destination is legal, but that the input needs to be expanded.
1829 assert(getTypeAction(Source.getValueType()) == ExpandInteger &&
1830 "This is not an expansion!");
1831
1832 // If this is unsigned, and not supported, first perform the conversion to
1833 // signed, then adjust the result if the sign bit is set.
1834 SDOperand SignedConv = ExpandIntOp_SINT_TO_FP(Source, DestTy);
1835
1836 // The 64-bit value loaded will be incorrectly if the 'sign bit' of the
1837 // incoming integer is set. To handle this, we dynamically test to see if
1838 // it is set, and, if so, add a fudge factor.
1839 SDOperand Lo, Hi;
1840 GetExpandedInteger(Source, Lo, Hi);
1841
1842 SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultType(Hi), Hi,
1843 DAG.getConstant(0, Hi.getValueType()),
1844 ISD::SETLT);
1845 SDOperand Zero = DAG.getIntPtrConstant(0), Four = DAG.getIntPtrConstant(4);
1846 SDOperand CstOffset = DAG.getNode(ISD::SELECT, Zero.getValueType(),
1847 SignSet, Four, Zero);
1848 uint64_t FF = 0x5f800000ULL;
1849 if (TLI.isLittleEndian()) FF <<= 32;
1850 Constant *FudgeFactor = ConstantInt::get((Type*)Type::Int64Ty, FF);
1851
1852 SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
1853 CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset);
1854 SDOperand FudgeInReg;
1855 if (DestTy == MVT::f32)
1856 FudgeInReg = DAG.getLoad(MVT::f32, DAG.getEntryNode(), CPIdx, NULL, 0);
1857 else if (DestTy.bitsGT(MVT::f32))
1858 // FIXME: Avoid the extend by construction the right constantpool?
1859 FudgeInReg = DAG.getExtLoad(ISD::EXTLOAD, DestTy, DAG.getEntryNode(),
1860 CPIdx, NULL, 0, MVT::f32);
1861 else
1862 assert(0 && "Unexpected conversion");
1863
1864 return DAG.getNode(ISD::FADD, DestTy, SignedConv, FudgeInReg);
1805 return MakeLibCall(LC, DstVT, &Op, 1, true);
1806 }
1807
1808 SDOperand DAGTypeLegalizer::ExpandIntOp_UINT_TO_FP(SDNode *N) {
1809 SDOperand Op = N->getOperand(0);
1810 MVT SrcVT = Op.getValueType();
1811 MVT DstVT = N->getValueType(0);
1812
1813 if (TLI.getOperationAction(ISD::SINT_TO_FP, SrcVT) == TargetLowering::Custom){
1814 // Do a signed conversion then adjust the result.
1815 SDOperand SignedConv = DAG.getNode(ISD::SINT_TO_FP, DstVT, Op);
1816 SignedConv = TLI.LowerOperation(SignedConv, DAG);
1817
1818 // The result of the signed conversion needs adjusting if the 'sign bit' of
1819 // the incoming integer was set. To handle this, we dynamically test to see
1820 // if it is set, and, if so, add a fudge factor.
1821
1822 const uint64_t F32TwoE32 = 0x4F800000ULL;
1823 const uint64_t F32TwoE64 = 0x5F800000ULL;
1824 const uint64_t F32TwoE128 = 0x7F800000ULL;
1825
1826 APInt FF(32, 0);
1827 if (SrcVT == MVT::i32)
1828 FF = APInt(32, F32TwoE32);
1829 else if (SrcVT == MVT::i64)
1830 FF = APInt(32, F32TwoE64);
1831 else if (SrcVT == MVT::i128)
1832 FF = APInt(32, F32TwoE128);
1833 else
1834 assert(false && "Unsupported UINT_TO_FP!");
1835
1836 // Check whether the sign bit is set.
1837 SDOperand Lo, Hi;
1838 GetExpandedInteger(Op, Lo, Hi);
1839 SDOperand SignSet = DAG.getSetCC(TLI.getSetCCResultType(Hi), Hi,
1840 DAG.getConstant(0, Hi.getValueType()),
1841 ISD::SETLT);
1842
1843 // Build a 64 bit pair (0, FF) in the constant pool, with FF in the lo bits.
1844 SDOperand FudgePtr = DAG.getConstantPool(ConstantInt::get(FF.zext(64)),
1845 TLI.getPointerTy());
1846
1847 // Get a pointer to FF if the sign bit was set, or to 0 otherwise.
1848 SDOperand Zero = DAG.getIntPtrConstant(0);
1849 SDOperand Four = DAG.getIntPtrConstant(4);
1850 if (TLI.isBigEndian()) std::swap(Zero, Four);
1851 SDOperand Offset = DAG.getNode(ISD::SELECT, Zero.getValueType(), SignSet,
1852 Zero, Four);
1853 FudgePtr = DAG.getNode(ISD::ADD, TLI.getPointerTy(), FudgePtr, Offset);
1854
1855 // Load the value out, extending it from f32 to the destination float type.
1856 // FIXME: Avoid the extend by constructing the right constant pool?
1857 SDOperand Fudge = DAG.getExtLoad(ISD::EXTLOAD, DstVT, DAG.getEntryNode(),
1858 FudgePtr, NULL, 0, MVT::f32);
1859 return DAG.getNode(ISD::FADD, DstVT, SignedConv, Fudge);
1860 }
1861
1862 // Otherwise, use a libcall.
1863 RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
1864 if (SrcVT == MVT::i32) {
1865 if (DstVT == MVT::f32)
1866 LC = RTLIB::UINTTOFP_I32_F32;
1867 else if (DstVT == MVT::f64)
1868 LC = RTLIB::UINTTOFP_I32_F64;
1869 else if (DstVT == MVT::f80)
1870 LC = RTLIB::UINTTOFP_I32_F80;
1871 else if (DstVT == MVT::ppcf128)
1872 LC = RTLIB::UINTTOFP_I32_PPCF128;
1873 } else if (SrcVT == MVT::i64) {
1874 if (DstVT == MVT::f32)
1875 LC = RTLIB::UINTTOFP_I64_F32;
1876 else if (DstVT == MVT::f64)
1877 LC = RTLIB::UINTTOFP_I64_F64;
1878 else if (DstVT == MVT::f80)
1879 LC = RTLIB::UINTTOFP_I64_F80;
1880 else if (DstVT == MVT::ppcf128)
1881 LC = RTLIB::UINTTOFP_I64_PPCF128;
1882 } else if (SrcVT == MVT::i128) {
1883 if (DstVT == MVT::f32)
1884 LC = RTLIB::UINTTOFP_I128_F32;
1885 else if (DstVT == MVT::f64)
1886 LC = RTLIB::UINTTOFP_I128_F64;
1887 else if (DstVT == MVT::f80)
1888 LC = RTLIB::UINTTOFP_I128_F80;
1889 else if (DstVT == MVT::ppcf128)
1890 LC = RTLIB::UINTTOFP_I128_PPCF128;
1891 }
1892 assert(LC != RTLIB::UNKNOWN_LIBCALL &&
1893 "Don't know how to expand this UINT_TO_FP!");
1894
1895 return MakeLibCall(LC, DstVT, &Op, 1, true);
18651896 }
18661897
18671898 SDOperand DAGTypeLegalizer::ExpandIntOp_BR_CC(SDNode *N) {
298298 SDOperand ExpandIntOp_EXTRACT_ELEMENT(SDNode *N);
299299 SDOperand ExpandIntOp_SELECT_CC(SDNode *N);
300300 SDOperand ExpandIntOp_SETCC(SDNode *N);
301 SDOperand ExpandIntOp_SINT_TO_FP(SDOperand Source, MVT DestTy);
301 SDOperand ExpandIntOp_SINT_TO_FP(SDNode *N);
302302 SDOperand ExpandIntOp_STORE(StoreSDNode *N, unsigned OpNo);
303303 SDOperand ExpandIntOp_TRUNCATE(SDNode *N);
304 SDOperand ExpandIntOp_UINT_TO_FP(SDOperand Source, MVT DestTy);
304 SDOperand ExpandIntOp_UINT_TO_FP(SDNode *N);
305305
306306 void IntegerExpandSetCCOperands(SDOperand &NewLHS, SDOperand &NewRHS,
307307 ISD::CondCode &CCCode);
134134 Names[RTLIB::SINTTOFP_I128_PPCF128] = "__floattitf";
135135 Names[RTLIB::UINTTOFP_I32_F32] = "__floatunsisf";
136136 Names[RTLIB::UINTTOFP_I32_F64] = "__floatunsidf";
137 Names[RTLIB::UINTTOFP_I32_F80] = "__floatunsixf";
138 Names[RTLIB::UINTTOFP_I32_PPCF128] = "__floatunsitf";
137139 Names[RTLIB::UINTTOFP_I64_F32] = "__floatundisf";
138140 Names[RTLIB::UINTTOFP_I64_F64] = "__floatundidf";
141 Names[RTLIB::UINTTOFP_I64_F80] = "__floatundixf";
142 Names[RTLIB::UINTTOFP_I64_PPCF128] = "__floatunditf";
143 Names[RTLIB::UINTTOFP_I128_F32] = "__floatuntisf";
144 Names[RTLIB::UINTTOFP_I128_F64] = "__floatuntidf";
145 Names[RTLIB::UINTTOFP_I128_F80] = "__floatuntixf";
146 Names[RTLIB::UINTTOFP_I128_PPCF128] = "__floatuntitf";
139147 Names[RTLIB::OEQ_F32] = "__eqsf2";
140148 Names[RTLIB::OEQ_F64] = "__eqdf2";
141149 Names[RTLIB::UNE_F32] = "__nesf2";