[clang] [lld] [llvm] [WIP][IR][Constants] Change the semantic of `ConstantPointerNull` to represent an actual `nullptr` instead of a zero-value pointer (PR #166667)
Alexander Richardson via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 16 23:10:02 PST 2025
================
@@ -1543,6 +1558,13 @@ Constant *llvm::ConstantFoldCastOperand(unsigned Opcode, Constant *C,
}
break;
case Instruction::IntToPtr:
+ // We can fold it to a null pointer if the input is the nullptr value.
+ if (std::optional<APInt> NullPtrValue = DL.getNullPtrValue(
+ DestTy->getScalarType()->getPointerAddressSpace())) {
+ if ((NullPtrValue->isZero() && C->isZeroValue()) ||
+ (NullPtrValue->isAllOnes() && C->isAllOnesValue()))
----------------
arichardson wrote:
I think we have to check the width of the input value for all ones since inttoptr zero-extends, so a short value would not end up as canonical nullptr.
https://github.com/llvm/llvm-project/pull/166667
More information about the llvm-commits
mailing list