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

    <tr>
        <th>Summary</th>
        <td>
            [mlir][vector] Narrow-type-emulation - incorrect result
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          banach-space
      </td>
    </tr>
</table>

<pre>
    Hi,

I was experimenting with [the narrow type emulation](https://github.com/llvm/llvm-project/blob/main/mlir/lib/Dialect/Vector/Transforms/VectorEmulateNarrowType.cpp) and noticed that this "unaligned" example:
```mlir
func.func @experiment(%arg0: vector<4xi2>) {
    %src = memref.alloc() : memref<3x4xi2>
    %c0 = arith.constant 0 : index
    %c1 = arith.constant 1 : index
    vector.store %arg0, %src[%c0, %c1] : memref<3x4xi2>, vector<4xi2>
    return
}
```

is incorrectly rewritten as (note that the final index is `%c0`):
```bash
$ bin/mlir-opt --test-emulate-narrow-int="arith-compute-bitwidth=1 memref-load-bitwidth=8" file.mlir
  func.func @experiment(%arg0: vector<4xi2>) {
    %alloc = memref.alloc() : memref<3xi8>
    %0 = vector.bitcast %arg0 : vector<4xi2> to vector<1xi8>
    %c0 = arith.constant 0 : index
    vector.store %0, %alloc[%c0] : memref<3xi8>, vector<1xi8>
    return
  }
```

I think I know _what_ needs updating, so will try to fix it whenever I get a chance. Unless there are volunteers in the meantime ðŸ˜… 

-Andrzej
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyslVFvozgQxz-N8zICGRNIeOAhLRtdX-5p715XxgzBu8ZG9tCk9-lPhiTttj1pT1opioXxzPxn5sdYhqBPFrFmxQMrmo2caXC-bqWVakjCJBVuWte91H9oJh4ZPzB-eIKzDICXCb0e0ZK2JzhrGoAVDzQgWOm9OwO9TAg4zkaSdpYVDRP7gWgKLD8wcWTieNI0zG2q3MjE0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