@@ -1718,40 +1718,37 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
1718
1718
if (!Ty->isHalfTy () && !Ty->isFloatTy () && !Ty->isDoubleTy ())
1719
1719
return nullptr ;
1720
1720
1721
- if (IntrinsicID == Intrinsic::round) {
1722
- APFloat V = Op->getValueAPF ();
1723
- V.roundToIntegral (APFloat::rmNearestTiesToAway);
1724
- return ConstantFP::get (Ty->getContext (), V);
1721
+ // Use internal versions of these intrinsics.
1722
+ APFloat U = Op->getValueAPF ();
1723
+
1724
+ if (IntrinsicID == Intrinsic::nearbyint || IntrinsicID == Intrinsic::rint) {
1725
+ U.roundToIntegral (APFloat::rmNearestTiesToEven);
1726
+ return ConstantFP::get (Ty->getContext (), U);
1725
1727
}
1726
1728
1727
- if (IntrinsicID == Intrinsic::floor) {
1728
- APFloat V = Op->getValueAPF ();
1729
- V.roundToIntegral (APFloat::rmTowardNegative);
1730
- return ConstantFP::get (Ty->getContext (), V);
1729
+ if (IntrinsicID == Intrinsic::round) {
1730
+ U.roundToIntegral (APFloat::rmNearestTiesToAway);
1731
+ return ConstantFP::get (Ty->getContext (), U);
1731
1732
}
1732
1733
1733
1734
if (IntrinsicID == Intrinsic::ceil) {
1734
- APFloat V = Op->getValueAPF ();
1735
- V.roundToIntegral (APFloat::rmTowardPositive);
1736
- return ConstantFP::get (Ty->getContext (), V);
1735
+ U.roundToIntegral (APFloat::rmTowardPositive);
1736
+ return ConstantFP::get (Ty->getContext (), U);
1737
1737
}
1738
1738
1739
- if (IntrinsicID == Intrinsic::trunc) {
1740
- APFloat V = Op->getValueAPF ();
1741
- V.roundToIntegral (APFloat::rmTowardZero);
1742
- return ConstantFP::get (Ty->getContext (), V);
1739
+ if (IntrinsicID == Intrinsic::floor) {
1740
+ U.roundToIntegral (APFloat::rmTowardNegative);
1741
+ return ConstantFP::get (Ty->getContext (), U);
1743
1742
}
1744
1743
1745
- if (IntrinsicID == Intrinsic::rint) {
1746
- APFloat V = Op->getValueAPF ();
1747
- V.roundToIntegral (APFloat::rmNearestTiesToEven);
1748
- return ConstantFP::get (Ty->getContext (), V);
1744
+ if (IntrinsicID == Intrinsic::trunc) {
1745
+ U.roundToIntegral (APFloat::rmTowardZero);
1746
+ return ConstantFP::get (Ty->getContext (), U);
1749
1747
}
1750
1748
1751
- if (IntrinsicID == Intrinsic::nearbyint) {
1752
- APFloat V = Op->getValueAPF ();
1753
- V.roundToIntegral (APFloat::rmNearestTiesToEven);
1754
- return ConstantFP::get (Ty->getContext (), V);
1749
+ if (IntrinsicID == Intrinsic::fabs) {
1750
+ U.clearSign ();
1751
+ return ConstantFP::get (Ty->getContext (), U);
1755
1752
}
1756
1753
1757
1754
// / We only fold functions with finite arguments. Folding NaN and inf is
@@ -1768,8 +1765,6 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
1768
1765
1769
1766
switch (IntrinsicID) {
1770
1767
default : break ;
1771
- case Intrinsic::fabs:
1772
- return ConstantFoldFP (fabs, V, Ty);
1773
1768
case Intrinsic::log:
1774
1769
return ConstantFoldFP (log, V, Ty);
1775
1770
case Intrinsic::log2:
@@ -1796,7 +1791,6 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
1796
1791
1797
1792
LibFunc Func = NotLibFunc;
1798
1793
TLI->getLibFunc (Name, Func);
1799
-
1800
1794
switch (Func) {
1801
1795
default :
1802
1796
break ;
@@ -1821,8 +1815,10 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
1821
1815
break ;
1822
1816
case LibFunc_ceil:
1823
1817
case LibFunc_ceilf:
1824
- if (TLI->has (Func))
1825
- return ConstantFoldFP (ceil, V, Ty);
1818
+ if (TLI->has (Func)) {
1819
+ U.roundToIntegral (APFloat::rmTowardPositive);
1820
+ return ConstantFP::get (Ty->getContext (), U);
1821
+ }
1826
1822
break ;
1827
1823
case LibFunc_cos:
1828
1824
case LibFunc_cosf:
@@ -1853,16 +1849,21 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
1853
1849
break ;
1854
1850
case LibFunc_fabs:
1855
1851
case LibFunc_fabsf:
1856
- if (TLI->has (Func))
1857
- return ConstantFoldFP (fabs, V, Ty);
1852
+ if (TLI->has (Func)) {
1853
+ U.clearSign ();
1854
+ return ConstantFP::get (Ty->getContext (), U);
1855
+ }
1858
1856
break ;
1859
1857
case LibFunc_floor:
1860
1858
case LibFunc_floorf:
1861
- if (TLI->has (Func))
1862
- return ConstantFoldFP (floor, V, Ty);
1859
+ if (TLI->has (Func)) {
1860
+ U.roundToIntegral (APFloat::rmTowardNegative);
1861
+ return ConstantFP::get (Ty->getContext (), U);
1862
+ }
1863
1863
break ;
1864
1864
case LibFunc_log:
1865
1865
case LibFunc_logf:
1866
+
1866
1867
case LibFunc_log_finite:
1867
1868
case LibFunc_logf_finite:
1868
1869
if (V > 0.0 && TLI->has (Func))
@@ -1878,8 +1879,10 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
1878
1879
break ;
1879
1880
case LibFunc_round:
1880
1881
case LibFunc_roundf:
1881
- if (TLI->has (Func))
1882
- return ConstantFoldFP (round, V, Ty);
1882
+ if (TLI->has (Func)) {
1883
+ U.roundToIntegral (APFloat::rmNearestTiesToAway);
1884
+ return ConstantFP::get (Ty->getContext (), U);
1885
+ }
1883
1886
break ;
1884
1887
case LibFunc_sin:
1885
1888
case LibFunc_sinf:
@@ -2040,9 +2043,11 @@ static Constant *ConstantFoldScalarCall2(StringRef Name,
2040
2043
break ;
2041
2044
case LibFunc_fmod:
2042
2045
case LibFunc_fmodf:
2043
- if (TLI->has (Func))
2044
- // TODO: What about hosts that lack a C99 library?
2045
- return ConstantFoldBinaryFP (fmod, Op1V, Op2V, Ty);
2046
+ if (TLI->has (Func)) {
2047
+ APFloat V = Op1->getValueAPF ();
2048
+ if (APFloat::opStatus::opOK == V.mod (Op2->getValueAPF ()))
2049
+ return ConstantFP::get (Ty->getContext (), V);
2050
+ }
2046
2051
break ;
2047
2052
case LibFunc_atan2:
2048
2053
case LibFunc_atan2f:
0 commit comments