[llvm-branch-commits] [llvm] [mlir] [WIP][IR][Constants] Change the semantic of `ConstantPointerNull` to represent an actual `nullptr` instead of a zero-value pointer (PR #183215)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 25 00:49:18 PST 2026


================
@@ -1592,6 +1592,13 @@ Constant *llvm::ConstantFoldCastOperand(unsigned Opcode, Constant *C,
                              : DestTy->getPointerAddressSpace();
       if (DL.isNullPointerAllZeroes(AS))
         return Constant::getNullValue(DestTy, &DL);
+      // Non-zero null: ptrtoint(ConstantPointerNull) folds to the actual
+      // null integer value for this address space.
+      if (isa<ConstantPointerNull>(C)) {
+        const APInt &NullVal = DL.getNullPtrValue(AS);
+        return ConstantInt::get(
+            DestTy, NullVal.zextOrTrunc(DestTy->getIntegerBitWidth()));
----------------
arsenm wrote:

Why zext or trunc? I'd expect a -1 pointer to be sign extended to -1

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


More information about the llvm-branch-commits mailing list