Skip to content

Commit 0d793d4

Browse files
matthias-springertru
authored andcommitted
[mlir][DialectUtils] Fix div by zero crash (#153380)
1 parent 9a68897 commit 0d793d4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mlir/lib/Dialect/Utils/StaticValueUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ std::optional<int64_t> constantTripCount(OpFoldResult lb, OpFoldResult ub,
272272
if (!ubConstant)
273273
return std::nullopt;
274274
std::optional<int64_t> stepConstant = getConstantIntValue(step);
275-
if (!stepConstant)
275+
if (!stepConstant || *stepConstant == 0)
276276
return std::nullopt;
277277

278278
return llvm::divideCeilSigned(*ubConstant - *lbConstant, *stepConstant);

mlir/test/Dialect/SCF/canonicalize.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,3 +1925,16 @@ func.func @index_switch_fold_no_res() {
19251925

19261926
// CHECK-LABEL: func.func @index_switch_fold_no_res()
19271927
// CHECK-NEXT: "test.op"() : () -> ()
1928+
1929+
// -----
1930+
1931+
// CHECK-LABEL: func @scf_for_all_step_size_0()
1932+
// CHECK: scf.forall (%{{.*}}) = (0) to (1) step (0)
1933+
func.func @scf_for_all_step_size_0() {
1934+
%x = arith.constant 0 : index
1935+
scf.forall (%i, %j) = (0, 4) to (1, 5) step (%x, 8) {
1936+
vector.print %x : index
1937+
scf.forall.in_parallel {}
1938+
}
1939+
return
1940+
}

0 commit comments

Comments
 (0)