Skip to content

GlobalISel: infinite loop trying to legalize G_BUILD_VECTOR #79578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jayfoad opened this issue Jan 26, 2024 · 2 comments · Fixed by #68189
Closed

GlobalISel: infinite loop trying to legalize G_BUILD_VECTOR #79578

jayfoad opened this issue Jan 26, 2024 · 2 comments · Fixed by #68189

Comments

@jayfoad
Copy link
Contributor

jayfoad commented Jan 26, 2024

; RUN: llc -global-isel=1 -mtriple=amdgcn -mcpu=gfx1030 < %s
define void @main(<19 x i32> %arg) {
bb:
  %i = bitcast <19 x i32> %arg to <38 x i16>
  %i1 = extractelement <38 x i16> %i, i64 0
  %i2 = icmp eq i16 %i1, 0
  %i3 = zext i1 %i2 to i32
  %i4 = bitcast i32 %i3 to float
  %i5 = insertelement <4 x float> zeroinitializer, float %i4, i64 0
  call void @llvm.amdgcn.image.store.2d.v4f32.i32(<4 x float> %i5, i32 0, i32 0, i32 0, <8 x i32> zeroinitializer, i32 0, i32 0)
  ret void
}
declare void @llvm.amdgcn.image.store.2d.v4f32.i32(<4 x float>, i32 immarg, i32, i32, <8 x i32>, i32 immarg, i32 immarg)
@llvmbot
Copy link
Member

llvmbot commented Jan 26, 2024

@llvm/issue-subscribers-backend-amdgpu

Author: Jay Foad (jayfoad)

``` ; RUN: llc -global-isel=1 -mtriple=amdgcn -mcpu=gfx1030 < %s define void @main(<19 x i32> %arg) { bb: %i = bitcast <19 x i32> %arg to <38 x i16> %i1 = extractelement <38 x i16> %i, i64 0 %i2 = icmp eq i16 %i1, 0 %i3 = zext i1 %i2 to i32 %i4 = bitcast i32 %i3 to float %i5 = insertelement <4 x float> zeroinitializer, float %i4, i64 0 call void @llvm.amdgcn.image.store.2d.v4f32.i32(<4 x float> %i5, i32 0, i32 0, i32 0, <8 x i32> zeroinitializer, i32 0, i32 0) ret void } declare void @llvm.amdgcn.image.store.2d.v4f32.i32(<4 x float>, i32 immarg, i32, i32, <8 x i32>, i32 immarg, i32 immarg) ```

@petar-avramovic
Copy link
Collaborator

petar-avramovic commented Jan 26, 2024

The problem here is that
%0:_(<19 x s32>) = G_BUILD_VECTOR is not legal for <19 x s32>
while the user of %0:_(<19 x s32>) is legal for <19 x s32>. User is G_BITCAST

  %20:_(<38 x s16>) = G_BITCAST %0:_(<19 x s32>)
  %32:_(<19 x s32>) = G_BITCAST %20:_(<38 x s16>)

G_BUILD_VECTOR waits for user to get legalized, legalization process should create G_UNMERGE_VALUES (<19 x s32>) and this two should be combined away.
Note: artifact combiner is not allowed to look through G_BITCAST so G_BITCAST has to be legalized by the target.
The not allowed to look through comes from how G_BITCAST was described in globalisel documentation if I remember correctly.

In summary G_BITCAST should not be legal for <19 x s32> and <38 x s16>

Good first step is to first properly list all all legal types.
There is a PR that tried to implement this
#68189

@sstipano sstipano self-assigned this Jan 26, 2024
sstipano added a commit that referenced this issue Feb 13, 2024
… types, instead of checking bit width. (#68189)

In D151116 it was suggested to have a set of classes to cover every
possible case. This does it for bitcast first.

closes #79578
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants