Skip to content

Commit 2fcdaba

Browse files
[mlir][DialectUtils] Fix div by zero crash (llvm#153380)
1 parent 10a6fd7 commit 2fcdaba

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
@@ -276,7 +276,7 @@ std::optional<int64_t> constantTripCount(OpFoldResult lb, OpFoldResult ub,
276276
if (!ubConstant)
277277
return std::nullopt;
278278
std::optional<int64_t> stepConstant = getConstantIntValue(step);
279-
if (!stepConstant)
279+
if (!stepConstant || *stepConstant == 0)
280280
return std::nullopt;
281281

282282
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
@@ -1912,3 +1912,16 @@ func.func @index_switch_fold_no_res() {
19121912

19131913
// CHECK-LABEL: func.func @index_switch_fold_no_res()
19141914
// CHECK-NEXT: "test.op"() : () -> ()
1915+
1916+
// -----
1917+
1918+
// CHECK-LABEL: func @scf_for_all_step_size_0()
1919+
// CHECK: scf.forall (%{{.*}}) = (0) to (1) step (0)
1920+
func.func @scf_for_all_step_size_0() {
1921+
%x = arith.constant 0 : index
1922+
scf.forall (%i, %j) = (0, 4) to (1, 5) step (%x, 8) {
1923+
vector.print %x : index
1924+
scf.forall.in_parallel {}
1925+
}
1926+
return
1927+
}

0 commit comments

Comments
 (0)