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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] ConversionPatternRewriter::create<tensor::FromElementsOp> generates arith.constant operation
        </td>
    </tr>

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

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

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

<pre>
    Based on the llvmorg-14.0.6 branch, I modified the toy example in order to create a new `tensor.from_element` operation through the following code:

```
LogicalResult
  matchAndRewrite(Operation *op, ArrayRef<Value> operands,
                  ConversionPatternRewriter &rewriter) const final {
    auto loc = op->getLoc();
    mlir::Type elementType = FloatType::getF64(getContext());
    int dim0 = 2;
    int dim1 = 3; 
    SmallVector<Value, 8> extentValues; 

    // Note: get a ranked tensor type, with dim vector and elementType
    auto dataTypeA = mlir::RankedTensorType::get({dim0, dim1}, elementType); 

    // Note: arith::ConstantOp
    auto f64Zero = rewriter.create<arith::ConstantOp>( loc, rewriter.getFloatAttr(elementType, 0));
    for ( int i = 0; i < dim0 * dim1; ++i) { 
      /* code */
      extentValues.push_back(rewriter.create<arith::ConstantOp>(
            loc, rewriter.getFloatAttr(elementType, i))); 
    } 
    
    Value tensorA = rewriter.create<tensor::FromElementsOp>(loc, dataTypeA, extentValues);

    // ...

   return success();
}
```

However, it generates `%cst_12 = arith.constant dense<[[0.000000e+00, 1.000000e+00, 2.000000e+00], [3.000000e+00, 4.000000e+00, 5.000000e+00]]> : tensor<2x3xf64>
` instead. 

And I found it cannot be lowered by `mlir-opt --convert-arith-to-llvm`. Am I using the `create<T>` API in the wrong way?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVkuP4jgQ_jXhYhElccLjkEOARtNS786otzWHvbScxBDPODaynab591vlBEhDj3YGWWC77KqvvnqYUtenfMUsr4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