@@ -102,6 +102,23 @@ IntegerRelation::findIntegerLexMin() const {
102
102
return maybeLexMin;
103
103
}
104
104
105
+ static bool rangeIsZero (ArrayRef<int64_t > range) {
106
+ return llvm::all_of (range, [](int64_t x) { return x == 0 ; });
107
+ }
108
+
109
+ void removeConstraintsInvolvingIdRange (IntegerRelation &poly, unsigned begin,
110
+ unsigned count) {
111
+ // We loop until i > 0 and index into i - 1 to avoid sign issues.
112
+ //
113
+ // We iterate backwards so that whether we remove constraint i - 1 or not, the
114
+ // next constraint to be tested is always i - 2.
115
+ for (unsigned i = poly.getNumEqualities (); i > 0 ; i--)
116
+ if (!rangeIsZero (poly.getEquality (i - 1 ).slice (begin, count)))
117
+ poly.removeEquality (i - 1 );
118
+ for (unsigned i = poly.getNumInequalities (); i > 0 ; i--)
119
+ if (!rangeIsZero (poly.getInequality (i - 1 ).slice (begin, count)))
120
+ poly.removeInequality (i - 1 );
121
+ }
105
122
unsigned IntegerRelation::insertId (IdKind kind, unsigned pos, unsigned num) {
106
123
assert (pos <= getNumIdKind (kind));
107
124
@@ -561,33 +578,6 @@ Matrix IntegerRelation::getBoundedDirections() const {
561
578
return dirs;
562
579
}
563
580
564
- bool eqInvolvesSuffixDims (const IntegerRelation &rel, unsigned eqIndex,
565
- unsigned numDims) {
566
- for (unsigned e = rel.getNumIds (), j = e - numDims; j < e; ++j)
567
- if (rel.atEq (eqIndex, j) != 0 )
568
- return true ;
569
- return false ;
570
- }
571
- bool ineqInvolvesSuffixDims (const IntegerRelation &rel, unsigned ineqIndex,
572
- unsigned numDims) {
573
- for (unsigned e = rel.getNumIds (), j = e - numDims; j < e; ++j)
574
- if (rel.atIneq (ineqIndex, j) != 0 )
575
- return true ;
576
- return false ;
577
- }
578
-
579
- void removeConstraintsInvolvingSuffixDims (IntegerRelation &rel,
580
- unsigned unboundedDims) {
581
- // We iterate backwards so that whether we remove constraint i - 1 or not, the
582
- // next constraint to be tested is always i - 2.
583
- for (unsigned i = rel.getNumEqualities (); i > 0 ; i--)
584
- if (eqInvolvesSuffixDims (rel, i - 1 , unboundedDims))
585
- rel.removeEquality (i - 1 );
586
- for (unsigned i = rel.getNumInequalities (); i > 0 ; i--)
587
- if (ineqInvolvesSuffixDims (rel, i - 1 , unboundedDims))
588
- rel.removeInequality (i - 1 );
589
- }
590
-
591
581
bool IntegerRelation::isIntegerEmpty () const {
592
582
return !findIntegerSample ().hasValue ();
593
583
}
@@ -671,7 +661,8 @@ Optional<SmallVector<int64_t, 8>> IntegerRelation::findIntegerSample() const {
671
661
IntegerRelation boundedSet (transformedSet);
672
662
unsigned numBoundedDims = result.first ;
673
663
unsigned numUnboundedDims = getNumIds () - numBoundedDims;
674
- removeConstraintsInvolvingSuffixDims (boundedSet, numUnboundedDims);
664
+ removeConstraintsInvolvingIdRange (boundedSet, numBoundedDims,
665
+ numUnboundedDims);
675
666
boundedSet.removeIdRange (numBoundedDims, boundedSet.getNumIds ());
676
667
677
668
// 3) Try to obtain a sample from the bounded set.
0 commit comments