[Mlir-commits] [mlir] [mlir] Add `arith-int-range-narrowing` pass (PR #112404)
Ivan Butygin
llvmlistbot at llvm.org
Mon Nov 4 06:55:56 PST 2024
================
@@ -214,6 +455,32 @@ struct IntRangeOptimizationsPass
signalPassFailure();
}
};
+
+struct IntRangeNarrowingPass final
+ : arith::impl::ArithIntRangeNarrowingBase<IntRangeNarrowingPass> {
+ using ArithIntRangeNarrowingBase::ArithIntRangeNarrowingBase;
+
+ void runOnOperation() override {
+ Operation *op = getOperation();
+ MLIRContext *ctx = op->getContext();
+ DataFlowSolver solver;
+ solver.load<DeadCodeAnalysis>();
+ solver.load<IntegerRangeAnalysis>();
+ if (failed(solver.initializeAndRun(op)))
+ return signalPassFailure();
+
+ DataFlowListener listener(solver);
+
+ RewritePatternSet patterns(ctx);
+ populateIntRangeNarrowingPatterns(patterns, solver, bitwidthsSupported);
+
+ GreedyRewriteConfig config;
+ config.listener = &listener;
+
+ if (failed(applyPatternsAndFoldGreedily(op, std::move(patterns), config)))
+ signalPassFailure();
----------------
Hardcode84 wrote:
The problem is in code
```
func.func @test_add_cmpi() -> i1 {
...
%4 = arith.addi %0, %1 : index
%5 = arith.cmpi slt, %3, %4 : index
return %5 : i1
}
```
`arith.cmpi` must be matched before `arith.addi`
The missing folders is not a big problem by itself (and I'm planning to run these patterns in greedy driver anyway in prod), but it makes test code matching more annoying as trunc/ext casts are not removed.
https://github.com/llvm/llvm-project/pull/112404
More information about the Mlir-commits
mailing list