[Mlir-commits] [mlir] [MLIR][Presburger] Fix a bug with determinant of IntMatrix (PR #76622)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Dec 30 10:08:20 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: None (Abhinav271828)
<details>
<summary>Changes</summary>
IntMatrix determinant() had a bug where it would try to assign to a null pointer.
A check to avoid this case has been added.
---
Full diff: https://github.com/llvm/llvm-project/pull/76622.diff
2 Files Affected:
- (modified) mlir/lib/Analysis/Presburger/Matrix.cpp (+3)
- (modified) mlir/unittests/Analysis/Presburger/MatrixTest.cpp (+3)
``````````diff
diff --git a/mlir/lib/Analysis/Presburger/Matrix.cpp b/mlir/lib/Analysis/Presburger/Matrix.cpp
index 25300f84cfc047..1f1188c115a8b5 100644
--- a/mlir/lib/Analysis/Presburger/Matrix.cpp
+++ b/mlir/lib/Analysis/Presburger/Matrix.cpp
@@ -452,6 +452,9 @@ MPInt IntMatrix::determinant(IntMatrix *inverse) const {
if (detM == 0)
return MPInt(0);
+ if (!inverse)
+ return detM;
+
*inverse = IntMatrix(nRows, nColumns);
for (unsigned i = 0; i < nRows; i++)
for (unsigned j = 0; j < nColumns; j++)
diff --git a/mlir/unittests/Analysis/Presburger/MatrixTest.cpp b/mlir/unittests/Analysis/Presburger/MatrixTest.cpp
index e6e452790f82d1..103619518c15a2 100644
--- a/mlir/unittests/Analysis/Presburger/MatrixTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/MatrixTest.cpp
@@ -251,6 +251,9 @@ TEST(MatrixTest, computeHermiteNormalForm) {
}
TEST(MatrixTest, inverse) {
+ IntMatrix mat1 = makeIntMatrix(2, 2, {{2, 1}, {7, 0}});
+ EXPECT_EQ(mat1.determinant(), -7);
+
FracMatrix mat = makeFracMatrix(
2, 2, {{Fraction(2), Fraction(1)}, {Fraction(7), Fraction(0)}});
FracMatrix inverse = makeFracMatrix(
``````````
</details>
https://github.com/llvm/llvm-project/pull/76622
More information about the Mlir-commits
mailing list