@@ -855,8 +855,7 @@ static AffineExpr simplifyFloorDiv(AffineExpr lhs, AffineExpr rhs) {
855
855
auto lhsConst = dyn_cast<AffineConstantExpr>(lhs);
856
856
auto rhsConst = dyn_cast<AffineConstantExpr>(rhs);
857
857
858
- // mlir floordiv by zero or negative numbers is undefined and preserved as is.
859
- if (!rhsConst || rhsConst.getValue () < 1 )
858
+ if (!rhsConst || rhsConst.getValue () == 0 )
860
859
return nullptr ;
861
860
862
861
if (lhsConst) {
@@ -875,12 +874,12 @@ static AffineExpr simplifyFloorDiv(AffineExpr lhs, AffineExpr rhs) {
875
874
if (rhsConst == 1 )
876
875
return lhs;
877
876
878
- // Simplify (expr * const ) floordiv divConst when expr is known to be a
879
- // multiple of divConst .
877
+ // Simplify ` (expr * lrhs ) floordiv rhsConst` when `lrhs` is known to be a
878
+ // multiple of `rhsConst` .
880
879
auto lBin = dyn_cast<AffineBinaryOpExpr>(lhs);
881
880
if (lBin && lBin.getKind () == AffineExprKind::Mul) {
882
881
if (auto lrhs = dyn_cast<AffineConstantExpr>(lBin.getRHS ())) {
883
- // rhsConst is known to be a positive constant.
882
+ // ` rhsConst` is known to be a nonzero constant.
884
883
if (lrhs.getValue () % rhsConst.getValue () == 0 )
885
884
return lBin.getLHS () * (lrhs.getValue () / rhsConst.getValue ());
886
885
}
@@ -891,7 +890,7 @@ static AffineExpr simplifyFloorDiv(AffineExpr lhs, AffineExpr rhs) {
891
890
if (lBin && lBin.getKind () == AffineExprKind::Add) {
892
891
int64_t llhsDiv = lBin.getLHS ().getLargestKnownDivisor ();
893
892
int64_t lrhsDiv = lBin.getRHS ().getLargestKnownDivisor ();
894
- // rhsConst is known to be a positive constant.
893
+ // rhsConst is known to be a nonzero constant.
895
894
if (llhsDiv % rhsConst.getValue () == 0 ||
896
895
lrhsDiv % rhsConst.getValue () == 0 )
897
896
return lBin.getLHS ().floorDiv (rhsConst.getValue ()) +
@@ -918,7 +917,7 @@ static AffineExpr simplifyCeilDiv(AffineExpr lhs, AffineExpr rhs) {
918
917
auto lhsConst = dyn_cast<AffineConstantExpr>(lhs);
919
918
auto rhsConst = dyn_cast<AffineConstantExpr>(rhs);
920
919
921
- if (!rhsConst || rhsConst.getValue () < 1 )
920
+ if (!rhsConst || rhsConst.getValue () == 0 )
922
921
return nullptr ;
923
922
924
923
if (lhsConst) {
@@ -937,12 +936,12 @@ static AffineExpr simplifyCeilDiv(AffineExpr lhs, AffineExpr rhs) {
937
936
if (rhsConst.getValue () == 1 )
938
937
return lhs;
939
938
940
- // Simplify (expr * const ) ceildiv divConst when const is known to be a
941
- // multiple of divConst .
939
+ // Simplify ` (expr * lrhs ) ceildiv rhsConst` when `lrhs` is known to be a
940
+ // multiple of `rhsConst` .
942
941
auto lBin = dyn_cast<AffineBinaryOpExpr>(lhs);
943
942
if (lBin && lBin.getKind () == AffineExprKind::Mul) {
944
943
if (auto lrhs = dyn_cast<AffineConstantExpr>(lBin.getRHS ())) {
945
- // rhsConst is known to be a positive constant.
944
+ // ` rhsConst` is known to be a nonzero constant.
946
945
if (lrhs.getValue () % rhsConst.getValue () == 0 )
947
946
return lBin.getLHS () * (lrhs.getValue () / rhsConst.getValue ());
948
947
}
0 commit comments