Commit 08735a9d authored by yb9976's avatar yb9976
Browse files

Added local optimization: -((a - b) * c) -> (b - a) * c.

parent 98b46639
......@@ -4581,6 +4581,25 @@ static ir_node *transform_node_Minus(ir_node *n)
}
}
if (is_Mul(op) && only_one_user(op)) {
ir_node *l = get_Mul_left(op);
ir_node *r = get_Mul_right(op);
ir_node *negated_l = can_negate_cheaply(NULL, l);
if (negated_l != NULL) {
/* -((a - b) * c) -> (b - a) * c */
ir_node *block = get_nodes_block(n);
ir_mode *mode = get_irn_mode(n);
return new_rd_Mul(dbgi, block, negated_l, r, mode);
}
ir_node *negated_r = can_negate_cheaply(NULL, r);
if (negated_r != NULL) {
/* -(a * (b - c)) -> a * (c - b) */
ir_node *block = get_nodes_block(n);
ir_mode *mode = get_irn_mode(n);
return new_rd_Mul(dbgi, block, l, negated_r, mode);
}
}
return n;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment