[llvm] [Loads] Allow replacement of null with ptr in `canReplacePointersIfEqual` (PR #184348)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 3 06:47:43 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))
----------------
nikic wrote:
Hm, yeah, I guess we should check the address space for now to be conservative. There is ongoing work to make ConstantPointerNull actually be a null pointer (as opposed to a zero pointer) in all address spaces, but that will still take a while.
https://github.com/llvm/llvm-project/pull/184348
More information about the llvm-commits
mailing list