AMDGPU: can optimize away v_readfirstlane_b32 on implicit_def input
For the small testcase:
; RUN: llc -march=amdgcn -mcpu=gfx900 < %s
; Only one readfistlane is really needed
define amdgpu_ps void @test(i32 %in, ptr %out) {
%v1 = insertelement <2 x i32> <i32 poison, i32 poison>, i32 %in, i32 0
%v2 = bitcast <2 x i32> %v1 to i64
%v3 = call i64 @llvm.amdgcn.s.quadmask.i64(i64 %v2)
%p = inttoptr i64 %v2 to ptr addrspace(4)
store i64 %v3, ptr %out
ret void
}
We are producing code which has 2 v_readfirstlane_b32 instructions. Only one is needed as second one reads undef:
v_readfirstlane_b32 s0, v0
v_readfirstlane_b32 s1, v1
s_quadmask_b64 s[0:1], s[0:1]
v_mov_b32_e32 v4, s1
v_mov_b32_e32 v3, s0
flat_store_dwordx2 v[1:2], v[3:4]
s_endpgm
Although backend does not see it is undef behind the REG_SEQUENCE.
@llvm/issue-subscribers-backend-amdgpu
Author: Stanislav Mekhanoshin (rampitec)
; Only one readfistlane is really needed
define amdgpu_ps void @test(i32 %in, ptr %out) { %v1 = insertelement <2 x i32> <i32 poison, i32 poison>, i32 %in, i32 0 %v2 = bitcast <2 x i32> %v1 to i64 %v3 = call i64 @llvm.amdgcn.s.quadmask.i64(i64 %v2) %p = inttoptr i64 %v2 to ptr addrspace(4) store i64 %v3, ptr %out ret void }
We are producing code which has 2 v_readfirstlane_b32 instructions. Only one is needed as second one reads undef:
v_readfirstlane_b32 s0, v0
v_readfirstlane_b32 s1, v1
s_quadmask_b64 s[0:1], s[0:1]
v_mov_b32_e32 v4, s1
v_mov_b32_e32 v3, s0
flat_store_dwordx2 v[1:2], v[3:4]
s_endpgm
Although backend does not see it is undef behind the REG_SEQUENCE.
</details>
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
- Check that no other contributor has already been assigned to this issue. If you believe that no one is actually working on it despite an assignment, ping the person. After one week without a response, the assignee may be changed.
- In the comments of this issue, request for it to be assigned to you, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
- Fix the issue locally.
- Run the test suite locally. Remember that the subdirectories under
test/create fine-grained testing targets, so you can e.g. usemake check-clang-astto only run Clang's AST tests. - Create a Git commit.
- Run
git clang-format HEAD~1to format your changes. - Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.
@llvm/issue-subscribers-good-first-issue
Author: Stanislav Mekhanoshin (rampitec)
; Only one readfistlane is really needed
define amdgpu_ps void @test(i32 %in, ptr %out) { %v1 = insertelement <2 x i32> <i32 poison, i32 poison>, i32 %in, i32 0 %v2 = bitcast <2 x i32> %v1 to i64 %v3 = call i64 @llvm.amdgcn.s.quadmask.i64(i64 %v2) %p = inttoptr i64 %v2 to ptr addrspace(4) store i64 %v3, ptr %out ret void }
We are producing code which has 2 v_readfirstlane_b32 instructions. Only one is needed as second one reads undef:
v_readfirstlane_b32 s0, v0
v_readfirstlane_b32 s1, v1
s_quadmask_b64 s[0:1], s[0:1]
v_mov_b32_e32 v4, s1
v_mov_b32_e32 v3, s0
flat_store_dwordx2 v[1:2], v[3:4]
s_endpgm
Although backend does not see it is undef behind the REG_SEQUENCE.
</details>
@kerbowa are you working on this, if not can I give it a go?
Most recently @JoshHuttonCode was looking at this issue.
Yes, I am taking a look at this issue.
@JoshHuttonCode are you still working on it?
Yes, I am. Now that my school term is done, I've got more time to work on it. Since this is my first issue, it's been taking me some time.
I have located the source of the issue, and I believe I have mostly implemented the fix. I am in the process of ensuring my fix does not break other use cases or have other side effects.
@JoshHuttonCode ping?
There is a PR open for this issue which is waiting for reviewer feedback.