Commit 48c9f5c9 authored by yb9976's avatar yb9976
Browse files

Generalized ~x + 1 => -x to ~x + C => (C - 1) - x.

parent 736159f0
......@@ -2706,12 +2706,20 @@ static ir_node *transform_node_Add(ir_node *n)
if (is_Not(a)) {
ir_node *op = get_Not_op(a);
if (is_Const(b) && is_Const_one(b)) {
/* ~x + 1 = -x */
ir_node *blk = get_nodes_block(n);
n = new_rd_Minus(get_irn_dbg_info(n), blk, op, mode);
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_PLUS_1);
return n;
if (is_Const(b)) {
ir_tarval *const tv = get_Const_tarval(b);
ir_tarval *const minus_one = get_mode_minus_one(mode);
ir_tarval *const add = tarval_add(tv, minus_one);
if (tarval_is_constant(add)) {
/* ~x + C = (C - 1) - x */
dbg_info *const dbgi = get_irn_dbg_info(n);
ir_node *const block = get_nodes_block(n);
ir_node *const c = new_rd_Const(dbgi, irg, add);
n = new_rd_Sub(get_irn_dbg_info(n), block, c, op, mode);
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_PLUS_C);
return n;
}
}
}
if (!irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_ARCH_DEP)) {
......
......@@ -108,7 +108,7 @@ enum firmstat_optimizations_t {
FS_OPT_INVOLUTION, /**< OP(OP(x)) = x */
FS_OPT_MINUS_NOT, /**< -(~x) = x + 1 */
FS_OPT_NOT_MINUS_1, /**< ~(x - 1) = -x */
FS_OPT_NOT_PLUS_1, /**< ~x + 1 = -x */
FS_OPT_NOT_PLUS_C, /**< ~x + C = (C - 1) - x */
FS_OPT_ADD_X_NOT_X, /**< ~x + x = -1 */
FS_OPT_FP_INV_MUL, /**< x / y = x * (1.0/y) */
FS_OPT_CONST_PHI, /**< Constant evaluation on Phi */
......
......@@ -98,7 +98,7 @@ static const struct {
{ (hook_opt_kind)FS_OPT_INVOLUTION, "algebraic simplification: OP(OP(x)) = x" },
{ (hook_opt_kind)FS_OPT_MINUS_NOT, "algebraic simplification: -(~x) = x + 1" },
{ (hook_opt_kind)FS_OPT_NOT_MINUS_1, "algebraic simplification: ~(x - 1) = -x" },
{ (hook_opt_kind)FS_OPT_NOT_PLUS_1, "algebraic simplification: ~x + 1 = -x" },
{ (hook_opt_kind)FS_OPT_NOT_PLUS_C, "algebraic simplification: ~x + C = (C - 1) - x" },
{ (hook_opt_kind)FS_OPT_ADD_X_NOT_X, "algebraic simplification: ~x + x = -1" },
{ (hook_opt_kind)FS_OPT_FP_INV_MUL, "algebraic simplification: x / y = x * (1.0/y)" },
{ (hook_opt_kind)FS_OPT_CONST_PHI, "constant evaluation on Phi node" },
......
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