Skip to content

Commit 05598d0

Browse files
authored
mdivmul (#263)
1 parent 4fc3c3b commit 05598d0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/polygeist/Ops.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4873,6 +4873,22 @@ struct AffineBufferElimination : public OpRewritePattern<T> {
48734873
}
48744874
};
48754875

4876+
struct MulDivMul : public OpRewritePattern<arith::MulIOp> {
4877+
using OpRewritePattern<MulIOp>::OpRewritePattern;
4878+
LogicalResult matchAndRewrite(MulIOp op,
4879+
PatternRewriter &rewriter) const override {
4880+
if (auto div = op.getLhs().getDefiningOp<arith::DivUIOp>()) {
4881+
if (auto mul = div.getLhs().getDefiningOp<arith::MulIOp>()) {
4882+
if (op.getRhs() == div.getRhs() && mul.getRhs() == op.getRhs()) {
4883+
rewriter.replaceOp(op, mul->getResults());
4884+
return success();
4885+
}
4886+
}
4887+
}
4888+
return failure();
4889+
}
4890+
};
4891+
48764892
void TypeAlignOp::getCanonicalizationPatterns(RewritePatternSet &results,
48774893
MLIRContext *context) {
48784894
results.insert<
@@ -4889,6 +4905,7 @@ void TypeAlignOp::getCanonicalizationPatterns(RewritePatternSet &results,
48894905
AffineBufferElimination<memref::AllocOp>,
48904906
SimplifyDeadAllocV2<memref::AllocaOp>,
48914907
SimplifyDeadAllocV2<memref::AllocOp>, SimplifyDeadAllocV2<LLVM::AllocaOp>,
4908+
MulDivMul,
48924909
// RankReduction<memref::AllocaOp, scf::ParallelOp>,
48934910
AggressiveAllocaScopeInliner, InductiveVarRemoval>(context);
48944911
}

0 commit comments

Comments
 (0)