@@ -986,18 +986,9 @@ static AffineExpr getSemiAffineExprFromFlatForm(ArrayRef<int64_t> flatExprs,
986
986
// constant coefficient corresponding to the indices in `coefficients` map,
987
987
// and affine expression corresponding to indices in `indexToExprMap` map.
988
988
989
- for (unsigned j = 0 ; j < numDims; ++j) {
990
- if (flatExprs[j] == 0 )
991
- continue ;
992
- // For dimensional expressions we set the index as <position number of the
993
- // dimension, 0>, as we want dimensional expressions to appear before
994
- // symbolic ones and products of dimensional and symbolic expressions
995
- // having the dimension with the same position number.
996
- std::pair<unsigned , signed > indexEntry (j, -1 );
997
- addEntry (indexEntry, flatExprs[j], getAffineDimExpr (j, context));
998
- }
999
989
// Ensure we do not have duplicate keys in `indexToExpr` map.
1000
- unsigned offset = 0 ;
990
+ unsigned offsetSym = 0 ;
991
+ signed offsetDim = -1 ;
1001
992
for (unsigned j = numDims; j < numDims + numSymbols; ++j) {
1002
993
if (flatExprs[j] == 0 )
1003
994
continue ;
@@ -1006,7 +997,7 @@ static AffineExpr getSemiAffineExprFromFlatForm(ArrayRef<int64_t> flatExprs,
1006
997
// as we want symbolic expressions with the same positional number to
1007
998
// appear after dimensional expressions having the same positional number.
1008
999
std::pair<unsigned , signed > indexEntry (
1009
- j - numDims, std::max (numDims, numSymbols) + offset ++);
1000
+ j - numDims, std::max (numDims, numSymbols) + offsetSym ++);
1010
1001
addEntry (indexEntry, flatExprs[j],
1011
1002
getAffineSymbolExpr (j - numDims, context));
1012
1003
}
@@ -1038,13 +1029,13 @@ static AffineExpr getSemiAffineExprFromFlatForm(ArrayRef<int64_t> flatExprs,
1038
1029
// constructing. When rhs is constant, we place 0 in place of keyB.
1039
1030
if (lhs.isa <AffineDimExpr>()) {
1040
1031
lhsPos = lhs.cast <AffineDimExpr>().getPosition ();
1041
- std::pair<unsigned , signed > indexEntry (lhsPos, - 1 );
1032
+ std::pair<unsigned , signed > indexEntry (lhsPos, offsetDim-- );
1042
1033
addEntry (indexEntry, flatExprs[numDims + numSymbols + it.index ()],
1043
1034
expr);
1044
1035
} else {
1045
1036
lhsPos = lhs.cast <AffineSymbolExpr>().getPosition ();
1046
1037
std::pair<unsigned , signed > indexEntry (
1047
- lhsPos, std::max (numDims, numSymbols) + offset ++);
1038
+ lhsPos, std::max (numDims, numSymbols) + offsetSym ++);
1048
1039
addEntry (indexEntry, flatExprs[numDims + numSymbols + it.index ()],
1049
1040
expr);
1050
1041
}
@@ -1066,12 +1057,23 @@ static AffineExpr getSemiAffineExprFromFlatForm(ArrayRef<int64_t> flatExprs,
1066
1057
lhsPos = lhs.cast <AffineSymbolExpr>().getPosition ();
1067
1058
rhsPos = rhs.cast <AffineSymbolExpr>().getPosition ();
1068
1059
std::pair<unsigned , signed > indexEntry (
1069
- lhsPos, std::max (numDims, numSymbols) + offset ++);
1060
+ lhsPos, std::max (numDims, numSymbols) + offsetSym ++);
1070
1061
addEntry (indexEntry, flatExprs[numDims + numSymbols + it.index ()], expr);
1071
1062
}
1072
1063
addedToMap[it.index ()] = true ;
1073
1064
}
1074
1065
1066
+ for (unsigned j = 0 ; j < numDims; ++j) {
1067
+ if (flatExprs[j] == 0 )
1068
+ continue ;
1069
+ // For dimensional expressions we set the index as <position number of the
1070
+ // dimension, 0>, as we want dimensional expressions to appear before
1071
+ // symbolic ones and products of dimensional and symbolic expressions
1072
+ // having the dimension with the same position number.
1073
+ std::pair<unsigned , signed > indexEntry (j, offsetDim--);
1074
+ addEntry (indexEntry, flatExprs[j], getAffineDimExpr (j, context));
1075
+ }
1076
+
1075
1077
// Constructing the simplified semi-affine sum of product/division/mod
1076
1078
// expression from the flattened form in the desired sorted order of indices
1077
1079
// of the various individual product/division/mod expressions.
0 commit comments