When the addrspacecast instruction was added, the ability to bitcast between pointers from different address spaces was removed.
There are cases, where after analysis, cast between pointers from different address spaces can be concluded to be a no-op cast.
If bitcast can be allowed in these scenarios, it would help further optimise the IR in Transform passes since its a no-op cast.
This enhancement to bitcast will require that pointers to the two address spaces have the same bit widths(can be queried from DataLayout).
Frontend should never misuse the bitcast wherever addrspace cast would have been more appropriate.
For example consider the below IR:
GVN pass has discovered a reinterpretation of bits via a store followed by a load.
%struct.S.coerce = type { i32 addrspace(1)* }
%s.sroa.0 = alloca i32*, align 8, addrspace(5)
%0 = extractvalue %struct.S.coerce %s.coerce, 0
%1 = bitcast i32* addrspace(5)* %s.sroa.0 to i32 addrspace(1)* addrspace(5)*
%2 = addrspacecast i32 addrspace(1)* addrspace(5)* %1 to i32 addrspace(1)
store i32 addrspace(1)* %0, i32 addrspace(1) %2, align 8
%3 = load i32*, i32* addrspace(5)* %s.sroa.0, align 8, !tbaa !2
GVN pass currently introduces no-op ptrotoint/inttoptr for load.
%3 = ptrtoint i32 addrspace(1)* %0 to i64
%4 = inttoptr i64 %3 to i32*
If bitcast of pointers from different address is allowed, load can be replaced with no-op bitcast
%3 = bitcast i32 addrspace(1)* %0 to i32*
This should be illegal, not legal and undefined, you really want the IR verifier to be able to pick up on this at least, if not an assertion at creation time