diff options
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index c5a2c2f..a96c3be 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -57,6 +57,7 @@ #include <cassert> #include <cerrno> #include <cfenv> +#include <cfloat> #include <cmath> #include <cstdint> @@ -1698,9 +1699,9 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) { Name == "sinh" || Name == "sinhf" || Name == "sqrt" || Name == "sqrtf"; case 't': - return Name == "tan" || Name == "tanf" || - Name == "tanh" || Name == "tanhf" || - Name == "trunc" || Name == "truncf"; + return Name == "tan" || Name == "tanf" || Name == "tanh" || + Name == "tanhf" || Name == "trunc" || Name == "truncf" || + Name == "tgamma" || Name == "tgammaf"; case '_': // Check for various function names that get used for the math functions // when the header files are preprocessed with the macro @@ -2417,6 +2418,14 @@ static Constant *ConstantFoldScalarCall1(StringRef Name, if (TLI->has(Func)) return ConstantFoldFP(erf, APF, Ty); break; + case LibFunc_tgamma: + case LibFunc_tgammaf: + // NOTE: These boundaries are somewhat conservative. + if (TLI->has(Func) && + (Ty->isDoubleTy() && APF > APFloat(DBL_MIN) && APF < APFloat(171.0) || + Ty->isFloatTy() && APF > APFloat(FLT_MIN) && APF < APFloat(35.0f))) + return ConstantFoldFP(tgamma, APF, Ty); + break; case LibFunc_nearbyint: case LibFunc_nearbyintf: case LibFunc_rint: @@ -3629,6 +3638,10 @@ bool llvm::isMathLibCallNoop(const CallBase *Call, case LibFunc_sqrtf: return Op.isNaN() || Op.isZero() || !Op.isNegative(); + case LibFunc_tgamma: + case LibFunc_tgammaf: + return true; + // FIXME: Add more functions: sqrt_finite, atanh, expm1, log1p, // maybe others? default: |