[llvm] [Loads] Allow replacement of null with ptr in `canReplacePointersIfEqual` (PR #184348)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 06:41:27 PST 2026
================
@@ -827,14 +827,18 @@ static bool isPointerUseReplacable(const Use &U, bool HasNonAddressBits) {
return Limit != 0;
}
-// Returns true if `To` is a null pointer, constant dereferenceable pointer or
-// both pointers have the same underlying objects.
+// Returns true if `From` is a null pointer, `To` is a null pointer, or `To` is
+// a constant dereferenceable pointer, or both pointers have the same underlying
+// objects.
static bool isPointerAlwaysReplaceable(const Value *From, const Value *To,
const DataLayout &DL) {
// This is not strictly correct, but we do it for now to retain important
// optimizations.
if (isa<ConstantPointerNull>(To))
return true;
+ // Conversely, replacing null with destination pointer is always valid.
+ if (isa<ConstantPointerNull>(From))
----------------
dtcxzyw wrote:
I guess it is incorrect when null is defined in a non-zero address space. A null constant is interpreted as `inttoptr 0 to ptr`, which may recover provenance.
https://github.com/llvm/llvm-project/pull/184348
More information about the llvm-commits
mailing list