[all-commits] [llvm/llvm-project] 393a75: [mlir][Vector] Add constant folding for vector.fro...
Yang Bai via All-commits
all-commits at lists.llvm.org
Mon Jun 30 20:40:15 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 393a75ebb735191603be8065f7eb66850f1353ac
https://github.com/llvm/llvm-project/commit/393a75ebb735191603be8065f7eb66850f1353ac
Author: Yang Bai <baiyang0132 at gmail.com>
Date: 2025-06-30 (Mon, 30 Jun 2025)
Changed paths:
M mlir/lib/Dialect/Vector/IR/VectorOps.cpp
M mlir/test/Dialect/Vector/canonicalize.mlir
Log Message:
-----------
[mlir][Vector] Add constant folding for vector.from_elements operation (#145849)
### Summary
This PR adds a new folding pattern for **vector.from_elements** that
canonicalizes it to **arith.constant** when all input operands are
constants.
### Implementation Details
**Leverages FoldAdaptor capabilities**: Uses adaptor.getElements() to
access **pre-computed** constant attributes, avoiding redundant pattern
matching on operands.
### Example Transformation
```
Before:
%c0_i32 = arith.constant 0 : i32
%c1_i32 = arith.constant 1 : i32
%c2_i32 = arith.constant 2 : i32
%c3_i32 = arith.constant 3 : i32
%v = vector.from_elements %c0_i32, %c1_i32, %c2_i32, %c3_i32 : vector<2x2xi32>
After:
%v = arith.constant dense<[[0, 1], [2, 3]]> : vector<2x2xi32>
```
---------
Co-authored-by: Yang Bai <yangb at nvidia.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list