[Mlir-commits] [mlir] [mlir][Vector] Lower `vector.to_elements` to LLVM (PR #145766)

Jakub Kuderski llvmlistbot at llvm.org
Thu Jun 26 06:53:34 PDT 2025


================
@@ -1985,6 +1985,37 @@ struct VectorFromElementsLowering
   }
 };
 
+/// Conversion pattern for a `vector.to_elements`.
+struct VectorToElementsLowering
+    : public ConvertOpToLLVMPattern<vector::ToElementsOp> {
+  using ConvertOpToLLVMPattern::ConvertOpToLLVMPattern;
+
+  LogicalResult
+  matchAndRewrite(vector::ToElementsOp toElementsOp, OpAdaptor adaptor,
+                  ConversionPatternRewriter &rewriter) const override {
+    Location loc = toElementsOp.getLoc();
+    auto idxType = typeConverter->convertType(rewriter.getIndexType());
+    Value source = adaptor.getSource();
+
+    SmallVector<Value> results(toElementsOp->getNumResults());
+    for (auto [idx, element] : llvm::enumerate(toElementsOp.getElements())) {
+      // Create an extractelement operation only for results that are not dead.
+      if (!element.use_empty()) {
----------------
kuhar wrote:

nit: you can invert this check and `continue` instead to reduce nesting

https://github.com/llvm/llvm-project/pull/145766


More information about the Mlir-commits mailing list