Consider the following IR targeted to AMDGPU:
%agg.tmp1 = alloca %struct.float4, align 16, addrspace(5)
%agg.tmp12.sroa.0.0..sroa_idx.i = getelementptr inbounds %struct.float4, %struct.float4 addrspace(5)* %agg.tmp1, i64 0, i32 0
In InferAddrSpace pass, the %agg.tmp12.sroa.0.0..sroa_idx.i
is considered to be in FLAT address space (0) so it’s specific address space
need to be inferred. From %agg.tmp1
, the address space is inferred to be PRIVATE address space (5).
When rewriting %agg.tmp12.sroa.0.0..sroa_idx.i
to the new address space, the operand %agg.tmp1
is not taken care of, so %agg.tmp1
is set to be Undef
, which is wrong.
To resolve this issue, in the function of static Value *operandWithNewAddressSpaceOrCreatePoison
, I think below code snippet need to be inserted:
static Value *operandWithNewAddressSpaceOrCreatePoison(
...
if (Value *NewOperand = ValueWithNewAddrSpace.lookup(Operand))
return NewOperand;
// __Insert this code snippet below__
// If the address space of the operand already meets the requirement, just return it
if (Operand->getType()->getPointerAddressSpace() == NewAddrSpace)
return Operand;
...
Any ideas? Thanks in advance.