[mlir][arith] Expose dedicated API for expanding ceil/floor division
authorLei Zhang <antiagainst@gmail.com>
Fri, 7 Oct 2022 19:42:08 +0000 (19:42 +0000)
committerLei Zhang <antiagainst@google.com>
Fri, 7 Oct 2022 19:51:59 +0000 (19:51 +0000)
This allows more precise control over which patterns to pick to
expand arithmetic ops. Previously ceil/floor division epxansion
is only available together with various min/max op expansion.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D135479

mlir/include/mlir/Dialect/Arith/Transforms/Passes.h
mlir/lib/Dialect/Arith/Transforms/ExpandOps.cpp

index a987bcd..5e441a7 100644 (file)
@@ -31,10 +31,13 @@ std::unique_ptr<Pass> createConstantBufferizePass(uint64_t alignment = 0);
 void populateWideIntEmulationPatterns(WideIntEmulationConverter &typeConverter,
                                       RewritePatternSet &patterns);
 
-/// Add patterns to expand Arith ops for LLVM lowering.
+/// Add patterns to expand Arith ceil/floor division ops.
+void populateCeilFloorDivExpandOpsPatterns(RewritePatternSet &patterns);
+
+/// Add patterns to expand Arith ops.
 void populateArithExpandOpsPatterns(RewritePatternSet &patterns);
 
-/// Create a pass to legalize Arith ops for LLVM lowering.
+/// Create a pass to legalize Arith ops.
 std::unique_ptr<Pass> createArithExpandOpsPass();
 
 /// Create a pass to replace signed ops with unsigned ones where they are proven
index 5a1793a..1a5911c 100644 (file)
@@ -225,12 +225,17 @@ struct ArithExpandOpsPass
 
 } // namespace
 
+void mlir::arith::populateCeilFloorDivExpandOpsPatterns(
+    RewritePatternSet &patterns) {
+  patterns
+      .add<CeilDivSIOpConverter, CeilDivUIOpConverter, FloorDivSIOpConverter>(
+          patterns.getContext());
+}
+
 void mlir::arith::populateArithExpandOpsPatterns(RewritePatternSet &patterns) {
+  populateCeilFloorDivExpandOpsPatterns(patterns);
   // clang-format off
   patterns.add<
-    CeilDivSIOpConverter,
-    CeilDivUIOpConverter,
-    FloorDivSIOpConverter,
     MaxMinFOpConverter<MaxFOp, arith::CmpFPredicate::UGT>,
     MaxMinFOpConverter<MinFOp, arith::CmpFPredicate::ULT>,
     MaxMinIOpConverter<MaxSIOp, arith::CmpIPredicate::sgt>,