The LLVM and SPIRV dialects provide an “undef” operation that comes handy when generating code - simply because sometimes a variable does not need to take a precise value, so no code is needed to do so.
I was wondering why the std dialect does not provide it.
The major challenge the standard dialect faces is definitional - what do we include, more importantly what do we exclude. Furthermore, for anything we include, we need clearly defined semantics. This is one of the major challenges with undef.
And yet “undefined” exists in various programming language semantics. It can be either seen as an arbitrary value or as a special undefined symbol whose use in computations produces other undefined values.
I think the subtlety is that while “undefined” exists in many language, it does not have the same semantic for each language. That makes it challenging when defining an IR, and undef in LLVM is quite complex already, and still not satisfactory actually (seeing the recent years attempt to evolve it): see for example https://www.cs.utah.edu/~regehr/papers/undef-pldi17.pdf
Stepping up, you mention variable that need not be initialized & codegen, is this already in buffer world? We don’t really have variables in std (well beyond loop induction variables where this would not apply).