Simplify affine binary op expression class hierarchy
- Drop sub-classing of affine binary op expressions.
- Drop affine expr op kind sub. Represent it as multiply by -1 and add. This
will also be in line with the math form when we'll need to represent a system of
linear equalities/inequalities: the negative number goes into the coefficient
of an affine form. (For eg. x_1 + (-1)*x_2 + 3*x_3 + (-2) >= 0). The folding
simplification will transparently deal with multiplying the -1 with any other
constants. This also means we won't need to simplify a multiply expression
like in x_1 + (-2)*x_2 to a subtract expression (x_1 - 2*x_2) for
canonicalization/uniquing.
- When we print the IR, we will still pretty print to a subtract when possible.
PiperOrigin-RevId: 205298958
diff --git a/lib/Parser/Parser.cpp b/lib/Parser/Parser.cpp
index 98fd716..7b7ee89 100644
--- a/lib/Parser/Parser.cpp
+++ b/lib/Parser/Parser.cpp
@@ -758,7 +758,8 @@
case AffineLowPrecOp::Add:
return builder.getAddExpr(lhs, rhs);
case AffineLowPrecOp::Sub:
- return builder.getSubExpr(lhs, rhs);
+ return builder.getAddExpr(
+ lhs, builder.getMulExpr(rhs, builder.getConstantExpr(-1)));
case AffineLowPrecOp::LNoOp:
llvm_unreachable("can't create affine expression for null low prec op");
return nullptr;