================
@@ -1561,6 +1583,24 @@ Constant *llvm::ConstantFoldCastOperand(unsigned Opcode, 
Constant *C,
       }
     }
     break;
+  case Instruction::AddrSpaceCast:
+    // A null pointer (`ptr addrspace(N) null` in IR presentation,
+    // `ConstantPointerNull` in LLVM class, not `nullptr` in C/C++) used to
+    // represent a zero-value pointer in the corresponding address space.
+    // Therefore, we can't simply fold an address space cast of a null pointer
+    // from one address space to another, because on some targets, the nullptr
+    // of an address space could be non-zero.
+    //
+    // Recently, the semantic of `ptr addrspace(N) null` is changed to 
represent
+    // the actual nullptr in the corresponding address space. It can be zero or
+    // non-zero, depending on the target. Therefore, we can fold an address
+    // space cast of a nullptr from one address space to another.
+
+    // If the input is a nullptr, we can fold it to the corresponding
+    // nullptr in the destination address space.
+    if (C->isNullValue())
----------------
arichardson wrote:

I don't see this property in langref so we should either add it or drop this 
fold. 

https://github.com/llvm/llvm-project/pull/166667
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to