<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109481>109481</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] Conversion to LLVM fails for AMX tile store intrinsic with BlockArgument
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ienkovich
</td>
</tr>
</table>
<pre>
Here is a small reproducer:
```
llvm.func @amx_phi(%copy: i1, %src: !llvm.ptr, %dst: !llvm.ptr) {
%cst_16 = llvm.mlir.constant(16 : i16) : i16
%cst_32 = llvm.mlir.constant(32 : i64) : i64
%0 = "amx.tilezero"(%cst_16, %cst_16) : (i16, i16) -> !llvm.array<16 x vector<16xbf16>>
llvm.br ^bb1(%0 : !llvm.array<16 x vector<16xbf16>>)
^bb1(%1: !llvm.array<16 x vector<16xbf16>>):
"amx.tilestored64"(%cst_16, %cst_16, %dst, %cst_32, %1) : (i16, i16, !llvm.ptr, i64, !llvm.array<16 x vector<16xbf16>>) -> ()
llvm.return
}
```
Translation to LLVM fails with the following error:
```
$ ./bin/mlir-translate --mlir-to-llvmir amx-phi.mlir
mlir-translate: /localdisk/ilyaenko/llvm-project/llvm/lib/IR/Instructions.cpp:685: void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT
<llvm::Value*> >, const llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed.
```
It looks like the store can be successfully translated only when its source tile is produced by another already translated AMX intrinsic call that provides `x86_amx` result instead of the original `[16 x <16 x float>]`. This makes it impossible to lower a loop with `amx.tdp*` call keeping an accumulator in a tile and storing it only after the loop.
I wonder if this can be fixed in MLIR code, e.g. by adding some explicit casts. If this has to be fixed in the translator, I'd appreciate any guidance on how it can be fixed.
</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