Optimize "- INT_CONSTANT" to be simply -INT_CONSTANT rather than (- INT_CONSTANT)

This commit is contained in:
Dianne Skoll
2025-05-16 08:30:44 -04:00
parent 6aa217044b
commit 4db201945c
2 changed files with 9 additions and 17 deletions
+7
View File
@@ -2264,6 +2264,13 @@ static expr_node *parse_factor(char const **e, int *r, Var *locals, int level)
return NULL;
}
/* Optimize '-' followed by integer constant */
if (op == '-' && node->type == N_CONSTANT) {
if (node->u.value.type == INT_TYPE) {
node->u.value.v.val = - node->u.value.v.val;
}
return node;
}
factor_node = alloc_expr_node(r);
if (!factor_node) {
free_expr_tree(node);