llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[AMDGPU][GlobalIsel] ICE: cannot select G_PHI

Open mgcarrasco opened this issue 6 months ago • 16 comments

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.

mgcarrasco avatar Jun 01 '26 12:06 mgcarrasco

@llvm/issue-subscribers-backend-amdgpu

Author: Manuel Carrasco (mgcarrasco)

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

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:

  1. 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.
  2. 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.
  3. 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.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. 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)

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.

try -global-isel - new-reg-bank-legalize

petar-avramovic avatar Jun 01 '26 15:06 petar-avramovic

cc to keep you posted @CatherineMoore @kzhuravl

mgcarrasco avatar Jun 01 '26 15:06 mgcarrasco

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

mgcarrasco avatar Jun 01 '26 15:06 mgcarrasco

yes sorry, meant -new-reg-bank-select

petar-avramovic avatar Jun 01 '26 15:06 petar-avramovic

I don't if its taken but if not i would love to work

Ko496-glitch avatar Jun 01 '26 17:06 Ko496-glitch

I don't if its taken but if not i would love to work

Sure, go ahead, thanks.

mgcarrasco avatar Jun 01 '26 18:06 mgcarrasco

Thanks can you assign it to me ?

Ko496-glitch avatar Jun 01 '26 18:06 Ko496-glitch

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.

petar-avramovic avatar Jun 01 '26 21:06 petar-avramovic

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?

mgcarrasco avatar Jun 02 '26 09:06 mgcarrasco

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

petar-avramovic avatar Jun 02 '26 10:06 petar-avramovic

hi @Ko496-glitch, are you still working on this? Can I grab it?

jkvargas avatar Jul 08 '26 05:07 jkvargas

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

Ko496-glitch avatar Jul 08 '26 18:07 Ko496-glitch

After https://github.com/llvm/llvm-project/pull/203928 new-reg-bank-select is used by default

mbrkusanin avatar Jul 13 '26 10:07 mbrkusanin