[clang] [clang] Introduce elementwise clz/ctz builtins (PR #131995)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 16 08:12:50 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.
----------------
efriedma-quic wrote:

Due to various interactions with the way poison works, anything that produces poison is undefined behavior, from a C language perspective.  Producing poison instead of triggering instant UB is mostly for our own convenience, internally.  If you want some kind of defined result, you need to either freeze the result, or implicitly synthesize the second argument to some constant.

https://github.com/llvm/llvm-project/pull/131995


More information about the cfe-commits mailing list