[llvm] [llubi] Add support for constant inttoptr/ptrtoint expressions (PR #207028)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 6 07:58:30 PDT 2026


dtcxzyw wrote:

> This patch treats constant inttoptr/ptrtoint expressions as if they are executed just before the user. However, since ptrtoint exposes the pointer provenance and inttoptr relies on the current set of exposed provenances, it is incorrect. Imagine that we have an inttoptr in a gep instruction and a ptrtoint in an add instruction. They can be freely DCEd/reordered. In addition, the behaviour also depends on the initialization order of globals. That is terrible. Nikita's proposal also mentioned this issue but left it as an open question: https://hackmd.io/@nikic/SJBt4mFCll#Constant-expressions
>From my perspective, constant expressions are allowed to execute at any point in the program (before their users). Moving ptrtoint forward or inttoptr backward will not make the program more undefined. So we can evaluate all constant expressions before the program entry (i.e., all globals involved with ptrtoint will be exposed at the start). The only remaining concern is the use of ConstantExpr::getAsInstruction, because it will convert CEs back into instruction sequences :(

Ping for comments. llvm 23 is about to be released in the next week:  https://discourse.llvm.org/t/llvm-23-x-will-branch-next-week-tue-14th-july/91233

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


More information about the llvm-commits mailing list