Here's a fix for SROA to avoid the generation of invalid bitcast between pointers in different address spaces.
The case is the following:
%p.addr = alloca <2 x float> addrspace(1)*, align 8 ; ... %p.new = bitcast <2 x float> addrspace(1)** %p.addr to <2 x float>** %val = load <2 x float>** %p.new, align 8
SROA identifies an AllocaSlice of %p.addr and %val and tries to rewrite it removing the load. The problem is that the source type of the loaded value is <2 x float> addrspace(1)* and the destination type is <2 x float>*, thus a bitcast between those types is invalid.
The proposed fix catches these cases generating a ptrtoint+inttoptr pair instead of an addrspacecast to keep the common bits of the value immutated.