Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's generally a bad idea for simplifier rules to multiply constants #8234

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/Simplify_Add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ Expr Simplify::visit(const Add *op, ExprInfo *bounds) {
rewrite(x + y*x, (y + 1) * x) ||
rewrite(x*y + x, x * (y + 1)) ||
rewrite(y*x + x, (y + 1) * x, !is_const(x)) ||
rewrite((x + c0)/c1 + c2, (x + fold(c0 + c1*c2))/c1, c1 != 0) ||
rewrite((x + (y + c0)/c1) + c2, x + (y + fold(c0 + c1*c2))/c1, c1 != 0) ||
rewrite(((y + c0)/c1 + x) + c2, x + (y + fold(c0 + c1*c2))/c1, c1 != 0) ||
rewrite((c0 - x)/c1 + c2, (fold(c0 + c1*c2) - x)/c1, c0 != 0 && c1 != 0) || // When c0 is zero, this would fight another rule
rewrite(x + (x + y)/c0, (fold(c0 + 1)*x + y)/c0, c0 != 0) ||
rewrite(x + (y + x)/c0, (fold(c0 + 1)*x + y)/c0, c0 != 0) ||
rewrite(x + (y - x)/c0, (fold(c0 - 1)*x + y)/c0, c0 != 0) ||
Expand Down
1 change: 1 addition & 0 deletions src/Simplify_Min.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ Expr Simplify::visit(const Min *op, ExprInfo *bounds) {
// Required for nested GuardWithIf tilings
rewrite(min((min(((y + c0)/c1), x)*c1), y + c2), min(x * c1, y + c2), c1 > 0 && c1 + c2 <= c0 + 1) ||
rewrite(min((min(((y + c0)/c1), x)*c1) + c2, y), min(x * c1 + c2, y), c1 > 0 && c1 <= c0 + c2 + 1) ||
rewrite(min(min(((y + c0)/c1), x)*c1, y), min(x * c1, y), c1 > 0 && c1 <= c0 + 1) ||

rewrite(min((x + c0)/c1, ((x + c2)/c3)*c4), (x + c0)/c1, c0 + c3 - c1 <= c2 && c1 > 0 && c3 > 0 && c1 * c4 == c3) ||
rewrite(min((x + c0)/c1, ((x + c2)/c3)*c4), ((x + c2)/c3)*c4, c2 <= c0 && c1 > 0 && c3 > 0 && c1 * c4 == c3) ||
Expand Down
3 changes: 0 additions & 3 deletions test/correctness/simplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,6 @@ void check_algebra() {
check((x * 2 - y) / 2, (0 - y) / 2 + x);
check((x * -2 - y) / 2, (0 - y) / 2 - x);
check((y - x * 4) / 2, y / 2 - x * 2);
check((x + 3) / 2 + 7, (x + 17) / 2);
check((x / 2 + 3) / 5, (x + 6) / 10);
check((x + (y + 3) / 5) + 5, (y + 28) / 5 + x);
check((x + 8) / 2, x / 2 + 4);
check((x - y) * -2, (y - x) * 2);
check((xf - yf) * -2.0f, (yf - xf) * 2.0f);
Expand Down
Loading