[llvm] b329d1b - [AMDGPU][ConstantFolding] Fold llvm.amdgcn.fmul.legacy intrinsic
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 19 08:10:36 PST 2020
Author: Jay Foad
Date: 2020-02-19T16:01:30Z
New Revision: b329d1b06eb2f7781be414002d49eca79b85b726
URL: https://github.com/llvm/llvm-project/commit/b329d1b06eb2f7781be414002d49eca79b85b726
DIFF: https://github.com/llvm/llvm-project/commit/b329d1b06eb2f7781be414002d49eca79b85b726.diff
LOG: [AMDGPU][ConstantFolding] Fold llvm.amdgcn.fmul.legacy intrinsic
Reviewers: arsenm, rampitec, nhaehnle
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, kerbowa, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D74835
Added:
llvm/test/Analysis/ConstantFolding/AMDGPU/fmul_legacy.ll
llvm/test/Analysis/ConstantFolding/AMDGPU/lit.local.cfg
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 059bf9a53275..f3f04a6a2eea 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -39,6 +39,7 @@
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/IntrinsicsAMDGPU.h"
#include "llvm/IR/IntrinsicsX86.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Type.h"
@@ -1458,6 +1459,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
case Intrinsic::convert_from_fp16:
case Intrinsic::convert_to_fp16:
case Intrinsic::bitreverse:
+ case Intrinsic::amdgcn_fmul_legacy:
case Intrinsic::x86_sse_cvtss2si:
case Intrinsic::x86_sse_cvtss2si64:
case Intrinsic::x86_sse_cvttss2si:
@@ -2082,6 +2084,16 @@ static Constant *ConstantFoldScalarCall2(StringRef Name,
return ConstantFP::get(Ty->getContext(), maximum(C1, C2));
}
+ if (IntrinsicID == Intrinsic::amdgcn_fmul_legacy) {
+ const APFloat &C1 = Op1->getValueAPF();
+ const APFloat &C2 = Op2->getValueAPF();
+ // The legacy behaviour is that multiplying zero by anything, even NaN
+ // or infinity, gives +0.0.
+ if (C1.isZero() || C2.isZero())
+ return ConstantFP::getNullValue(Ty);
+ return ConstantFP::get(Ty->getContext(), C1 * C2);
+ }
+
if (!TLI)
return nullptr;
diff --git a/llvm/test/Analysis/ConstantFolding/AMDGPU/fmul_legacy.ll b/llvm/test/Analysis/ConstantFolding/AMDGPU/fmul_legacy.ll
new file mode 100644
index 000000000000..86cfe70ea0b5
--- /dev/null
+++ b/llvm/test/Analysis/ConstantFolding/AMDGPU/fmul_legacy.ll
@@ -0,0 +1,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+declare float @llvm.amdgcn.fmul.legacy(float, float)
+
+define void @test(float* %p) {
+; CHECK-LABEL: @test(
+; CHECK-NEXT: store volatile float 6.000000e+00, float* [[P:%.*]]
+; CHECK-NEXT: store volatile float 0.000000e+00, float* [[P]]
+; CHECK-NEXT: store volatile float 0.000000e+00, float* [[P]]
+; CHECK-NEXT: store volatile float 0.000000e+00, float* [[P]]
+; CHECK-NEXT: store volatile float 0.000000e+00, float* [[P]]
+; CHECK-NEXT: store volatile float 0.000000e+00, float* [[P]]
+; CHECK-NEXT: store volatile float 0.000000e+00, float* [[P]]
+; CHECK-NEXT: store volatile float 0.000000e+00, float* [[P]]
+; CHECK-NEXT: store volatile float 0.000000e+00, float* [[P]]
+; CHECK-NEXT: store volatile float 0.000000e+00, float* [[P]]
+; CHECK-NEXT: store volatile float 0.000000e+00, float* [[P]]
+; CHECK-NEXT: ret void
+;
+ %a = call float @llvm.amdgcn.fmul.legacy(float +2.0, float +3.0)
+ store volatile float %a, float* %p
+ %b = call float @llvm.amdgcn.fmul.legacy(float +2.0, float +0.0)
+ store volatile float %b, float* %p
+ %c = call float @llvm.amdgcn.fmul.legacy(float +2.0, float -0.0)
+ store volatile float %c, float* %p
+ %d = call float @llvm.amdgcn.fmul.legacy(float +0.0, float +0.0)
+ store volatile float %d, float* %p
+ %e = call float @llvm.amdgcn.fmul.legacy(float +0.0, float -0.0)
+ store volatile float %e, float* %p
+ %f = call float @llvm.amdgcn.fmul.legacy(float -0.0, float +0.0)
+ store volatile float %f, float* %p
+ %g = call float @llvm.amdgcn.fmul.legacy(float -0.0, float -0.0)
+ store volatile float %g, float* %p
+ %h = call float @llvm.amdgcn.fmul.legacy(float +0.0, float 0x7ff0000000000000) ; +inf
+ store volatile float %h, float* %p
+ %i = call float @llvm.amdgcn.fmul.legacy(float 0xfff0000000000000, float +0.0) ; -inf
+ store volatile float %i, float* %p
+ %j = call float @llvm.amdgcn.fmul.legacy(float 0x7ff0001000000000, float -0.0) ; +nan
+ store volatile float %j, float* %p
+ %k = call float @llvm.amdgcn.fmul.legacy(float -0.0, float 0xfff0000100000000) ; -nan
+ store volatile float %k, float* %p
+ ret void
+}
diff --git a/llvm/test/Analysis/ConstantFolding/AMDGPU/lit.local.cfg b/llvm/test/Analysis/ConstantFolding/AMDGPU/lit.local.cfg
new file mode 100644
index 000000000000..2a665f06be72
--- /dev/null
+++ b/llvm/test/Analysis/ConstantFolding/AMDGPU/lit.local.cfg
@@ -0,0 +1,2 @@
+if not 'AMDGPU' in config.root.targets:
+ config.unsupported = True
More information about the llvm-commits
mailing list