Commit e71958af authored by Michael Beck's avatar Michael Beck
Browse files

Add - (a - b) = b - a transformation

[r15568]
parent faf65108
......@@ -54,6 +54,7 @@ enum firmstat_optimizations_t {
FS_OPT_ADD_SUB, /**< (a + x) - x = (a - x) + x */
FS_OPT_ADD_MUL_A_X_A, /**< a * x + a = a * (x + 1) */
FS_OPT_SUB_0_A, /**< 0 - a = -a */
FS_OPT_MINUS_SUB, /**< - (a - b) = b - a */
FS_OPT_SUB_MUL_A_X_A, /**< a * x - a = a * (x - 1) */
FS_OPT_SUB_SUB_X_Y_Z, /**< (x - y) - z = x - (y + z) */
FS_OPT_MUL_MINUS_1, /**< a * -1 = -a */
......
......@@ -2758,6 +2758,14 @@ static ir_node *transform_node_Minus(ir_node *n) {
ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv);
n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, blk, op, c, mode);
DBG_OPT_ALGSIM2(oldn, a, n, FS_OPT_MINUS_NOT);
} else if (is_Sub(a)) {
/* - (a-b) = b - a */
ir_node *la = get_Sub_left(a);
ir_node *ra = get_Sub_right(a);
ir_node *blk = get_irn_n(n, -1);
n = new_rd_Sub(get_irn_dbg_info(n), current_ir_graph, blk, ra, la, mode);
DBG_OPT_ALGSIM2(oldn, a, n, FS_OPT_MINUS_SUB);
}
return n;
......
......@@ -72,6 +72,7 @@ static const struct {
{ FS_OPT_ADD_SUB, "algebraic simplification: (a + x) - x = (a - x) + x = a" },
{ FS_OPT_ADD_MUL_A_X_A, "algebraic simplification: a * x + a = a * (x + 1)" },
{ FS_OPT_SUB_0_A, "algebraic simplification: 0 - a = -a" },
{ FS_OPT_MINUS_SUB, "algebraic simplification: -(a - b) = b - a" },
{ FS_OPT_SUB_MUL_A_X_A, "algebraic simplification: a * x - a = a * (x - 1)" },
{ FS_OPT_SUB_SUB_X_Y_Z, "algebraic simplification: (x - y) - z = x - (y + z)" },
{ FS_OPT_MUL_MINUS_1, "algebraic simplification: a * -1 = -a" },
......
Supports Markdown
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