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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] `memref.store` and `vector.store` not working in `scf.for` in `mlir-vulkan-runner`
        </td>
    </tr>

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

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

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

<pre>
    I was writing an integration test with `mlir-vulkan-runner`. When I was initializing an input buffer using `memref.store` in an `scf.for` loop in the host function, I got an error that possibly resulted from `finalize-memref-to-llvm` in the pass pipeline of `mlir-vulkan-runner` (https://github.com/llvm/llvm-project/blob/main/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp#L78). I also tried using `vector.store` instead but still got the same error. 
```
error: LLVM Translation failed for operation: builtin.unrealized_conversion_cast
Error: could not convert to LLVM IR
```

The host function is:
```
func.func @main() {
  // Allocate 3 buffers.
  %in_buf = memref.alloc() : memref<128xi32>
 %out_buf = memref.alloc() : memref<1xi32>
  %total_count_buf = memref.alloc() : memref<1xi32>

  // Constants.
  %cst0 = arith.constant 0 : i32
  %idx0 = arith.constant 0 : index
  %idx1 = arith.constant 1 : index
  %idx32 = arith.constant 32 : index
  %idx64 = arith.constant 64 : index
  %idx65 = arith.constant 65 : index
 %idx128 = arith.constant 128 : index

  // Initialize input buffer.
 // The input will be [0, 1, ..., 62, 63, 63, 62, ..., 1, 0]
  scf.for %iter = %idx0 to %idx64 step %idx1 {
    %iter_i32 = index.castu %iter : index to i32
    memref.store %iter_i32, %in_buf[%iter] : memref<128xi32>
  }
  %cst127 = arith.constant 127 : i32
  scf.for %iter = %idx65 to %idx128 step %idx1 {
    %iter_i32 = index.castu %iter : index to i32
    %elem = arith.subi %cst127, %iter_i32 : i32
 memref.store %elem, %in_buf[%iter] : memref<128xi32>
  }

  //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