<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/97086>97086</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AMDGPU] [NVPTX] Infer Address Spaces pass leaving behind GEP with no operands
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
StackDoubleFlow
</td>
</tr>
</table>
<pre>
This crash was found using an IR fuzzer. It looks like Infer Address Spaces only runs under the AMDGPU and NVPTX backends. The only way I've been able to reproduce this was with a byval struct argument in a function that gets inlined. The inlined function is reading the second field of the struct in this case.
```
%struct = type { i64, i64 }
define i64 @bar(ptr byval(%struct) %a) alwaysinline {
%1 = getelementptr %struct, ptr %a, i64 0, i32 1
%2 = load i64, ptr %1, align 4
ret i64 0
}
define i64 @foo(%struct* %arg) {
%1 = call i64 @bar(%struct* byval(%struct) align 8 %arg)
ret i64 0
}
```
Compiler Explorer: https://godbolt.org/z/9zW6nnffT
Here's the IR dump before and after the pass:
```
*** IR Dump After Infer address spaces (infer-address-spaces) ***
; Function Attrs: alwaysinline
define i64 @bar(ptr byval(%struct) %a) #0 {
%1 = getelementptr %struct, ptr %a, i64 0, i32 1
%2 = load i64, ptr %1, align 4
ret i64 0
}
*** IR Dump After Infer address spaces (infer-address-spaces) ***
define i64 @foo(ptr %arg) #1 {
%arg1 = alloca %struct, align 8, addrspace(5)
call void @llvm.lifetime.start.p5(i64 16, ptr addrspace(5) %arg1)
call void @llvm.memcpy.p5.p0.i64(ptr addrspace(5) align 1 %arg1, ptr align 1 %arg, i64 16, i1 false)
%1 = getelementptr
%2 = load i64, ptr addrspace(5) %1, align 4
call void @llvm.lifetime.end.p5(i64 16, ptr addrspace(5) %arg1)
ret i64 0
}
```
Notice how %1 turned into an empty GEP. This will cause an ICE when later passes assume GEP operands.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o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