Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 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
7 changes: 4 additions & 3 deletions mlir/include/mlir/Dialect/Arith/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ void populateUnsignedWhenEquivalentPatterns(RewritePatternSet &patterns,
/// Create a pass which do optimizations based on integer range analysis.
std::unique_ptr<Pass> createIntRangeOptimizationsPass();

/// Add patterns for integer bitwidth narrowing.
void populateArithIntNarrowingPatterns(RewritePatternSet &patterns,
const ArithIntNarrowingOptions &options);
/// Add patterns for int range based narrowing.
void populateIntRangeNarrowingPatterns(RewritePatternSet &patterns,
DataFlowSolver &solver,
ArrayRef<unsigned> bitwidthsSupported);

//===----------------------------------------------------------------------===//
// Registration
Expand Down
36 changes: 22 additions & 14 deletions mlir/include/mlir/Dialect/Arith/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ def ArithIntRangeOpts : Pass<"int-range-optimizations"> {
];
}

def ArithIntRangeNarrowing : Pass<"arith-int-range-narrowing"> {
let summary = "Reduce integer operations bitwidth based on integer range analysis";
let description = [{
This pass runs integer range analysis and tries to narrow arith ops to the
specified bitwidth based on its results.

`bitwidthsSupported` assumed to be not wider than `index` type.
TODO: get index width from DLTI.
}];

let options = [
ListOption<"bitwidthsSupported", "int-bitwidths-supported", "unsigned",
"Integer bitwidths supported">,
];

// Explicitly depend on "arith" because this pass could create operations in
// `arith` out of thin air in some cases.
let dependentDialects = [
"::mlir::arith::ArithDialect"
];
}

def ArithEmulateUnsupportedFloats : Pass<"arith-emulate-unsupported-floats"> {
let summary = "Emulate operations on unsupported floats with extf/truncf";
let description = [{
Expand Down Expand Up @@ -92,18 +114,4 @@ def ArithEmulateWideInt : Pass<"arith-emulate-wide-int"> {
let dependentDialects = ["vector::VectorDialect"];
}

def ArithIntNarrowing : Pass<"arith-int-narrowing"> {
let summary = "Reduce integer operation bitwidth";
let description = [{
Reduce bitwidths of integer types used in arith operations. This pass
prefers the narrowest available integer bitwidths that are guaranteed to
produce the same results.
}];
let dependentDialects = ["vector::VectorDialect"];
let options = [
ListOption<"bitwidthsSupported", "int-bitwidths-supported", "unsigned",
"Integer bitwidths supported">,
];
}

#endif // MLIR_DIALECT_ARITH_TRANSFORMS_PASSES
1 change: 0 additions & 1 deletion mlir/lib/Dialect/Arith/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ add_mlir_dialect_library(MLIRArithTransforms
EmulateWideInt.cpp
EmulateNarrowType.cpp
ExpandOps.cpp
IntNarrowing.cpp
IntRangeOptimizations.cpp
ReifyValueBounds.cpp
UnsignedWhenEquivalent.cpp
Expand Down
Loading