Commit 71bd6158 authored by Michael Beck's avatar Michael Beck
Browse files

Add -(~x) = x + 1 algebraic simplification

[r15008]
parent 8b68fa0a
......@@ -78,6 +78,8 @@ enum firmstat_optimizations_t {
FS_OPT_MUX_TO_MAX, /**< Mux(a > b, a, b) = Max(a,b) */
FS_OPT_MUX_TO_ABS, /**< Mux(a > b, a, b) = Abs(a,b) */
FS_OPT_MUX_TO_SHR, /**< Mux(a > b, a, b) = a >> b */
FS_OPT_IDEM_UNARY, /**< Idempotent unary operation */
FS_OPT_MINUS_NOT, /**< -(~x) = x + 1 */
FS_OPT_CONST_PHI, /**< Constant evaluation on Phi */
FS_BE_IA32_LEA, /**< Lea was created */
FS_BE_IA32_LOAD_LEA, /**< Load merged with a Lea */
......
......@@ -990,7 +990,7 @@ static ir_node *equivalent_node_idempotent_unop(ir_node *n) {
/* optimize symmetric unop */
if (get_irn_op(pred) == get_irn_op(n)) {
n = get_unop_op(pred);
DBG_OPT_ALGSIM2(oldn, pred, n);
DBG_OPT_ALGSIM2(oldn, pred, n, FS_OPT_IDEM_UNARY);
}
return n;
} /* equivalent_node_idempotent_unop */
......@@ -2548,12 +2548,26 @@ static ir_node *transform_node_Not(ir_node *n) {
/**
* Transform a Minus.
* Optimize:
* -(~x) = x + 1
*/
static ir_node *transform_node_Minus(ir_node *n) {
ir_node *c, *oldn = n;
ir_node *a = get_Minus_op(n);
HANDLE_UNOP_PHI(tarval_neg,a,c);
if (is_Not(a)) {
/* -(~x) = x + 1 */
ir_node *op = get_Not_op(a);
ir_mode *mode = get_irn_mode(op);
tarval *tv = get_mode_one(mode);
ir_node *blk = get_irn_n(n, -1);
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);
}
return n;
} /* transform_node_Minus */
......
......@@ -96,6 +96,8 @@ static const struct {
{ FS_OPT_MUX_TO_MAX, "algebraic simplification: Mux(a > b, a, b) = Max(a,b)" },
{ FS_OPT_MUX_TO_ABS, "algebraic simplification: Mux(a > b, a, b) = Abs(a,b)" },
{ FS_OPT_MUX_TO_SHR, "algebraic simplification: Mux(a > b, a, b) = a >> b" },
{ FS_OPT_IDEM_UNARY, "algebraic simplification: Idempotent unary operation" },
{ FS_OPT_MINUS_NOT, "algebraic simplification: -(~x) = x + 1" },
{ FS_OPT_CONST_PHI, "constant evaluation on Phi node" },
{ FS_BE_IA32_LEA, "ia32 Backend transformation: Lea was created" },
{ FS_BE_IA32_LOAD_LEA, "ia32 Backend transformation: Load merged with a Lea" },
......
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