diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2020-05-21 12:31:28 -0400 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2020-05-22 08:21:38 -0400 |
commit | 88c20fa3d2a25ea1319c78cb1173532511879cfc (patch) | |
tree | a275dbe804f0495a732dc9ddbb4129032c66a336 /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 5a8db275f8fc8ee19b184f831bda1cdfc6771776 (diff) | |
download | llvm-88c20fa3d2a25ea1319c78cb1173532511879cfc.zip llvm-88c20fa3d2a25ea1319c78cb1173532511879cfc.tar.gz llvm-88c20fa3d2a25ea1319c78cb1173532511879cfc.tar.bz2 |
InstCombine: Add constant folding/simplify for amdgcn.ldexp intrinsic
This really belongs in InstructionSimplify since it doesn't introduce
new instructions. Put it in instcombine to avoid increasing the number
of passes considering target intrinsics.
I also noticed that we seem to now be interpreting strictfp attributes
on call sites, so try to handle that.
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index b2bde95..4fdc73c 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1457,6 +1457,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) { case Intrinsic::amdgcn_cubetc: case Intrinsic::amdgcn_fmul_legacy: case Intrinsic::amdgcn_fract: + case Intrinsic::amdgcn_ldexp: case Intrinsic::x86_sse_cvtss2si: case Intrinsic::x86_sse_cvtss2si64: case Intrinsic::x86_sse_cvttss2si: @@ -2224,6 +2225,16 @@ static Constant *ConstantFoldScalarCall2(StringRef Name, return ConstantFP::get(Ty->getContext(), APFloat((double)std::pow((double)Op1V, (int)Op2C->getZExtValue()))); + + if (IntrinsicID == Intrinsic::amdgcn_ldexp) { + // FIXME: Should flush denorms depending on FP mode, but that's ignored + // everywhere else. + + // scalbn is equivalent to ldexp with float radix 2 + APFloat Result = scalbn(Op1->getValueAPF(), Op2C->getSExtValue(), + APFloat::rmNearestTiesToEven); + return ConstantFP::get(Ty->getContext(), Result); + } } return nullptr; } |