[Mlir-commits] [mlir] [mlir] Don't hoist transfers from potentially zero trip loops (PR #112752)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Oct 17 10:40:58 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 87645e920528802fb1864e159da3d2be1b733432 ca0bc32f7d13628ae688cf1290cdc6db99dee73a --extensions cpp -- mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp b/mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
index f382b2c13b..92345e7695 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
@@ -213,40 +213,39 @@ void mlir::linalg::hoistRedundantVectorTransfers(Operation *root) {
     // a potentially zero trip count loop may cause a vector transfer to be
     // executed when it shouldn't be.
     llvm::DenseSet<LoopLikeOpInterface> definiteNonZeroTripCountLoops;
-    root->walk(
-        [&](LoopLikeOpInterface loopLike) {
-          std::optional<SmallVector<OpFoldResult>> lbs =
-              loopLike.getLoopLowerBounds();
-          std::optional<SmallVector<OpFoldResult>> ubs =
-              loopLike.getLoopUpperBounds();
-          // If loop bounds cannot be found, assume possibly zero trip count.
-          if (!lbs || !ubs) {
-            return;
-          }
-          // Otherwise, use ValueBounds to find the maximum lower bound and
-          // minimum upper bound. If the bounds are found, and maxLb is less
-          // than the minUb, then the loop will not have zero trip count.
-          for (auto [lb, ub] : llvm::zip_equal(lbs.value(), ubs.value())) {
-            FailureOr<int64_t> maxLb =
-                ValueBoundsConstraintSet::computeConstantBound(
-                    presburger::BoundType::UB, /*var=*/lb,
-                    /*stopCondition=*/nullptr, /*closedUB=*/true);
-            if (failed(maxLb)) {
-              return;
-            }
-            FailureOr<int64_t> minUb =
-                ValueBoundsConstraintSet::computeConstantBound(
-                    presburger::BoundType::LB, /*var=*/ub,
-                    /*stopCondition=*/nullptr);
-            if (failed(minUb)) {
-              return;
-            }
-            if (minUb.value() <= maxLb.value()) {
-              return;
-            }
-            definiteNonZeroTripCountLoops.insert(loopLike);
-          }
-        });
+    root->walk([&](LoopLikeOpInterface loopLike) {
+      std::optional<SmallVector<OpFoldResult>> lbs =
+          loopLike.getLoopLowerBounds();
+      std::optional<SmallVector<OpFoldResult>> ubs =
+          loopLike.getLoopUpperBounds();
+      // If loop bounds cannot be found, assume possibly zero trip count.
+      if (!lbs || !ubs) {
+        return;
+      }
+      // Otherwise, use ValueBounds to find the maximum lower bound and
+      // minimum upper bound. If the bounds are found, and maxLb is less
+      // than the minUb, then the loop will not have zero trip count.
+      for (auto [lb, ub] : llvm::zip_equal(lbs.value(), ubs.value())) {
+        FailureOr<int64_t> maxLb =
+            ValueBoundsConstraintSet::computeConstantBound(
+                presburger::BoundType::UB, /*var=*/lb,
+                /*stopCondition=*/nullptr, /*closedUB=*/true);
+        if (failed(maxLb)) {
+          return;
+        }
+        FailureOr<int64_t> minUb =
+            ValueBoundsConstraintSet::computeConstantBound(
+                presburger::BoundType::LB, /*var=*/ub,
+                /*stopCondition=*/nullptr);
+        if (failed(minUb)) {
+          return;
+        }
+        if (minUb.value() <= maxLb.value()) {
+          return;
+        }
+        definiteNonZeroTripCountLoops.insert(loopLike);
+      }
+    });
 
     root->walk([&](vector::TransferReadOp transferRead) {
       if (!isa<MemRefType>(transferRead.getShapedType()))

``````````

</details>


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


More information about the Mlir-commits mailing list