Index: mlir/lib/IR/AffineExpr.cpp =================================================================== --- mlir/lib/IR/AffineExpr.cpp +++ mlir/lib/IR/AffineExpr.cpp @@ -601,7 +601,10 @@ return getAffineConstantExpr(lhsConst.getValue() * rhsConst.getValue(), lhs.getContext()); - assert(lhs.isSymbolicOrConstant() || rhs.isSymbolicOrConstant()); + // Even though it is not legal to multiply two dimensions it may happen as an + // intermediate state during composition. + if(!lhs.isSymbolicOrConstant() && !rhs.isSymbolicOrConstant()) + return nullptr; // Canonicalize the mul expression so that the constant/symbolic term is the // RHS. If both the lhs and rhs are symbolic, swap them if the lhs is a Index: mlir/test/Dialect/Affine/canonicalize.mlir =================================================================== --- mlir/test/Dialect/Affine/canonicalize.mlir +++ mlir/test/Dialect/Affine/canonicalize.mlir @@ -43,7 +43,8 @@ // CHECK-DAG: [[$MAP_mix_dims_and_symbols_e:#map[0-9]+]] = affine_map<()[s0, s1] -> ((s1 * 4 + s0 * 168 - 4) floordiv 3)> // Affine maps for test case: $symbolic_semi_affine -// CHECK-DAG: [[$symbolic_semi_affine:#map[0-9]+]] = affine_map<(d0)[s0] -> (d0 floordiv (s0 + 1))> +// CHECK-DAG: [[$symbolic_semi_affine_1:#map[0-9]+]] = affine_map<(d0)[s0] -> (d0 floordiv (s0 + 1))> +// CHECK-DAG: [[$symbolic_semi_affine_2:#map[0-9]+]] = affine_map<(d0)[s0] -> (d0 * (s0 + 1))> // CHECK-LABEL: func @compose_affine_maps_1dto2d_no_symbols() { func @compose_affine_maps_1dto2d_no_symbols() { @@ -382,8 +383,11 @@ affine.for %i0 = 1 to 100 { %1 = affine.apply affine_map<()[s0] -> (s0 + 1)> ()[%M] %2 = affine.apply affine_map<(d0)[s0] -> (d0 floordiv s0)> (%i0)[%1] - // CHECK-DAG: {{.*}} = affine.apply [[$symbolic_semi_affine]](%{{.*}})[%{{.*}}] + // CHECK-DAG: {{.*}} = affine.apply [[$symbolic_semi_affine_1]](%{{.*}})[%{{.*}}] store %f1, %A[%2] : memref + %3 = affine.apply affine_map<(d0)[s0] -> (d0 * s0)> (%i0)[%1] + // CHECK-DAG: {{.*}} = affine.apply [[$symbolic_semi_affine_2]](%{{.*}})[%{{.*}}] + store %f1, %A[%3] : memref } return }