[llvm] [Attributor] Don't replace `AddrSpaceCast` with `ConstantPointerNull` (PR #126779)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 11 22:02:59 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:
Interestingly, that was exactly the first version of my fix, but I chose the current approach after a second thought.
We still want to look through address space cast when analyzing potential pointer value and/or underlying object. The only thing concerned here is probably nullptr. I think it is okay to treat `ptr addrspace(x) null` same as `addrspacecast (ptr null to ptr addrspace(x))` when we do analysis such that we can know whether a pointer points to nothing, but we will not replace the latter with the former because of the limitation/issue/design we currently have.
On a side note, IMHO, they should be the same and `ptr addrspace(x) null` should present the nullptr in AS x but the source code representation `ConstantPointerNull` means something else. Once we have a new class for DL nullptr, I think `ptr addrspace(x) null` should belong to it.
https://github.com/llvm/llvm-project/pull/126779
More information about the llvm-commits
mailing list