Skip to content

Commit bed0d3a

Browse files
Add new simplifier rules (#8902)
* Add rewrite rules * remove unnecessary parentheses * uncomment
1 parent b6e889d commit bed0d3a

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/Simplify_Sub.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,12 @@ Expr Simplify::visit(const Sub *op, ExprInfo *info) {
384384
(no_overflow_int(op->type) && EVAL_IN_LAMBDA //
385385
(rewrite(c0 - (c1 - x) / c2, (fold(c0 * c2 - c1 + c2 - 1) + x) / c2, c2 > 0) ||
386386
rewrite(c0 - (x + c1) / c2, (fold(c0 * c2 - c1 + c2 - 1) - x) / c2, c2 > 0) ||
387+
rewrite(x - x / c0, (x * fold(c0 - 1) + fold(c0 - 1)) / c0, c0 > 0) ||
387388
rewrite(x - (x + y) / c0, (x * fold(c0 - 1) - y + fold(c0 - 1)) / c0, c0 > 0) ||
388389
rewrite(x - (x - y) / c0, (x * fold(c0 - 1) + y + fold(c0 - 1)) / c0, c0 > 0) ||
389390
rewrite(x - (y + x) / c0, (x * fold(c0 - 1) - y + fold(c0 - 1)) / c0, c0 > 0) ||
390391
rewrite(x - (y - x) / c0, (x * fold(c0 + 1) - y + fold(c0 - 1)) / c0, c0 > 0) ||
392+
rewrite(x / c0 - x, (x * fold(1 - c0)) / c0) ||
391393
rewrite((x + y) / c0 - x, (x * fold(1 - c0) + y) / c0) ||
392394
rewrite((y + x) / c0 - x, (y + x * fold(1 - c0)) / c0) ||
393395
rewrite((x - y) / c0 - x, (x * fold(1 - c0) - y) / c0) ||

test/correctness/simplify.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ void check_algebra() {
432432
check((y + (x / 3 * 3)) + x % 3, x + y);
433433
check((y + (x / 3)) * 3 + x % 3, y * 3 + x);
434434

435+
check(x - (x / 2), (x + 1) / 2);
436+
check((x / 3) - x, (x * -2) / 3);
435437
check(x / 2 + x % 2, (x + 1) / 2);
436438
check(x % 2 + x / 2, (x + 1) / 2);
437439
check(((x + 1) / 2) * 2 - x, x % 2);

0 commit comments

Comments
 (0)