| Issue |
207969
|
| Summary |
[AMDGPU] RewriteOutArguments produces incorrect result when call-site arguments may alias
|
| Labels |
backend:AMDGPU,
miscompilation
|
| Assignees |
|
| Reporter |
antoniofrighetto
|
IR:
```llvm
define i32 @callee(ptr addrspace(5) %val, ptr addrspace(5) %other) {
store i32 0, ptr addrspace(5) %val
%load = load i32, ptr addrspace(5) %other
ret i32 %load
}
define amdgpu_kernel void @caller(ptr addrspace(1) %out) {
%slot = alloca i32, addrspace(5)
store i32 1, ptr addrspace(5) %slot
%result = call i32 @callee(ptr addrspace(5) %slot, ptr addrspace(5) %slot)
store i32 %result, ptr addrspace(1) %out
ret void
}
```
Invoking opt trunk with `-mtriple=amdgcn-amd-amdhsa -amdgpu-rewrite-out-arguments` leads to:
```llvm
%callee = type { i32, i32 }
define private %callee @callee.body(ptr addrspace(5) %val, ptr addrspace(5) %other) {
%load = load i32, ptr addrspace(5) %other, align 4
%1 = insertvalue %callee poison, i32 %load, 0
%2 = insertvalue %callee %1, i32 0, 1
ret %callee %2
}
define i32 @callee(ptr addrspace(5) %0, ptr addrspace(5) %1) #0 {
%3 = call %callee @callee.body(ptr addrspace(5) poison, ptr addrspace(5) %1)
%4 = extractvalue %callee %3, 1
store i32 %4, ptr addrspace(5) %0, align 4
%5 = extractvalue %callee %3, 0
ret i32 %5
}
define amdgpu_kernel void @caller(ptr addrspace(1) %out) {
%slot = alloca i32, align 4, addrspace(5)
store i32 1, ptr addrspace(5) %slot, align 4
%result = call i32 @callee(ptr addrspace(5) %slot, ptr addrspace(5) %slot)
store i32 %result, ptr addrspace(1) %out, align 4
ret void
}
attributes #0 = { alwaysinline }
```
When both arguments passed to `@callee` alias the same slot, `%out` ends up holding 0 in the original program. After the rewrite, the store into `%val` has been sunk past the load in the stub, thus `%other` observes the pre-call value and `%out` ends up holding 1.
Godbolt: https://llvm.godbolt.org/z/7fP35jfsx.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs