llvm / llvm/llvm-project

[MLIR] MLIR `vector.load` lowering generates an invalid logical pointer

Open
#213,192 1 comment 0 reactions 0 assignees View on GitHub
mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

On LLVM main, lowering `vector.load` and `vector.store` to SPIR-V generates a pointer `OpBitcast` that is invalid with the Logical addressing model. The lowering itself succeeds, but spirv-val rejects the serialized module.

### Input Program
**input.mlir**
```llvm
module attributes {
gpu.container_module,
spirv.target_env = #spirv.target_env<
#spirv.vce,
#spirv.resource_limits<>>
} {
gpu.module @kernels {
gpu.func @copy_vector(%src : memref<16xf32>, %dst : memref<16xf32>) kernel
attributes {
spirv.entry_point_abi =
#spirv.entry_point_abi
} {
%c0 = arith.constant 0 : index
%value = vector.load %src[%c0] : memref<16xf32>, vector<4xf32>
vector.store %value, %dst[%c0] : memref<16xf32>, vector<4xf32>
gpu.return
}
}

func.func @main() {
%c1 = arith.constant 1 : index
%src = memref.alloc() : memref<16xf32>
%dst = memref.alloc() : memref<16xf32>
gpu.launch_func @kernels::@copy_vector
blocks in (%c1, %c1, %c1) threads in (%c1, %c1, %c1)
args(%src : memref<16xf32>, %dst : memref<16xf32>)
memref.dealloc %src : memref<16xf32>
memref.dealloc %dst : memref<16xf32>
return
}
}
```

### Reproduction Command
```bash
mlir-opt input.mlir \
'--pass-pipeline=builtin.module(spirv-attach-target{ver=v1.3 caps=Shader exts=SPV_KHR_storage_buffer_storage_class},test-convert-to-spirv{convert-gpu-modules=true nest-in-gpu-module=true},gpu.module(spirv.module(spirv-lower-abi-attrs,spirv-update-vce)))' \
-o lowered.mlir

# Extract the nested spirv.module into a standalone MLIR file.
sed -n '/^ spirv.module /,/^ }/p' lowered.mlir |
sed 's/^ //' > spirv-module.mlir

mlir-translate \
--no-implicit-module --serialize-spirv \
spirv-module.mlir -o module.spv

spirv-val --target-env vulkan1.1 module.spv
```

The last command fails with:
```bash
error: line 36: OpLoad Pointer '19[%19]' is not a logical pointer.
%20 = OpLoad %v4float %19
```

Version: 13e5ce40eff159ed9b2db3660b41c47ca640ce51.

Contributor guide

Open the contributing guide

Research direction

Start with input.mlir and run the shown mlir-opt pipeline, then serialize the extracted spirv-module.mlir with mlir-translate. Inspect the generated pointer operations and use spirv-val to verify the fix; done means the lowered module validates without the logical-pointer error.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.