<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/122942>122942</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir][presburger] "Isolated" local variables can produce crash or unexpected results in IntegerRelation/PresburgerRelation routines
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir:presburger
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
christopherbate
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
christopherbate
</td>
</tr>
</table>
<pre>
I've noticed an issue where "isolated" local variables can cause problems in the elimination of non-div locals (IntegerRelation -> PresburgerRelation) as well as in the set subtraction algorithm (`getSetDifference` in `PresburgerRelation.cpp`).
By "isolated" I mean that there is a local defined in the IntegerRelation system, but there may not be a constraint that links the local to other variables. This sounds contrived, but it can happen if a user constructs an IntegerRelation from an AffineMap where one of the domain variables is not used to calculate the range. Invoking `IntegerRelation::getRangeSet` would then turn all the domain variables into locals, resulting in a local which is not related to any other variable in the system.
If you then try to compute the "non-div local" representation, I noticed that the number of disjuncts can become much larger than if the local is eliminated (e.g. 2x for each unused local). Furthermore, I will sporadically run into an unreachable here https://github.com/llvm/llvm-project/blob/main/mlir/lib/Analysis/Presburger/Simplex.cpp#L1463. Will update this issue with a concise reproducer.
As a workaround, I added a routine to eliminate such locals whenever I construct an IntegerRelation. It doesn't look like any of the existing simplification routines in `IntegerRelation` know how to remove with such locals.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVV2v4jYT_jXmZrRRcCAcLrhg97xISG-lardSrx1nQmZx7MgfcPj31TiBQ2mrqldIwTPzzPNhqxDoZBF3Yv1VSKl7TyG6sUffqIhCSrF-X6gUe-d3L38uGtfedkchNxcE6yJpbEFZoBASwrVHjyCkpOCMitgKKcE4rQxclCfVGAyglQWtUkAYvWsMDgHIQuwR0NBAVkVyFlwH1tkvLV2mBgGEfDvaiCf039FMh76I6n_wq8fQJP_0XcgtqABXNIZ_5-4BI4TURK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