21 #define GEN_PASS_DEF_ARITHUNSIGNEDWHENEQUIVALENT
22 #include "mlir/Dialect/Arith/Transforms/Passes.h.inc"
34 CmpIPredicate pred = op.getPredicate();
36 case CmpIPredicate::sle:
37 case CmpIPredicate::slt:
38 case CmpIPredicate::sge:
39 case CmpIPredicate::sgt:
40 return success(llvm::all_of(op.getOperands(), [&solver](
Value v) ->
bool {
41 return succeeded(staticallyNonNegative(solver, v));
52 case CmpIPredicate::sle:
53 return CmpIPredicate::ule;
54 case CmpIPredicate::slt:
55 return CmpIPredicate::ult;
56 case CmpIPredicate::sge:
57 return CmpIPredicate::uge;
58 case CmpIPredicate::sgt:
59 return CmpIPredicate::ugt;
71 void notifyOperationErased(
Operation *op)
override {
84 template <
typename Signed,
typename Un
signed>
89 LogicalResult matchAndRewrite(Signed op,
PatternRewriter &rw)
const override {
107 LogicalResult matchAndRewrite(CmpIOp op,
PatternRewriter &rw)
const override {
112 op.getLhs(), op.getRhs());
120 struct ArithUnsignedWhenEquivalentPass
121 :
public arith::impl::ArithUnsignedWhenEquivalentBase<
122 ArithUnsignedWhenEquivalentPass> {
124 void runOnOperation()
override {
131 return signalPassFailure();
133 DataFlowListener listener(solver);
145 patterns.add<ConvertOpToUnsigned<DivSIOp, DivUIOp>,
146 ConvertOpToUnsigned<CeilDivSIOp, CeilDivUIOp>,
147 ConvertOpToUnsigned<FloorDivSIOp, DivUIOp>,
148 ConvertOpToUnsigned<RemSIOp, RemUIOp>,
149 ConvertOpToUnsigned<MinSIOp, MinUIOp>,
150 ConvertOpToUnsigned<MaxSIOp, MaxUIOp>,
151 ConvertOpToUnsigned<ExtSIOp, ExtUIOp>, ConvertCmpIToUnsigned>(
156 return std::make_unique<ArithUnsignedWhenEquivalentPass>();
static CmpIPredicate toUnsignedPred(CmpIPredicate pred)
Return the unsigned equivalent of a signed comparison predicate, or the predicate itself if there is ...
static LogicalResult isCmpIConvertable(DataFlowSolver &solver, CmpIOp op)
Succeeds when the comparison predicate is a signed operation and all the operands are non-negative,...
The general data-flow analysis solver.
void eraseState(AnchorT anchor)
Erase any analysis state associated with the given lattice anchor.
AnalysisT * load(Args &&...args)
Load an analysis into the solver. Return the analysis instance.
LogicalResult initializeAndRun(Operation *top)
Initialize the children analyses starting from the provided top-level operation and run the analysis ...
MLIRContext is the top-level object for a collection of MLIR operations.
Operation is the basic unit of execution within MLIR.
MLIRContext * getContext()
Return the context this operation is associated with.
result_range getResults()
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Dead code analysis analyzes control-flow, as understood by RegionBranchOpInterface and BranchOpInterf...
Integer range analysis determines the integer value range of SSA values using operations that define ...
void populateUnsignedWhenEquivalentPatterns(RewritePatternSet &patterns, DataFlowSolver &solver)
Replace signed ops with unsigned ones where they are proven equivalent.
std::unique_ptr< Pass > createArithUnsignedWhenEquivalentPass()
Create a pass to replace signed ops with unsigned ones where they are proven equivalent.
LogicalResult staticallyNonNegative(DataFlowSolver &solver, Operation *op)
Succeeds if an op can be converted to its unsigned equivalent without changing its semantics.
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
void walkAndApplyPatterns(Operation *op, const FrozenRewritePatternSet &patterns, RewriterBase::Listener *listener=nullptr)
A fast walk-based pattern rewrite driver.
OpRewritePattern is a wrapper around RewritePattern that allows for matching and rewriting against an...