[Mlir-commits] [mlir] [mlir][vector]add foldConstantOp fold function and apply it to extractOp and insertOp. (PR #124399)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Sun Jan 26 00:34:09 PST 2025
================
@@ -1977,6 +1977,48 @@ static Value foldScalarExtractFromFromElements(ExtractOp extractOp) {
return fromElementsOp.getElements()[flatIndex];
}
+// If the dynamic operands of `extractOp` or `insertOp` is result of
+// `constantOp`, then fold it.
+template <typename T>
+static LogicalResult foldConstantOp(T op, SmallVectorImpl<Value> &operands) {
+ auto staticPosition = op.getStaticPosition().vec();
+ OperandRange dynamicPosition = op.getDynamicPosition();
+
+ // If the dynamic operands is empty, it is returned directly.
+ if (!dynamicPosition.size())
+ return failure();
+ unsigned index = 0;
+
+ // `opChange` is a flog. If it is true, it means to update `op` in place.
----------------
ftynse wrote:
```suggestion
// `opChange` is a flag. If it is true, it means to update `op` in place.
```
https://github.com/llvm/llvm-project/pull/124399
More information about the Mlir-commits
mailing list