Revert "[qfcc] Don't fold constants for algebra"

This reverts commit e87e01e4f2.

In the end, this wasn't necessary, and it causes problems in itself.
This commit is contained in:
Bill Currie 2025-01-03 01:03:28 +09:00
parent 6b38fdca35
commit 34fe4efc9d

View file

@ -133,7 +133,7 @@ neg_expr (const expr_t *e)
neg = new_unary_expr ('-', e); neg = new_unary_expr ('-', e);
} }
neg->expr.type = type; neg->expr.type = type;
return edag_add_expr (neg); return edag_add_expr (fold_constants (neg));
} }
const expr_t * const expr_t *
@ -585,6 +585,7 @@ sum_expr_low (const type_t *type, int op, const expr_t *a, const expr_t *b)
} }
auto sum = typed_binary_expr (type, op, a, b); auto sum = typed_binary_expr (type, op, a, b);
sum = fold_constants (sum);
sum = edag_add_expr (sum); sum = edag_add_expr (sum);
return sum; return sum;
} }
@ -820,6 +821,7 @@ distribute_product (const type_t *type, const expr_t *a, const expr_t *b,
for (auto j = b_adds; *j; j++) { for (auto j = b_adds; *j; j++) {
auto p = product (type, *i, *j); auto p = product (type, *i, *j);
if (p) { if (p) {
p = fold_constants (p);
p = edag_add_expr (p); p = edag_add_expr (p);
a = sum_expr (type, a, p); a = sum_expr (type, a, p);
} }
@ -829,6 +831,7 @@ distribute_product (const type_t *type, const expr_t *a, const expr_t *b,
for (auto j = b_subs; *j; j++) { for (auto j = b_subs; *j; j++) {
auto p = product (type, *i, *j); auto p = product (type, *i, *j);
if (p) { if (p) {
p = fold_constants (p);
p = edag_add_expr (p); p = edag_add_expr (p);
a = sum_expr (type, a, p); a = sum_expr (type, a, p);
} }
@ -838,6 +841,7 @@ distribute_product (const type_t *type, const expr_t *a, const expr_t *b,
for (auto j = b_subs; *j; j++) { for (auto j = b_subs; *j; j++) {
auto p = product (type, *i, *j); auto p = product (type, *i, *j);
if (p) { if (p) {
p = fold_constants (p);
p = edag_add_expr (p); p = edag_add_expr (p);
b = sum_expr (type, b, p); b = sum_expr (type, b, p);
} }
@ -847,6 +851,7 @@ distribute_product (const type_t *type, const expr_t *a, const expr_t *b,
for (auto j = b_adds; *j; j++) { for (auto j = b_adds; *j; j++) {
auto p = product (type, *i, *j); auto p = product (type, *i, *j);
if (p) { if (p) {
p = fold_constants (p);
p = edag_add_expr (p); p = edag_add_expr (p);
b = sum_expr (type, b, p); b = sum_expr (type, b, p);
} }
@ -878,6 +883,7 @@ static const expr_t *
apply_scale (const type_t *type, const expr_t *expr, const expr_t *prod) apply_scale (const type_t *type, const expr_t *expr, const expr_t *prod)
{ {
if (expr && prod) { if (expr && prod) {
expr = fold_constants (expr);
expr = edag_add_expr (expr); expr = edag_add_expr (expr);
expr = scale_expr (type, expr, prod); expr = scale_expr (type, expr, prod);
} }