-
Notifications
You must be signed in to change notification settings - Fork 116
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
Fix signed zero issues of FRem #2782
Conversation
Test summary for commit fc12f6aCTS tests (Failed: 0/138994)
Ubuntu navi3x, SrdcvkUbuntu navi2x, Srdcvk |
We use IR builder CreateFRem to translate OpFRem to LLVM native frem instruction. The instruction is further lowered by backend following such formula: frem(x, y) = x - y * trunc(x/y) There is a latent issue when x=-0.0. According to SPIR-V spec, the sign of the result of FRem is the same as the sign of the dividend. But when we input x=-0.0 to above formula, we finally get the addition of (-0.0) + 0.0. The result is +0.0 returned by HW. Hence, we have to manually check this special case when nsz fast math flag is not specified.
Test summary for commit efec18eCTS tests (Failed: 0/137949)
Ubuntu navi3x, SrdcvkUbuntu navi2x, Srdcvk |
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 just looked into LLVM LangRef.rst. It says this about frem
:
The value produced is the floating-point remainder of the two operands. This is the same output as a libm '
fmod
' function, but without any possibility of settingerrno
. The remainder has the same sign as the dividend.
It seems like we should probably consider this an LLVM backend bug that must be fixed there instead of in LLPC?
cc @kezhaoAMD This might affect some of your stuff as well.
I created an issue ticket to LLVM backend team. If this could be resolved quickly, I will drop this change. Otherwise, I will keep it as a temporary workaround and remove it once backend fix lands. |
Thanks @jayfoad. I close this PR since a better fix is in LLVM itself: llvm/llvm-project#70448 |
The SPIR-V spec (https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpFRem) only specifies the sign of the result when the result is not zero, so this case is OK. |
We use IR builder CreateFRem to translate OpFRem to LLVM native frem instruction. The instruction is further lowered by backend following such formula:
frem(x, y) = x - y * trunc(x/y)
There is a latent issue when x=-0.0. According to SPIR-V spec, the sign of the result of FRem is the same as the sign of the dividend. But when we input x=-0.0 to above formula, we finally get the addition of (-0.0) + 0.0. The result is +0.0 returned by HW. Hence, we have to manually check this special case when nsz fast math flag is not specified.