Skip to content

Commit d1d3a1a

Browse files
committed
[MLIR][Arith] add and(a, or(a,b)) folder
1 parent c1f0e68 commit d1d3a1a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

mlir/lib/Dialect/Arith/IR/ArithOps.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,18 @@ OpFoldResult arith::AndIOp::fold(FoldAdaptor adaptor) {
896896
if (Value result = foldAndIofAndI(*this))
897897
return result;
898898

899+
/// and(a, or(a, b)) -> a
900+
for (int i = 0; i < 2; i++) {
901+
auto a = getOperand(1 - i);
902+
if (auto orOp = getOperand(i).getDefiningOp<arith::OrIOp>()) {
903+
for (int j = 0; j < 2; j++) {
904+
if (orOp->getOperand(j) == a) {
905+
return a;
906+
}
907+
}
908+
}
909+
}
910+
899911
return constFoldBinaryOp<IntegerAttr>(
900912
adaptor.getOperands(),
901913
[](APInt a, const APInt &b) { return std::move(a) & b; });

0 commit comments

Comments
 (0)