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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 23 19:51:38 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)) {
+        if (auto *CE = dyn_cast<ConstantExpr>(&OldV);
+            CE && CE->getOpcode() == Instruction::AddrSpaceCast)
+          continue;
+      }
----------------
arsenm wrote:

Checking this here, in manifest, and for this specific expression doesn't feel like the right way to address this.

I would trust it slightly more if it was a check on the address space of the pointer type, but I would still expect this logic to be somewhere else

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


More information about the llvm-commits mailing list