[clang] [clang] Introduce elementwise clz/ctz builtins (PR #131995)
Fraser Cormack via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 16 02:08:21 PDT 2025
================
@@ -847,6 +848,14 @@ of different sizes and signs is forbidden in binary and ternary builtins.
semantics, see `LangRef
<http://llvm.org/docs/LangRef.html#llvm-min-intrinsics-comparation>`_
for the comparison.
+ T __builtin_elementwise_clz(T x[, T y]) return the number of leading 0 bits in the first argument. If integer types
+ the first argument is 0 and an optional second argument is provided,
+ the second argument is returned. If the first argument is 0 but only
+ one argument is provided, the result is undefined.
----------------
frasercrmck wrote:
I originally had "the behaviour is undefined" as that's what `__builtin_clzg` has, but it was pointed out in another discussion above that we're only returning a `poison` value in this situation and this is narrower in scope than "undefined behaviour". I therefore changed it to "the result is undefined" as the GCC docs say that for `__builtin_clz`.
Is `poison` an "indeterminate" value? I can definitely see "erroneous value" in that `poison` is specified by LLVM as being the result of an erroneous operation.
I'm happy to change it to whatever.
https://github.com/llvm/llvm-project/pull/131995
More information about the cfe-commits
mailing list