[Mlir-commits] [mlir] [MLIR][Presburger] Fix stale pivot in Smith normal form (PR #189789)

Yue Huang llvmlistbot at llvm.org
Tue Mar 31 20:43:03 PDT 2026


https://github.com/AdUhTkJm created https://github.com/llvm/llvm-project/pull/189789

The pivot used to fix divisibility in Smith normal form is stale. This will not affect correctness, but can lower efficiency since the outer loop will be executed more times.

Thanks for @benquike of discovering this.

>From 563e15417f22c0acca5701c97750939a23f851a3 Mon Sep 17 00:00:00 2001
From: Yue Huang <yh548 at cam.ac.uk>
Date: Wed, 1 Apr 2026 11:39:00 +0800
Subject: [PATCH] [MLIR][Presburger] Fix stale pivot in Smith normal form

---
 mlir/lib/Analysis/Presburger/Matrix.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mlir/lib/Analysis/Presburger/Matrix.cpp b/mlir/lib/Analysis/Presburger/Matrix.cpp
index 6ea04543146b7..94e9eb5792dab 100644
--- a/mlir/lib/Analysis/Presburger/Matrix.cpp
+++ b/mlir/lib/Analysis/Presburger/Matrix.cpp
@@ -653,8 +653,6 @@ IntMatrix::computeSmithNormalForm() const {
         u.negateRow(i);
       }
 
-      DynamicAPInt pivot = d(i, i);
-
       // Clear other entries in row i and column i with Euclid's algorithm.
       for (unsigned r = i + 1; r < numRows; ++r) {
         while (d(r, i) != 0) {
@@ -684,7 +682,7 @@ IntMatrix::computeSmithNormalForm() const {
         }
       }
 
-      if (auto row = findNonMultipleRow(d, i + 1, pivot)) {
+      if (auto row = findNonMultipleRow(d, i + 1, d(i, i))) {
         // Add the row (r) to row i. This brings d(r, c) into the i-th row,
         // creating a new value at d(i, c) that will be used to reduce the
         // pivot size.



More information about the Mlir-commits mailing list