一句话:提出 raw memory 类型与 freezing load 扩展 LLVM IR,替代 undef 的最后用途,为彻底移除 undef 铺路。
LLVM IR 中的 undef 与 poison 两个延迟未定义行为值长期是错误来源;undef 尤其难以推理,其“每次观察可取不同任意值”的语义会让 2×y 改写为 y+y 等看似简单的优化变得不健全。它的最后用途是表示未初始化内存,并影响位域 lowering、原始数据拷贝与比较。本文提出对 LLVM IR 的扩展:引入 raw memory 值类型和 freezing load,并论证二者足以替代 undef 的剩余用途。作者在 LLVM 中实现这些构造,评估显示对运行时和编译时性能影响很小。该工作扫除了彻底移除 undef 的最后障碍,为更简单的语义模型和更易论证 IR 分析与优化的健全性铺平道路。
LLVM’s intermediate representation (IR) has two deferred undefined behavior (UB) values: undef and poison. The existence of these two values has been a persistent source of bugs. Reasoning about the correctness of analyses and optimizations for the regular cases is already tricky; ensuring that these are sound for all UB cases is highly non-trivial. Undef values, in particular, are one of the most misunderstood concepts of LLVM IR. On paper, the definition is simple: they represent an arbitrary value of the underlying type, and can yield a different value each time they are observed. However, this property makes even simple algebraic rewrites, such as replacing 2 × y with y + y , unsound in LLVM. Because reasoning about undef is hard, and the benefits of having it are limited, we have set a roadmap to eliminate it altogether from LLVM IR. The last remaining use of undef is the value of uninitialized memory, which has implications on the lowering of bitfields, as well as raw data copies and comparisons. In this paper, we propose an extension to LLVM IR that includes a raw memory value type and a freezing load. We show that these two constructs are sufficient to replace the remaining uses of undef in LLVM. Our implementation shows that these changes have minimal impact on both run-time and compile-time performance. By removing the final hurdle to eliminating undef from LLVM IR, this work paves the way for a simpler semantic model and easier reasoning about the soundness of IR analyses and optimizations.
@article{LoboMMLSL26,
title = {Towards Removing Undef Values from LLVM IR},
author = {Pedro Lobo and John McIver and George Mitenkov and Juneyoung Lee and Kirshanthan Sundararajah and Nuno P. Lopes},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {PLDI},
year = {2026},
doi = {10.1145/3808250}
}