[clang] [clang] Introduce elementwise ctlz/cttz builtins (PR #131995)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 4 14:33:52 PDT 2025


efriedma-quic wrote:

> That's not what I'm requesting, it would be an undefined value. It is not instant undefined behavior, you would get UB on use of that value

You're creating a lot of work by insisting on this.

We don't currently have a definition of what it means to "use" a value in a way that would cause undefined behavior with poison.  The standards define "indeterminate value"(C++)/"indeterminate representation"(C), but those aren't suitable here: they allow constructs that produce undefined behavior with poison.

So if we want to allow this usage, we would need to very carefully define what it means to "use" a value, in a way that consistent with the way clang currently generates LLVM IR, and avoid potential conflicts with future memory model improvements.  Which is hard because the LLVM memory model is still incomplete.  So we'd need an RFC for defining what an "undefined value" is.

If you have some plan to use this notion of "undefined value" for something other than ctlz/cttz, then maybe this work is worth doing, but I don't want do do it just for a few obscure builtins.

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


More information about the cfe-commits mailing list