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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Inconsistent results for tensor.from_elements
        </td>
    </tr>

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

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

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

<pre>
    I have the following MLIR program:
test.mlir:
```
module {
 func.func @tensor_i1(%arg0: tensor<?xi1>) -> i1 {
    %idx0 = index.constant 0
    %idx1 = index.constant 1
    %false = arith.constant false
    %dim = tensor.dim %arg0, %idx0 : tensor<?xi1>
 %0 = scf.for %arg1 = %idx0 to %dim step %idx1 iter_args(%arg2 = %false) -> (i1) {
      %extracted = tensor.extract %arg0[%arg1] : tensor<?xi1>
 vector.print %extracted : i1
      %1 = arith.addi %arg2, %extracted : i1
      scf.yield %1 : i1
    }
    return %0 : i1
  }
 func.func private @func1() -> f32{

    %true_6 = arith.constant true
    %false_7 = arith.constant false
    %false_8 = arith.constant false
    %false_9 = arith.constant false
    %true_10 = arith.constant true
    %from_elements = tensor.from_elements %true_6, %false_7, %false_8, %false_9, %true_10 : tensor<5xi1>
    %cast_158 = tensor.cast %from_elements : tensor<5xi1> to tensor<?xi1>
    %214 = call @tensor_i1(%cast_158) : (tensor<?xi1>) -> i1
    
    %1 = arith.sitofp %214 : i1 to f32
    vector.print %214 : i1
    return %1 : f32
 }
}
```
When I ran ```/data/tmp/v1102/llvm-project/build/bin/mlir-opt --test-linalg-decompose-ops=remove-dead-args-and-results --one-shot-bufferize="dialect-filter=tensor,linalg,bufferization" --canonicalize --one-shot-bufferize="dialect-filter=arith" --convert-arith-to-llvm --expand-strided-metadata --func-bufferize --one-shot-bufferize="dialect-filter=tensor" --convert-index-to-llvm --convert-vector-to-llvm --finalize-memref-to-llvm --convert-scf-to-cf --convert-func-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1102/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1102/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1102/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
1
0
0
0
1
0
0.000000e+00
```
However, when I ran ```/data/tmp/v1102/llvm-project/build/bin/mlir-opt --test-linalg-decompose-ops=remove-dead-args-and-results --one-shot-bufferize="dialect-filter=tensor,linalg,bufferization" --canonicalize --one-shot-bufferize="dialect-filter=arith" --convert-arith-to-llvm --test-linalg-transform-patterns=test-patterns --expand-strided-metadata --func-bufferize --one-shot-bufferize="dialect-filter=tensor" --convert-index-to-llvm --convert-vector-to-llvm --finalize-memref-to-llvm --convert-scf-to-cf --convert-func-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1102/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1102/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1102/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got inconsistent results over multiple runs.

The above two results seem to be inconsistent. I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused these results.

My git version is 33bdb53d864e3e244d8fd5649062f17b7d4c958d.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV09v27gT_TT0ZUBBoiRbPviQxDV-AX69LBbYo0GJI5kFRQok5ST99Avqjy0nbtB2rw0C2xwO3zyO3oxI7pxsNOKO5I8k369470_G7l64bt6Mbr4lfFUa8bZ7hhM_I_gTQm2UMi9SN_D1_89_QWdNY3lL0gcS70n84NH5qFXSXixkHU__w7A1olcIZPM4jqHudRWFDyBZ7FE7Y48yIawgLOe2iUn6AKOZpE8kPbzKhKRfCNsCJekXkMkCCwAIy6V4jYGke5Ba4GtUGe081x7i917JPa_kxqvmyuHgxq30p6vbMHHjKmQ7OI5ko2E4bYE9LXjd3c4IRFg-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