-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add possibility to lower llvm.fmuladd into mad from OpenCL extinst #824
Add possibility to lower llvm.fmuladd into mad from OpenCL extinst #824
Conversation
lib/SPIRV/SPIRVWriter.cpp
Outdated
@@ -2231,6 +2231,22 @@ SPIRVValue *LLVMToSPIRV::transIntrinsicInst(IntrinsicInst *II, | |||
// For llvm.fmuladd.* fusion is not guaranteed. If a fused multiply-add | |||
// is required the corresponding llvm.fma.* intrinsic function should be | |||
// used instead. | |||
if (!checkTypeForSPIRVExtendedInstLowering(II, BM)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no handling for fmuladd
in checkTypeForSPIRVExtendedInstLowering
, it will always return true
. Should we extend checkTypeForSPIRVExtendedInstLowering
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this is necessary, because llvm.fmuladd.*
is only defined for floating-point scalars, which perfectly matches requirements of fma
extinst. We don't even need to check for vector length, because llvm.fmuladd.*
is not defined for vectors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkTypeForSPIRVExtendedInstLowering
takes II
as a parameter. This function is based on switch
on intrinsic id and there is no case
for Intrinsic::fmuladd
. We either should add case Intrinsic::fmuladd:
, or don't call checkTypeForSPIRVExtendedInstLowering
at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I will remove the call
e0bba94
to
2b65828
Compare
static cl::opt<bool> SPIRVReplaceLLVMFmulAddWithOpenCLMad( | ||
"spirv-replace-fmuladd-with-ocl-mad", | ||
cl::desc("Allow replacement of llvm.fmuladd.* intrinsic with OpenCL mad " | ||
"instruction from OpenCL extended instruction set"), | ||
cl::init(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How likely is it that similar user-requested replacements will be added for other intrinsics? If such plans (or such bits of code) exist already, would a single "joint" option like -spirv-replace-intrinsics-with-ocl-ext
be preferable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How likely is it that similar user-requested replacements will be added for other intrinsics?
This patch is more like a workaround for the lack of fine-grained fp-contraction support in SPIR-V spec, comparing it to OpenCL spec and LLVM IR representation. So, in general I wouldn't expect this to happen often, but still there might be a few more similar situations (right now I can't think of any)
If such plans (or such bits of code) exist already, would a single "joint" option like
-spirv-replace-intrinsics-with-ocl-ext
be preferable?
Since this is more like a workaround and I'm not aware of any similar things I guess it would be better to go with this particular option for fmuladd
@@ -202,6 +202,12 @@ static cl::opt<SPIRV::DebugInfoEIS> DebugEIS( | |||
"extended instruction set. This version of SPIR-V debug " | |||
"info format is compatible with the SPIRV-Tools"))); | |||
|
|||
static cl::opt<bool> SPIRVReplaceLLVMFmulAddWithOpenCLMad( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to make it a bool
-accepting option instead of a simple flag?
(I personally don't think it matters much, but just for the sake of consistency)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to make it a
bool
-accepting option instead of a simple flag?
No particular reason from command line interface point of view, but from technical point of view I need to take a more careful look at LLVM's CommandLine library to see if it is possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like boolOrDefault
is what I'm looking for here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I was too quick with boolOrDefault
: I don't need it, because I don't really care about whether the option was passed or not, but I care about its value.
Also, CommandLine library supports flags through boolean options, i.e. -spirv-replace-fmuladd-with-ocl-mad
is equivalent to -spirv-replace-fmuladd-with-ocl-mad=true
.
From my point of view the current way is good enough: most likely no one will ever use that switch and I don't want to overcomplicate the code just to get a -no-spirv-replace-fmuladd-with-ocl-mad
alias (moreover, due to CommandLine library it would be really confusing to be able to use -no-spirv-replace-fmuladd-with-ocl-mad=false
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for expanding on this, SGTM.
Signed-off-by: Aleksander Fadeev <aleksander.fadeev@intel.com>
Signed-off-by: Aleksander Fadeev <aleksander.fadeev@intel.com>
Signed-off-by: Aleksander Fadeev <aleksander.fadeev@intel.com>
05d38e0
to
514f5b8
Compare
…ad from OpenCL.. 'master' -> 'xmain-web' (KhronosGroup#8) CONFLICT (content): Merge conflict in include/LLVMSPIRVOpts.h commit 1cb18fd Author: Alexey Sachkov <alexey.sachkov@intel.com> Date: Wed Dec 9 17:45:33 2020 +0300 Add possibility to lower llvm.fmuladd into mad from OpenCL extinst (KhronosGroup#824) Change-Id: I725ce530db2dfe1c2f443b70f5d298b9a8238fc0
This is a PR #793, which I had to re-create in order to enable Travis CI check (I hope it will work)