<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58409>58409</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            incorrect lowering of vector.contract 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir:vectorops
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            nicolasvasilache
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ftynse
      </td>
    </tr>
</table>

<pre>
    `vector.contract` lowers to add/mul contraction regardless of the contraction kind specified.  Repro (expected to find compares or mins in the output, but add/mul are generated instead):

```mlir
cat <<EOF | mlir-opt -convert-vector-to-llvm | grep cmp
#map0 = affine_map<(i, j, k) -> (i, k)>
#map1 = affine_map<(i, j, k) -> (k, j)>
#map2 = affine_map<(i, j, k) -> (i, j)> 

func.func @main() -> (i32) {
  %c0 = arith.constant 0 : i32
  %v0 = arith.constant dense<[[1., 2., 3., 4.], 
                              [5., 6., 7., 8.], 
                              [9., 10., 11., 12.]]> : vector<3x4xf32>

  %v1 = arith.constant dense<[[1., 2., 3.], 
                              [4., 5., 6.], 
                              [7., 8., 9.], 
                              [10., 11., 12.]]> : vector<4x3xf32>
  
  %v2 = arith.constant dense<[[0., 0., 0.], 
                              [0., 0., 0.], 
                              [0., 0., 0.]]> : vector<3x3xf32>

  %v3 = vector.contract {indexing_maps = [#map0, #map1, #map2], iterator_types = ["parallel", "parallel", "reduction"], kind = #vector.kind<minf>} %v0, %v1, %v2 : vector<3x4xf32>, vector<4x3xf32> into vector<3x3xf32>
  vector.print %v3 : vector<3x3xf32>
  return %c0 : i32
}
EOF
```

https://reviews.llvm.org/D136079 adds a stopgap, but a proper lowering may be desired.

On a side note, the modeling of contraction kind by a single selector isn't very clear to me. There are two primitive operations involved: per-element combination (multiplication) and accumulation (summation), which of them is being controlled by the kind?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVl1zozoM_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