summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorEvandro Menezes <e.menezes@samsung.com>2019-09-12 21:23:22 +0000
committerEvandro Menezes <e.menezes@samsung.com>2019-09-12 21:23:22 +0000
commit08df6e64d5700d9469358ecfa4bdb46073116529 (patch)
tree4f418a0c6795345932cb2553a2fc9218fb44ea60 /llvm/lib
parent75e963ec6fae4ba36bae3c6712614847f8221754 (diff)
downloadbcm5719-llvm-08df6e64d5700d9469358ecfa4bdb46073116529.tar.gz
bcm5719-llvm-08df6e64d5700d9469358ecfa4bdb46073116529.zip
[ConstantFolding] Expand folding of some library functions
Expanding the folding of `nearbyint()`, `rint()` and `trunc()` to library functions, in addition to the current support for intrinsics. Differential revision: https://reviews.llvm.org/D67468 llvm-svn: 371774
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 9c926167ca0..7b3d8157780 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1491,17 +1491,21 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
case 'l':
return Name == "log" || Name == "logf" ||
Name == "log10" || Name == "log10f";
+ case 'n':
+ return Name == "nearbyint" || Name == "nearbyintf";
case 'p':
return Name == "pow" || Name == "powf";
case 'r':
- return Name == "round" || Name == "roundf";
+ return Name == "rint" || Name == "rintf" ||
+ Name == "round" || Name == "roundf";
case 's':
return Name == "sin" || Name == "sinf" ||
Name == "sinh" || Name == "sinhf" ||
Name == "sqrt" || Name == "sqrtf";
case 't':
return Name == "tan" || Name == "tanf" ||
- Name == "tanh" || Name == "tanhf";
+ Name == "tanh" || Name == "tanhf" ||
+ Name == "trunc" || Name == "truncf";
case '_':
// Check for various function names that get used for the math functions
// when the header files are preprocessed with the macro
@@ -1863,7 +1867,6 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
break;
case LibFunc_log:
case LibFunc_logf:
-
case LibFunc_log_finite:
case LibFunc_logf_finite:
if (V > 0.0 && TLI->has(Func))
@@ -1877,6 +1880,15 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
// TODO: What about hosts that lack a C99 library?
return ConstantFoldFP(log10, V, Ty);
break;
+ case LibFunc_nearbyint:
+ case LibFunc_nearbyintf:
+ case LibFunc_rint:
+ case LibFunc_rintf:
+ if (TLI->has(Func)) {
+ U.roundToIntegral(APFloat::rmNearestTiesToEven);
+ return ConstantFP::get(Ty->getContext(), U);
+ }
+ break;
case LibFunc_round:
case LibFunc_roundf:
if (TLI->has(Func)) {
@@ -1911,6 +1923,13 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
if (TLI->has(Func))
return ConstantFoldFP(tanh, V, Ty);
break;
+ case LibFunc_trunc:
+ case LibFunc_truncf:
+ if (TLI->has(Func)) {
+ U.roundToIntegral(APFloat::rmTowardZero);
+ return ConstantFP::get(Ty->getContext(), U);
+ }
+ break;
}
return nullptr;
}
OpenPOWER on IntegriCloud