llvm / llvm/llvm-project

[MLIR][Linalg] `--convert-arith-to-llvm` rewrites a `linalg.matmul` body and leaves the op unverifiable

Open
#217,967 11 comments 0 reactions 0 assignees View on GitHub
mlir:linalg
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Reproducer

### small.mlir
```mlir
func.func @f(%a: memref<2x3xi32>, %b: memref<3x2xi32>, %c: memref<2x2xi32>) {
linalg.matmul ins(%a, %b : memref<2x3xi32>, memref<3x2xi32>) outs(%c : memref<2x2xi32>)
return
}
```

### To reproduce:

```
mlir-opt small.mlir -o /dev/null # parses and verifies
```
```
mlir-opt small.mlir --convert-arith-to-llvm
```

### Crash:

```
small.mlir:2:3: error: expected add/mul op in the body
linalg.matmul ins(%a, %b : memref<2x3xi32>, memref<3x2xi32>) outs(%c : memref<2x2xi32>)
^
small.mlir:2:3: note: see current operation:
"linalg.matmul"(%arg0, %arg1, %arg2) <{indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d2)>, affine_map<(d0, d1, d2) -> (d2, d1)>, affine_map<(d0, d1, d2) -> (d0, d1)>], operandSegmentSizes = array}> ({
^bb0(%arg3: i32, %arg4: i32, %arg5: i32):
%0 = "llvm.mul"(%arg3, %arg4) <{overflowFlags = 0 : i32}> : (i32, i32) -> i32
%1 = "llvm.add"(%arg5, %0) <{overflowFlags = 0 : i32}> : (i32, i32) -> i32
"linalg.yield"(%1) : (i32) -> ()
}) : (memref<2x3xi32>, memref<3x2xi32>, memref<2x2xi32>) -> ()
```

Contributor guide

Open the contributing guide

Research direction

Start with the provided small.mlir reproducer and run mlir-opt both with and without --convert-arith-to-llvm to compare verification behavior. Trace the conversion's handling of the linalg.matmul body; done means the pass no longer leaves an unverifiable linalg.matmul operation and the reproducer completes successfully.

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
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.