[llvm] b87e3e2 - AMDGPU: Don't create potentially dead rcp declarations
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 11 15:11:47 PST 2020
Author: Matt Arsenault
Date: 2020-02-11T18:11:39-05:00
New Revision: b87e3e2d0db8b0eb7a8f26525dad74cc7014b85f
URL: https://github.com/llvm/llvm-project/commit/b87e3e2d0db8b0eb7a8f26525dad74cc7014b85f
DIFF: https://github.com/llvm/llvm-project/commit/b87e3e2d0db8b0eb7a8f26525dad74cc7014b85f.diff
LOG: AMDGPU: Don't create potentially dead rcp declarations
This will introduce unused declarations if this doesn't reach any of
the paths that will really use it.
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
index e3cc2a4abdee..e6499afcd7a3 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
@@ -620,10 +620,12 @@ static Value *optimizeWithRcp(Value *Num, Value *Den, bool AllowInaccurateRcp,
return nullptr;
Type *Ty = Den->getType();
- Function *Decl = Intrinsic::getDeclaration(Mod, Intrinsic::amdgcn_rcp, Ty);
if (const ConstantFP *CLHS = dyn_cast<ConstantFP>(Num)) {
if (AllowInaccurateRcp || RcpIsAccurate) {
if (CLHS->isExactlyValue(1.0)) {
+ Function *Decl = Intrinsic::getDeclaration(
+ Mod, Intrinsic::amdgcn_rcp, Ty);
+
// v_rcp_f32 and v_rsq_f32 do not support denormals, and according to
// the CI documentation has a worst case error of 1 ulp.
// OpenCL requires <= 2.5 ulp for 1.0 / x, so it should always be OK to
@@ -636,10 +638,13 @@ static Value *optimizeWithRcp(Value *Num, Value *Den, bool AllowInaccurateRcp,
// 1.0 / x -> rcp(x)
return Builder.CreateCall(Decl, { Den });
- }
+ }
// Same as for 1.0, but expand the sign out of the constant.
- if (CLHS->isExactlyValue(-1.0)) {
+ if (CLHS->isExactlyValue(-1.0)) {
+ Function *Decl = Intrinsic::getDeclaration(
+ Mod, Intrinsic::amdgcn_rcp, Ty);
+
// -1.0 / x -> rcp (fneg x)
Value *FNeg = Builder.CreateFNeg(Den);
return Builder.CreateCall(Decl, { FNeg });
@@ -648,6 +653,9 @@ static Value *optimizeWithRcp(Value *Num, Value *Den, bool AllowInaccurateRcp,
}
if (AllowInaccurateRcp) {
+ Function *Decl = Intrinsic::getDeclaration(
+ Mod, Intrinsic::amdgcn_rcp, Ty);
+
// Turn into multiply by the reciprocal.
// x / y -> x * (1.0 / y)
Value *Recip = Builder.CreateCall(Decl, { Den });
More information about the llvm-commits
mailing list