null in addrspace(0) is defined to not point to any valid object.
Casting the pointer to another address space cannot make it point
to a valid object.
This is consistent with alias analysis's interpretation of null, e.g.
; Function: ptr_compare: 2 pointers, 0 call sites
; MayAlias: i32* %ptr, i32 addrspace(3)* @lds
define void @ptr_compare(i32* %ptr) {
%load = load i32, i32 addrspace(3)* @lds store i32 0, i32* %ptr ret void
}
; Function: null_compare: 2 pointers, 0 call sites
; NoAlias: i32 addrspace(3)* @lds, i32* null
define void @null_compare() {
%load = load i32, i32 addrspace(3)* @lds store i32 0, i32* null ret void
}
Fixes issue 58617, for the basic case. More complex cases,
like an offset from a GEP should also fold out. I'm not sure
it's appropriate for ConstantFolding to handle the general case,
which should use getUnderlyingObject.