summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2023-08-12 13:51:49 -0400
committerMatt Arsenault <Matthew.Arsenault@amd.com>2023-08-14 18:28:21 -0400
commitc7876c55acc14983a50bf2865ed87e7bb4bd4209 (patch)
treea26b835ac076c1b8f0321872832eed3aae24db04 /llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
parent19f2b68095fe727e40079b7c6380b36b6462e691 (diff)
AMDGPU: Replace fabs and copysign libcalls with intrinsics
Preserves flags and metadata like the other cases.
Diffstat (limited to 'llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp')
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
index 3372200edd1e..1ca4559f1008 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
@@ -103,12 +103,14 @@ private:
/// AllowMinSize is true, allow the replacement in a minsize function.
bool shouldReplaceLibcallWithIntrinsic(const CallInst *CI,
bool AllowMinSizeF32 = false,
- bool AllowF64 = false);
+ bool AllowF64 = false,
+ bool AllowStrictFP = false);
void replaceLibCallWithSimpleIntrinsic(CallInst *CI, Intrinsic::ID IntrID);
bool tryReplaceLibcallWithSimpleIntrinsic(CallInst *CI, Intrinsic::ID IntrID,
bool AllowMinSizeF32 = false,
- bool AllowF64 = false);
+ bool AllowF64 = false,
+ bool AllowStrictFP = false);
protected:
bool isUnsafeMath(const FPMathOperator *FPOp) const;
@@ -583,8 +585,8 @@ bool AMDGPULibCalls::fold(CallInst *CI) {
// Specialized optimizations for each function call.
//
- // TODO: Handle other simple intrinsic wrappers. Sqrt, copysign, fabs,
- // ldexp, log, rounding intrinsics.
+ // TODO: Handle other simple intrinsic wrappers. Sqrt, ldexp, log, rounding
+ // intrinsics.
//
// TODO: Handle native functions
switch (FInfo.getId()) {
@@ -610,6 +612,12 @@ bool AMDGPULibCalls::fold(CallInst *CI) {
case AMDGPULibFunc::EI_MAD:
return tryReplaceLibcallWithSimpleIntrinsic(CI, Intrinsic::fmuladd, true,
true);
+ case AMDGPULibFunc::EI_FABS:
+ return tryReplaceLibcallWithSimpleIntrinsic(CI, Intrinsic::fabs, true,
+ true, true);
+ case AMDGPULibFunc::EI_COPYSIGN:
+ return tryReplaceLibcallWithSimpleIntrinsic(CI, Intrinsic::copysign, true,
+ true, true);
case AMDGPULibFunc::EI_POW:
case AMDGPULibFunc::EI_POWR:
case AMDGPULibFunc::EI_POWN:
@@ -1066,7 +1074,8 @@ FunctionCallee AMDGPULibCalls::getNativeFunction(Module *M,
// substituting them with direct calls with all the flags.
bool AMDGPULibCalls::shouldReplaceLibcallWithIntrinsic(const CallInst *CI,
bool AllowMinSizeF32,
- bool AllowF64) {
+ bool AllowF64,
+ bool AllowStrictFP) {
Type *FltTy = CI->getType()->getScalarType();
const bool IsF32 = FltTy->isFloatTy();
@@ -1081,7 +1090,7 @@ bool AMDGPULibCalls::shouldReplaceLibcallWithIntrinsic(const CallInst *CI,
const Function *ParentF = CI->getFunction();
// TODO: Handle strictfp
- if (ParentF->hasFnAttribute(Attribute::StrictFP))
+ if (!AllowStrictFP && ParentF->hasFnAttribute(Attribute::StrictFP))
return false;
if (IsF32 && !AllowMinSizeF32 && ParentF->hasMinSize())
@@ -1098,8 +1107,10 @@ void AMDGPULibCalls::replaceLibCallWithSimpleIntrinsic(CallInst *CI,
bool AMDGPULibCalls::tryReplaceLibcallWithSimpleIntrinsic(CallInst *CI,
Intrinsic::ID IntrID,
bool AllowMinSizeF32,
- bool AllowF64) {
- if (!shouldReplaceLibcallWithIntrinsic(CI, AllowMinSizeF32, AllowF64))
+ bool AllowF64,
+ bool AllowStrictFP) {
+ if (!shouldReplaceLibcallWithIntrinsic(CI, AllowMinSizeF32, AllowF64,
+ AllowStrictFP))
return false;
replaceLibCallWithSimpleIntrinsic(CI, IntrID);
return true;