================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits