Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Shape/IR/Shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ OpFoldResult DivOp::fold(FoldAdaptor adaptor) {
if (!lhs)
return nullptr;
auto rhs = llvm::dyn_cast_if_present<IntegerAttr>(adaptor.getRhs());
if (!rhs)
if (!rhs || rhs.getValue().isZero())
return nullptr;

// Division in APInt does not follow floor(lhs, rhs) when the result is
Expand Down
13 changes: 13 additions & 0 deletions mlir/test/Dialect/Shape/fold-div.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Bug: #131279
// RUN: mlir-opt --test-scf-pipelining %s | FileCheck %s
// CHECK: fold_div_index_neg_rhs
// CHECK-NEXT: %c0 = arith.constant 0 : index
// CHECK-NEXT: %0 = shape.div %c0, %c0 : index, index -> index
// CHECK-NEXT: return %0 : index
module {
func.func @fold_div_index_neg_rhs() -> index {
%c0 = arith.constant 0 : index
%0 = shape.div %c0, %c0 : index, index -> index
return %0 : index
}
}