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
15 changes: 15 additions & 0 deletions mlir/lib/Dialect/Arith/IR/ValueBoundsOpInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ struct MulIOpInterface
}
};

struct FloorDivSIOpInterface
: public ValueBoundsOpInterface::ExternalModel<FloorDivSIOpInterface,
FloorDivSIOp> {
void populateBoundsForIndexValue(Operation *op, Value value,
ValueBoundsConstraintSet &cstr) const {
auto divSIOp = cast<FloorDivSIOp>(op);
assert(value == divSIOp.getResult() && "invalid value");

AffineExpr lhs = cstr.getExpr(divSIOp.getLhs());
AffineExpr rhs = cstr.getExpr(divSIOp.getRhs());
cstr.bound(value) == lhs.floorDiv(rhs);
}
};

struct SelectOpInterface
: public ValueBoundsOpInterface::ExternalModel<SelectOpInterface,
SelectOp> {
Expand Down Expand Up @@ -157,6 +171,7 @@ void mlir::arith::registerValueBoundsOpInterfaceExternalModels(
arith::ConstantOp::attachInterface<arith::ConstantOpInterface>(*ctx);
arith::SubIOp::attachInterface<arith::SubIOpInterface>(*ctx);
arith::MulIOp::attachInterface<arith::MulIOpInterface>(*ctx);
arith::FloorDivSIOp::attachInterface<arith::FloorDivSIOpInterface>(*ctx);
arith::SelectOp::attachInterface<arith::SelectOpInterface>(*ctx);
});
}
24 changes: 24 additions & 0 deletions mlir/test/Dialect/Arith/value-bounds-op-interface-impl.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ func.func @arith_muli_non_pure(%a: index, %b: index) -> index {

// -----

// CHECK: #[[$map:.*]] = affine_map<()[s0] -> (s0 floordiv 5)>
// CHECK-LABEL: func @arith_floordivsi(
// CHECK-SAME: %[[a:.*]]: index
// CHECK: %[[apply:.*]] = affine.apply #[[$map]]()[%[[a]]]
// CHECK: return %[[apply]]
func.func @arith_floordivsi(%a: index) -> index {
%0 = arith.constant 5 : index
%1 = arith.floordivsi %a, %0 : index
%2 = "test.reify_bound"(%1) : (index) -> (index)
return %2 : index
}

// -----

func.func @arith_floordivsi_non_pure(%a: index, %b: index) -> index {
%0 = arith.floordivsi %a, %b : index
// Semi-affine expressions (such as "symbol * symbol") are not supported.
// expected-error @below{{could not reify bound}}
%1 = "test.reify_bound"(%0) : (index) -> (index)
return %1 : index
}

// -----

// CHECK-LABEL: func @arith_const()
// CHECK: %[[c5:.*]] = arith.constant 5 : index
// CHECK: %[[c5:.*]] = arith.constant 5 : index
Expand Down