[Mlir-commits] [mlir] [mlir] IntRangeNarrowing: Narrow loop induction variables. (PR #175455)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Jan 11 12:27:10 PST 2026


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 origin/main HEAD --extensions cpp,h -- mlir/include/mlir/Dialect/Arith/Transforms/Passes.h mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp mlir/lib/Dialect/SCF/IR/SCF.cpp mlir/lib/Interfaces/LoopLikeInterface.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

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

``````````diff
diff --git a/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp b/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
index 01b8ed7cc..d46b88824 100644
--- a/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/IntRangeOptimizations.cpp
@@ -564,17 +564,22 @@ struct NarrowLoopBounds final : OpInterfaceRewritePattern<LoopLikeOpInterface> {
 
         // Additional check: ensure indVar + step doesn't overflow.
         // During loop increment, we compute iv_next = iv_current + step in the
-        // narrowed type. If this overflows, the loop behavior becomes incorrect.
-        // We must check both signed and unsigned ranges since we don't know
-        // whether the loop semantics treat values as signed or unsigned.
+        // narrowed type. If this overflows, the loop behavior becomes
+        // incorrect. We must check both signed and unsigned ranges since we
+        // don't know whether the loop semantics treat values as signed or
+        // unsigned.
         unsigned srcWidth = lbRange.smin().getBitWidth();
         unsigned removedWidth = srcWidth - targetBitwidth;
 
         // Check that max(indVar) + step fits in the target type.
-        APInt indVarPlusStepSmin = indVarRange.smin().sadd_sat(stepRange.smin());
-        APInt indVarPlusStepSmax = indVarRange.smax().sadd_sat(stepRange.smax());
-        APInt indVarPlusStepUmin = indVarRange.umin().uadd_sat(stepRange.umin());
-        APInt indVarPlusStepUmax = indVarRange.umax().uadd_sat(stepRange.umax());
+        APInt indVarPlusStepSmin =
+            indVarRange.smin().sadd_sat(stepRange.smin());
+        APInt indVarPlusStepSmax =
+            indVarRange.smax().sadd_sat(stepRange.smax());
+        APInt indVarPlusStepUmin =
+            indVarRange.umin().uadd_sat(stepRange.umin());
+        APInt indVarPlusStepUmax =
+            indVarRange.umax().uadd_sat(stepRange.umax());
 
         bool indVarPlusStepFitsSigned =
             indVarPlusStepSmin.getNumSignBits() >= (removedWidth + 1) &&

``````````

</details>


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


More information about the Mlir-commits mailing list