[Mlir-commits] [mlir] [mlir][memref] Refactor `ViewOpShapeFolder` (PR #176567)

Jakub Kuderski llvmlistbot at llvm.org
Sat Jan 17 07:02:57 PST 2026


================
@@ -3763,71 +3763,69 @@ OpFoldResult ViewOp::fold(FoldAdaptor adaptor) {
 }
 
 namespace {
+/// Given a memref type and a range of values that defines its dynamic
+/// dimension sizes, turn all dynamic sizes that have a constant value into
+/// static dimension sizes.
+static MemRefType
+foldDynamicToStaticDimSizes(MemRefType type, ValueRange dynamicSizes,
+                            SmallVector<Value> &foldedDynamicSizes) {
+  SmallVector<int64_t> staticShape(type.getShape());
+  assert(type.getNumDynamicDims() == dynamicSizes.size() &&
+         "incorrect number of dynamic sizes");
+
+  // Compute new static and dynamic sizes.
+  unsigned ctr = 0;
+  for (int64_t i = 0, e = type.getRank(); i < e; ++i) {
+    if (type.isDynamicDim(i)) {
+      Value dynamicSize = dynamicSizes[ctr++];
+      std::optional<int64_t> cst = getConstantIntValue(dynamicSize);
+      if (cst.has_value()) {
----------------
kuhar wrote:

```suggestion
      if (std::optional<int64_t> cst = getConstantIntValue(dynamicSize)) {
```

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


More information about the Mlir-commits mailing list