Skip to content

Commit 340f06a

Browse files
authored
Fix: bail out when divisor is zero (#133518)
Fixes: #131279
1 parent efca37f commit 340f06a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mlir/lib/Dialect/Shape/IR/Shape.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ OpFoldResult DivOp::fold(FoldAdaptor adaptor) {
11241124
if (!lhs)
11251125
return nullptr;
11261126
auto rhs = llvm::dyn_cast_if_present<IntegerAttr>(adaptor.getRhs());
1127-
if (!rhs)
1127+
if (!rhs || rhs.getValue().isZero())
11281128
return nullptr;
11291129

11301130
// Division in APInt does not follow floor(lhs, rhs) when the result is

mlir/test/Dialect/Shape/fold-div.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Bug: #131279
2+
// RUN: mlir-opt --test-scf-pipelining %s | FileCheck %s
3+
// CHECK: fold_div_index_neg_rhs
4+
// CHECK-NEXT: %c0 = arith.constant 0 : index
5+
// CHECK-NEXT: %0 = shape.div %c0, %c0 : index, index -> index
6+
// CHECK-NEXT: return %0 : index
7+
module {
8+
func.func @fold_div_index_neg_rhs() -> index {
9+
%c0 = arith.constant 0 : index
10+
%0 = shape.div %c0, %c0 : index, index -> index
11+
return %0 : index
12+
}
13+
}

0 commit comments

Comments
 (0)