[llvm] [Loads] Allow replacement of null with ptr in `canReplacePointersIfEqual` (PR #184348)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 06:48:49 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))
----------------
antoniofrighetto wrote:

I thought @nikic RFC / null_pointer_is_defined upcoming work has yet to be taken place?

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


More information about the llvm-commits mailing list