summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2023-08-26 10:47:54 -0400
committerMatt Arsenault <Matthew.Arsenault@amd.com>2023-09-01 08:22:16 -0400
commitdeefda7074398b7e8b7dae9dace43a8c694a49c1 (patch)
tree02246428cfb4aa9e6955eb7c412f39e7627465a1 /llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
parentdac8f974b51b076773ec49603df4e627f4d9089c (diff)
AMDGPU: Use exp2 and log2 intrinsics directly for f16/f32
These codegen correctly but f64 doesn't. This prevents losing fast math flags on the way to the underlying intrinsic. https://reviews.llvm.org/D158997
Diffstat (limited to 'llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp')
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
index 0fb1474f8012..285768ff28a1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
@@ -969,12 +969,19 @@ bool AMDGPULibCalls::fold_pow(FPMathOperator *FPOp, IRBuilder<> &B,
return true;
}
+ // If we should use the generic intrinsic instead of emitting a libcall
+ const bool ShouldUseIntrinsic = eltType->isFloatTy() || eltType->isHalfTy();
+
// powr ---> exp2(y * log2(x))
// pown/pow ---> powr(fabs(x), y) | (x & ((int)y << 31))
- FunctionCallee ExpExpr =
- getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_EXP2, FInfo));
- if (!ExpExpr)
- return false;
+ FunctionCallee ExpExpr;
+ if (ShouldUseIntrinsic)
+ ExpExpr = Intrinsic::getDeclaration(M, Intrinsic::exp2, {FPOp->getType()});
+ else {
+ ExpExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_EXP2, FInfo));
+ if (!ExpExpr)
+ return false;
+ }
bool needlog = false;
bool needabs = false;
@@ -1043,10 +1050,16 @@ bool AMDGPULibCalls::fold_pow(FPMathOperator *FPOp, IRBuilder<> &B,
nval = cnval ? cnval : opr0;
}
if (needlog) {
- FunctionCallee LogExpr =
- getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_LOG2, FInfo));
- if (!LogExpr)
- return false;
+ FunctionCallee LogExpr;
+ if (ShouldUseIntrinsic) {
+ LogExpr =
+ Intrinsic::getDeclaration(M, Intrinsic::log2, {FPOp->getType()});
+ } else {
+ LogExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_LOG2, FInfo));
+ if (!LogExpr)
+ return false;
+ }
+
nval = CreateCallEx(B,LogExpr, nval, "__log2");
}