-
Notifications
You must be signed in to change notification settings - Fork 248
Add translation of fpclass llvm intrinsic #1922
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
Conversation
There is no direct counterpart for it in SPIR-V, so testing is mapped on a sequence of SPIR-V instructions: 1. test for qnan and snan -> OpIsNan 2. test for neg/pos inf -> OpIsInf + OpSignBitSet 3. test for neg/pos normal -> OpIsNormal + OpSignBitSet 4. test for neg/pos subnormal -> not (OpIsNormal or OpIsNan) + OpSignBitSet 5. test for neg/pos zero -> OpFOrdEqual + OpSignBitSet Signed-off-by: Sidorov, Dmitry <[email protected]>
jcranmer-intel
left a comment
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.
Since I've been reviewing several of the upstream patches related here, I felt I should give some drive-by comments.
The "correct" lowering of is_fpclass is given by TargetLowering::expandIS_FPCLASS (https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp#L8019). Instcombine should be canonicalizing the tests that are equivalent to a single comparison into a single instruction, so checking for the really simple cases may not be all that beneficial.
The general strategy for the implementation should not to be to check with floating-point operations, but integer operations on bitcast-to-int. This avoids issues where floating-point operations may have underspecified issues (e.g., comparison to zero returning different results depending on denormals-are-zero setting).
Signed-off-by: Sidorov, Dmitry <[email protected]>
|
@jcranmer-intel thanks! I've applied the comments. Not QNan, SNan, PosSubnormal, NegSubnormal, PosZero and NegZero are checked after bitcast to int. Checks for normal and inf remained to be the same - relying on existing SPIR-V instructions. |
Signed-off-by: Sidorov, Dmitry <[email protected]>
Signed-off-by: Sidorov, Dmitry <[email protected]>
|
@jcranmer-intel @asudarsa @svenvh @maksimsab @jgstarIntel please take a look |
| ; RUN: spirv-val %t.spv | ||
| ; RUN: llvm-spirv -r %t.spv -o %t.rev.bc | ||
|
|
||
| ; Just check that reverse translation works |
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.
Can we have a quick check to ensure that fpclass is not generated here?
Thanks
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 guess it's being checked implicitly by the fact, that forward translation doesn't error out due to unknown intrinsic
| ResultVec.emplace_back( | ||
| GetNegPosInstTest(TestIsInf, FPClass & fcNegInf)); | ||
| } | ||
| if (FPClass & fcNormal) { |
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 possibility that fcNormal bit is set and both fcPosNormal and fcNegNormal are not set? In such such, what is the expected behavior? Thanks
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.
fcNormal is (fcPosNormal | fcNegNormal) so it's impossible scenario
same for inf, subnormal etc
asudarsa
left a comment
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.
Overall LGTM. Just a couple of minor questions/comments.
Thanks
Signed-off-by: Sidorov, Dmitry <[email protected]>
|
@asudarsa may I ask to take another look? I've added 2 enhancements: added caching for sign test results to be reused => less IsSignBit instructions generated and added check for inverted test aka (is inf, is normal, is subnormal is zero) = (is not nan) |
Signed-off-by: Sidorov, Dmitry <[email protected]>
|
@jcranmer-intel may I ask you to revisit the PR? |
jcranmer-intel
left a comment
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.
In theory, the tests could be a little more comprehensive, but without an update-test-checks-like script, it is going to be too painful to make such a test for the limited extra value it would bring.
Optimized LLVM IR started to contain this intrinsic recently after InstCombine updates, like:
"Fold and/or of fcmp into class" ( 08f03887 )
There is no direct counterpart for it in SPIR-V, so testing is mapped on a sequence of SPIR-V instructions:
issignaling(V) ==> isnan(V) && !isquiet(V)