diff --git a/mlir/lib/Analysis/Presburger/PresburgerSet.cpp b/mlir/lib/Analysis/Presburger/PresburgerSet.cpp --- a/mlir/lib/Analysis/Presburger/PresburgerSet.cpp +++ b/mlir/lib/Analysis/Presburger/PresburgerSet.cpp @@ -521,7 +521,7 @@ // When coalescing is successful, the contained IntegerPolyhedron is swapped // with the last element of `polyhedrons` and subsequently erased and // similarly for simplices. - for (unsigned i = 0; i < polyhedrons.size(); ++i) { + for (unsigned i = 0; i < polyhedrons.size();) { // TODO: This does some comparisons two times (index 0 with 1 and index 1 // with 0). diff --git a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp --- a/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp +++ b/mlir/unittests/Analysis/Presburger/PresburgerSetTest.cpp @@ -619,6 +619,17 @@ expectCoalesce(1, set); } +TEST(SetTest, coalesceDoubleIncrement) { + PresburgerSet set = parsePresburgerSetFromPolyStrings( + 1, { + "(x) : (x == 0)", + "(x) : (x - 2 == 0)", + "(x) : (x + 2 == 0)", + "(x) : (x - 2 >= 0, -x + 3 >= 0)", + }); + expectCoalesce(3, set); +} + static void expectComputedVolumeIsValidOverapprox(const PresburgerSet &set, Optional trueVolume,