[llvm] [Attributor] Don't replace `AddrSpaceCast` with `ConstantPointerNull` (PR #126779)

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 11 12:08:45 PST 2025


================
@@ -10970,6 +10970,15 @@ struct AAPotentialValuesImpl : AAPotentialValues {
       Value *NewV = getSingleValue(A, *this, getIRPosition(), Values);
       if (!NewV || NewV == &OldV)
         continue;
+      // FIXME: ConstantPointerNull represents a pointer with value 0, but it
+      // doesn’t necessarily mean a nullptr. `ptr addrspace(x) null` is not the
+      // same as `addrspacecast (ptr null to ptr addrspace(x))` if the nullptr
+      // in AS x is not zero. Therefore, we can't simply replace it.
+      if (isa<ConstantPointerNull>(NewV) && isa<ConstantExpr>(OldV)) {
----------------
shiltian wrote:

The result type must be a pointer so that leaves us to `IntToPtr` and `AddrSpaceCast` for the outermost expression. If it is `IntToPtr`, I think they can be directly replaced because the value will have to be 0. With that being said, I think this would work fine.

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


More information about the llvm-commits mailing list