[Mlir-commits] [mlir] [mlir] Allow folding dynamic full size subviews (PR #140619)

Han-Chung Wang llvmlistbot at llvm.org
Mon May 19 14:54:50 PDT 2025


================
@@ -3127,15 +3127,24 @@ static bool isTrivialSubViewOp(SubViewOp subViewOp) {
       }))
     return false;
 
-  // Check all size values are static and matches the (static) source shape.
+  // Check all size values match the source shape.
   ArrayRef<int64_t> sourceShape = subViewOp.getSourceType().getShape();
-  for (const auto &size : llvm::enumerate(mixedSizes)) {
-    std::optional<int64_t> intValue = getConstantIntValue(size.value());
-    if (!intValue || *intValue != sourceShape[size.index()])
-      return false;
+  if (llvm::all_of_zip(mixedSizes, sourceShape,
+                       [](OpFoldResult mixedSize, int64_t staticSize) {
+                         std::optional<int64_t> constSize =
+                             getConstantIntValue(mixedSize);
+                         return constSize.has_value() &&
+                                *constSize == staticSize;
----------------
hanhanW wrote:

I think you can use `isConstantIntValue`.

https://github.com/llvm/llvm-project/blob/a0c515a9ef3be780e2dfd64d86de9e401b137b28/mlir/include/mlir/Dialect/Utils/StaticValueUtils.h#L112-L113

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


More information about the Mlir-commits mailing list