diff --git a/mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp b/mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp --- a/mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp +++ b/mlir/lib/Dialect/SCF/Utils/AffineCanonicalizationUtils.cpp @@ -169,7 +169,8 @@ Value iv, Value ub, Value step, bool insideLoop) { FlatAffineValueConstraints constraints; - constraints.appendDimVar({iv, ub, step}); + constraints.appendDimVar({iv}); + constraints.appendSymbolVar({ub, step}); if (auto constUb = getConstantIntValue(ub)) constraints.addBound(IntegerPolyhedron::EQ, 1, *constUb); if (auto constStep = getConstantIntValue(step)) diff --git a/mlir/test/Dialect/SCF/for-loop-peeling.mlir b/mlir/test/Dialect/SCF/for-loop-peeling.mlir --- a/mlir/test/Dialect/SCF/for-loop-peeling.mlir +++ b/mlir/test/Dialect/SCF/for-loop-peeling.mlir @@ -275,3 +275,20 @@ } return %r0 : i32 } + +// ----- + +// Make sure that there is no crash. + +// CHECK-LABEL: func @regression +func.func @regression(%arg0: memref, %arg1: index) { + %c0 = arith.constant 0 : index + %0 = affine.apply affine_map<()[s0] -> (s0 * s0)>()[%arg1] + scf.for %arg2 = %c0 to %0 step %arg1 { + // Step size is a symbol, so multiplication is OK. + %1 = affine.min affine_map<(d0)[s0] -> (s0, -d0 + s0 * s0)>(%arg2)[%arg1] + %2 = arith.index_cast %1 : index to i64 + memref.store %2, %arg0[] : memref + } + return +}