diff options
| author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2023-08-25 07:58:51 -0400 |
|---|---|---|
| committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2023-09-01 08:22:16 -0400 |
| commit | a45b787c91af623add62f4f927f51fb782a2dee6 (patch) | |
| tree | 92517070d3d5008ff92e02e57273832aebe5f25f /llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp | |
| parent | f5d8a9b1bbf2b9894c653a5807753d268e13fc11 (diff) | |
AMDGPU: Turn pow libcalls into powr
powr is just pow with the assumption that x >= 0, otherwise nan. This
fires at least 6 times in luxmark
https://reviews.llvm.org/D158908
Diffstat (limited to 'llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp')
| -rw-r--r-- | llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp index 6a85a06a0b6f..f5e9b09ccaf7 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp @@ -14,6 +14,7 @@ #include "AMDGPU.h" #include "AMDGPULibFunc.h" #include "GCNSubtarget.h" +#include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/IntrinsicsAMDGPU.h" @@ -694,7 +695,21 @@ bool AMDGPULibCalls::fold(CallInst *CI) { {CI->getType(), CI->getArgOperand(1)->getType()})); return true; } - case AMDGPULibFunc::EI_POW: + case AMDGPULibFunc::EI_POW: { + Module *M = Callee->getParent(); + AMDGPULibFunc PowrInfo(AMDGPULibFunc::EI_POWR, FInfo); + FunctionCallee PowrFunc = getFunction(M, PowrInfo); + + // pow(x, y) -> powr(x, y) for x >= -0.0 + // TODO: Pass all arguments to cannotBeOrderedLessThanZero + if (PowrFunc && cannotBeOrderedLessThanZero(FPOp->getOperand(0), + M->getDataLayout())) { + cast<CallInst>(FPOp)->setCalledFunction(PowrFunc); + return fold_pow(FPOp, B, PowrInfo) || true; + } + + return fold_pow(FPOp, B, FInfo); + } case AMDGPULibFunc::EI_POWR: case AMDGPULibFunc::EI_POWN: return fold_pow(FPOp, B, FInfo); |
