Issue 244451
Summary [AMDGPU][GlobalISel] Generic-pointer llvm.amdgcn.load.to.lds asserts in RegBankLegalize
Labels new issue
Assignees
Reporter nodecoda
    `llvm.amdgcn.load.to.lds` is declared with `llvm_anyptr_ty`, so the generic
pointer (`p0`) overload is legal. `llc -global-isel` aborts on it in
RegBankLegalize; SelectionDAG handles the same IR fine.

### Repro

```llvm
declare void @llvm.amdgcn.load.to.lds(ptr, ptr addrspace(3), i32, i32, i32)

define amdgpu_kernel void @k(ptr addrspace(1) %global_buffer, ptr addrspace(3) %lds) {
entry:
  %gepvmem = addrspacecast ptr addrspace(1) %global_buffer to ptr
  call void @llvm.amdgcn.load.to.lds(ptr %gepvmem, ptr addrspace(3) %lds, i32 4, i32 4, i32 0)
  ret void
}
```

```console
$ llc -global-isel -global-isel-abort=2 -mtriple=amdgpu9.50 lds.ll -o /dev/null
llc: lib/Target/AMDGPU/AMDGPURegBankLegalizeHelper.cpp:2393: ... applyMappingSrc(...):
  Assertion `Ty == getTyFromID(MethodIDs[i])' failed.

$ llc -mtriple=amdgpu9.50 lds.ll -o - | grep global_load_lds
	global_load_lds_dword v0, s[0:1] offset:4
```

Reproduces on amdgpu9.00, 9.42, 9.50, 10.30, 11.00 and 12.00 (assertions build).

### Cause

`AMDGPURegBankLegalizeRules.cpp:2471` puts three intrinsics on one rule:

```cpp
addRulesForIOpcs(
 {amdgcn_global_load_lds, amdgcn_load_to_lds, amdgcn_load_async_to_lds})
 .Any({{}, {{}, {IntrId, VgprP1, SgprB32_M0}}});
```

`amdgcn_global_load_lds` takes `LLVMQualPointerType<1>` (IntrinsicsAMDGPU.td:2699),
so `VgprP1` is right for it. `load.to.lds` and `load.async.to.lds` take
`llvm_anyptr_ty` (IntrinsicsAMDGPU.td:2682); for the `p0` overload the operand's
LLT is `p0`, which never equals `getTyFromID(VgprP1)`. The `p7` overload does not
fail because `AMDGPULowerBufferFatPointers` expands it first
(AMDGPULowerBufferFatPointers.cpp:2505); nothing expands the generic case.

The same abort shows up on an existing test when it is forced to GlobalISel:
`CodeGen/AMDGPU/waitcnt-unscoped.ll` `@test_waitcnt` passes a generic pointer
(gep on a `p1` kernarg that is bitcast to `p0`) to `load.to.lds`. Reproduce with
`-run-pass=amdgpu-reg-bank-legalize` on the MIR printed with
`-stop-before=amdgpu-reg-bank-legalize`.

Found by running every `CodeGen/AMDGPU/**/*.ll` (3638 files) through
`-global-isel -global-isel-abort=2` with the triple taken from the test's own RUN
line, then filtering to the cases where the default (SelectionDAG) pipeline
succeeds.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to