[Mlir-commits] [mlir] Lower affine modulo by powers of two using bitwise AND (PR #146311)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jun 30 00:57:28 PDT 2025


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 HEAD~1 HEAD --extensions cpp -- mlir/lib/Dialect/Affine/Utils/Utils.cpp
``````````

</details>

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

``````````diff
diff --git a/mlir/lib/Dialect/Affine/Utils/Utils.cpp b/mlir/lib/Dialect/Affine/Utils/Utils.cpp
index de9c78747..0cffe52dd 100644
--- a/mlir/lib/Dialect/Affine/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/Affine/Utils/Utils.cpp
@@ -81,21 +81,24 @@ public:
   ///             negative = a < 0 in
   ///         select negative, remainder + b, remainder.
   ///
-  /// Special case for power of 2: use bitwise AND (x & (n-1)) for non-negative x.
+  /// Special case for power of 2: use bitwise AND (x & (n-1)) for non-negative
+  /// x.
   Value visitModExpr(AffineBinaryOpExpr expr) {
     if (auto rhsConst = dyn_cast<AffineConstantExpr>(expr.getRHS())) {
       if (rhsConst.getValue() <= 0) {
         emitError(loc, "modulo by non-positive value is not supported");
         return nullptr;
       }
-      
-      // Special case: x mod n where n is a power of 2 can be optimized to x & (n-1)
+
+      // Special case: x mod n where n is a power of 2 can be optimized to x &
+      // (n-1)
       int64_t rhsValue = rhsConst.getValue();
       if (rhsValue > 0 && (rhsValue & (rhsValue - 1)) == 0) {
         auto lhs = visit(expr.getLHS());
         assert(lhs && "unexpected affine expr lowering failure");
-        
-        Value maskCst = builder.create<arith::ConstantIndexOp>(loc, rhsValue - 1);
+
+        Value maskCst =
+            builder.create<arith::ConstantIndexOp>(loc, rhsValue - 1);
         return builder.create<arith::AndIOp>(loc, lhs, maskCst);
       }
     }

``````````

</details>


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


More information about the Mlir-commits mailing list