Perform cancellation in SimplifyingIrBuilder::addExpr#2020
Perform cancellation in SimplifyingIrBuilder::addExpr#2020jacobhinkle wants to merge 3 commits intomainfrom
Conversation
|
!build --diff --diff-bench |
| std::vector<bool> cancelled_pos(pos_terms.size(), false); | ||
| std::vector<bool> cancelled_neg(neg_terms.size(), false); | ||
| bool performed_cancellation = false; | ||
| for (size_t j : c10::irange(neg_terms.size())) { |
There was a problem hiding this comment.
Iterate over negative terms first since they are likely more rare. If no negative terms were found, we'll quickly see that no cancellation is possible and return the simple sum.
|
I wonder this level of simplification should be done by the expr simplifier. Some historical context: SimplifyingIrBuilder existed before the expr simplifier. We could replace SimplifyingIrBuilder entirely with the expr simplifier as the latter is more powerful. However, it's also much more costly than the simple and quick simplification done by SimplifyingIrBuilder. We can use SimplifyingIrBuilder without worrying about added overheads but that's not the case with the expr simplifier. |
So, to me, SimplifyingIrBuilder is for quick low-hanging fruits only and thus can be used without worrying about overheads, whereas the expr simplifier is a heavy-weight process that's much more comprehensive, so it should be used selectively. Any thoughts? @zasdfgbnm |
I agree with this statement. However, it is not clear to me what should be the boundary. What is considered a "low-hanging fruits" and what should be considered as "heavy-weight"? We need a clear definition here. An alternative idea: I think the idea of "optimization fuel" that I learnt from @wujingyue's talk is really interesting. Should we just totally kill |
Maybe, no recursive simplification?
Or super fast expr simplifier? 😉 |
Sounds like a good boundary. |
|
Yeah, I was thinking the boundary is something like "no recursive, does not require inequality or divisibility proofs", since those are the heavy-weight parts of |
|
In order to use |
|
If |
|
Did a quick experiment in #2022, which uses |
|
On my workstation, I see |
|
!build --diff |
|
Diff used old commit on main. Retrying. |
|
!build --diff |
This change modifies
SimplifyingIrBuilder::addExprto cancel negative terms with positive ones. For example, the following expressions will all be simplified tox + yory + x:x - (-y)(x + z) - ((-y) + z)(x + y) + (a + (b + (-(b + a)))This is a more powerful alternative to #2017, but it does introduce more complexity in
SimplifyingIrBuilder.Note that if cancellation is performed, terms might be reordered from the order given. However, if no cancellation is performed then
IrBuilder::addExpr(lhs, rhs)is returned, so no reordering will take place.TODO: tests