[AMDGPU][GlobalIsel] ICE: cannot select G_PHI
The following bitcode module triggers an internal compiler error for -global-isel -O0 in f68ef5b4303de763ecf37fd57cbefc3891ee48c0:
define i32 @__ockl_get_num_groups() {
%1 = load i16, ptr addrspace(4) null, align 2
%2 = icmp ne i16 %1, 0
br label %3
3: ; preds = %0
%4 = phi i1 [ %2, %0 ]
%5 = zext i1 %4 to i32
ret i32 %5
}
Reproducer: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O0 -global-isel module.ll
Failure: LLVM ERROR: cannot select: %12:sreg_64_xexec(s1) = G_PHI %11:vcc(s1), %bb.1 (in function: __ockl_get_num_groups
Bug found by @ElliotBLabs.
@llvm/issue-subscribers-backend-amdgpu
Author: Manuel Carrasco (mgcarrasco)
define i32 @<!-- -->__ockl_get_num_groups() {
%1 = load i16, ptr addrspace(4) null, align 2
%2 = icmp ne i16 %1, 0
br label %3
3: ; preds = %0
%4 = phi i1 [ %2, %0 ]
%5 = zext i1 %4 to i32
ret i32 %5
}
Reproducer: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O0 -global-isel module.ll
Bug found by @ElliotBLabs.
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 is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
- Leave a comment indicating that you are working on the issue, 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. Be aware that LLVM's AI policy forbids the use of AI tools to fix good first issues since it squanders a learning opportunity. Using LLMs to search and learn is permitted, since the goal is learning.
- 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: Manuel Carrasco (mgcarrasco)
define i32 @<!-- -->__ockl_get_num_groups() {
%1 = load i16, ptr addrspace(4) null, align 2
%2 = icmp ne i16 %1, 0
br label %3
3: ; preds = %0
%4 = phi i1 [ %2, %0 ]
%5 = zext i1 %4 to i32
ret i32 %5
}
Reproducer: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O0 -global-isel module.ll
Failure: LLVM ERROR: cannot select: %12:sreg_64_xexec(s1) = G_PHI %11:vcc(s1), %bb.1 (in function: __ockl_get_num_groups
Bug found by @ElliotBLabs.
try -global-isel - new-reg-bank-legalize
cc to keep you posted @CatherineMoore @kzhuravl
try -global-isel - new-reg-bank-legalize
@petar-avramovic Thanks! I gave it a try but -new-reg-bank-legalize doesn't exist, is it -new-reg-bank-select?
-mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -O0 -global-isel -new-reg-bank-select works and the ICE is not reproducible
yes sorry, meant -new-reg-bank-select
I don't if its taken but if not i would love to work
I don't if its taken but if not i would love to work
Sure, go ahead, thanks.
Thanks can you assign it to me ?
there is nothing to fix here, just global-isel can't determine correct bank for phi (this was uniform phi). use -global-isel -new-reg-bank-select. Divergent phis are not easy to select, they are lowered in amdgpu divergencelowering.
there is nothing to fix here, just global-isel can't determine correct bank for phi (this was uniform phi). use -global-isel -new-reg-bank-select. Divergent phis are not easy to select, they are lowered in amdgpu divergencelowering.
Thanks @petar-avramovic. Just to follow, so this test is then exercising missing support in -global-isel and to avoid that for now we must use it with -new-reg-bank-select, right?
yes, to be precise this is not really supported with generic regbankselect pass, the one in just -global-isel pipeline. There is some work in progress to make new passes that will be able to work correctly, ones in -global-isel -new-reg-bank-select pipeline, it should become default -global-isel pipeline for amdgpu soon. If you want to test functional -global-isel, need to run -global-isel -new-reg-bank-select, but it is not complete yet so it might error out with some missing opcode support
hi @Ko496-glitch, are you still working on this? Can I grab it?
hi @Ko496-glitch, are you still working on this? Can I grab it?
I believe we already discussed in the feed that there is nothing to fix here
After https://github.com/llvm/llvm-project/pull/203928 new-reg-bank-select is used by default