-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[clang][docs] Revise documentation for __builtin_reduce_(max|min)
.
#114637
Conversation
@llvm/pr-subscribers-clang Author: None (c8ef) ChangesFull diff: https://github.com/llvm/llvm-project/pull/114637.diff 1 Files Affected:
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index 10232ff41da15a..b7676bab623ef8 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -745,12 +745,8 @@ Let ``VT`` be a vector type and ``ET`` the element type of ``VT``.
======================================= ====================================================================== ==================================
Name Operation Supported element types
======================================= ====================================================================== ==================================
- ET __builtin_reduce_max(VT a) return x or y, whichever is larger; If exactly one argument is integer and floating point types
- a NaN, return the other argument. If both arguments are NaNs,
- fmax() return a NaN.
- ET __builtin_reduce_min(VT a) return x or y, whichever is smaller; If exactly one argument integer and floating point types
- is a NaN, return the other argument. If both arguments are
- NaNs, fmax() return a NaN.
+ ET __builtin_reduce_max(VT a) return the largest element of the vector. integer and floating point types
+ ET __builtin_reduce_min(VT a) return the smallest element of the vector. integer and floating point types
ET __builtin_reduce_add(VT a) \+ integer types
ET __builtin_reduce_mul(VT a) \* integer types
ET __builtin_reduce_and(VT a) & integer types
|
clang/docs/LanguageExtensions.rst
Outdated
is a NaN, return the other argument. If both arguments are | ||
NaNs, fmax() return a NaN. | ||
ET __builtin_reduce_max(VT a) return the largest element of the vector. integer and floating point types | ||
ET __builtin_reduce_min(VT a) return the smallest element of the vector. integer and floating point types |
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.
Please can you add back the NaN semantics - AFAICT they should always return the largest/smallest non-NAN value if any vector element is non-NAN, otherwise it could return any of the NAN values in the (all NAN) vector. There might be a better way of phrasing that......
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.
LLVM LangRef states: "This instruction has the same comparison semantics as the ‘llvm.maxnum.*’ intrinsic." Can I add a link to https://llvm.org/docs/LangRef.html#vector-reduction-intrinsics?
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.
Add pointers to the floating point min/max function.
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.
Do we have any kind of conformance testing for this?
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'm not sure if we had any conformance testing before, but since this is just a document change and the patch is keeping the clang builtin document aligned with the llvm intrinsic document, maybe there's no need to add extra tests here?
clang/docs/LanguageExtensions.rst
Outdated
floating point, this function has the same comparison semantics as | ||
``__builtin_reduce_maximum``. | ||
ET __builtin_reduce_min(VT a) return the smallest element of the vector. If the element type is integer and floating point types | ||
floating point, this function has the same comparison semantics as |
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.
Looking at the implementation, this is going to use reduce_fmax intrinsic, which is not the same as reduce_maximum
I think this builtin trying to support floating point is an anti-feature, and if it has to, it should have matched minimum/maximum. But that's not what the implementation is doing
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
I apologize for my earlier mistake. The function |
@c8ef why did you close this? |
clang/docs/LanguageExtensions.rst
Outdated
ET __builtin_reduce_max(VT a) return the largest element of the vector. The result will always be integer and floating point types | ||
a number unless all elements of the vector are NaN. | ||
ET __builtin_reduce_min(VT a) return the smallest element of the vector. The result will always be integer and floating point types | ||
a number unless all elements of the vector are NaN. |
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.
The floating point result will always be a number unless all elements of the vector are NaN.
?
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.
Done!
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.
LGTM
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.
LGTM, thanks!
ET __builtin_reduce_max(VT a) return the largest element of the vector. The floating point result integer and floating point types | ||
will always be a number unless all elements of the vector are NaN. | ||
ET __builtin_reduce_min(VT a) return the smallest element of the vector. The floating point result integer and floating point types | ||
will always be a number unless all elements of the vector are NaN. |
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.
This will not be true for a signaling nan for a 2 element vector with IEEE behavior for minnum/maxnum
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.
But really it was a mistake to make this support floating point
The function operation described in the document did not match its actual semantic meaning, this patch resolved the problem.