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

added -(x >>u 31) and -(x >>s 31)

[r15795]
parent 3993a824
......@@ -88,6 +88,7 @@ enum firmstat_optimizations_t {
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 */
FS_OPT_PREDICATE, /**< Predicate optimization */
FS_BE_IA32_LEA, /**< Lea was created */
FS_BE_IA32_LOAD_LEA, /**< Load merged with a Lea */
FS_BE_IA32_STORE_LEA, /**< Store merged with a Lea */
......
......@@ -3041,6 +3041,7 @@ static ir_node *transform_node_Not(ir_node *n) {
* Transform a Minus.
* Optimize:
* -(~x) = x + 1
* -(a-b) = b - a
*/
static ir_node *transform_node_Minus(ir_node *n) {
ir_node *c, *oldn = n;
......@@ -3050,15 +3051,52 @@ static ir_node *transform_node_Minus(ir_node *n) {
HANDLE_UNOP_PHI(tarval_neg,a,c);
mode = get_irn_mode(a);
if (get_mode_arithmetic(mode) == irma_twos_complement && is_Not(a)) {
/* -(~x) = x + 1 */
ir_node *op = get_Not_op(a);
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);
} else if (is_Sub(a)) {
if (get_mode_arithmetic(mode) == irma_twos_complement) {
/* the following rules are only to twos-complement */
if (is_Not(a)) {
/* -(~x) = x + 1 */
ir_node *op = get_Not_op(a);
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;
}
if (is_Shr(a)) {
ir_node *c = get_Shr_right(a);
if (is_Const(c)) {
tarval *tv = get_Const_tarval(c);
if (tarval_is_long(tv) && get_tarval_long(tv) == get_mode_size_bits(mode) - 1) {
/* -(a >>u (size-1)) = a >>s (size-1) */
ir_node *v = get_Shr_left(a);
n = new_rd_Shrs(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), v, c, mode);
DBG_OPT_ALGSIM2(oldn, a, n, FS_OPT_PREDICATE);
return n;
}
}
}
if (is_Shrs(a)) {
ir_node *c = get_Shrs_right(a);
if (is_Const(c)) {
tarval *tv = get_Const_tarval(c);
if (tarval_is_long(tv) && get_tarval_long(tv) == get_mode_size_bits(mode) - 1) {
/* -(a >>s (size-1)) = a >>u (size-1) */
ir_node *v = get_Shrs_left(a);
n = new_rd_Shr(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), v, c, mode);
DBG_OPT_ALGSIM2(oldn, a, n, FS_OPT_PREDICATE);
return n;
}
}
}
}
if (is_Sub(a)) {
/* - (a-b) = b - a */
ir_node *la = get_Sub_left(a);
ir_node *ra = get_Sub_right(a);
......@@ -3066,6 +3104,7 @@ static ir_node *transform_node_Minus(ir_node *n) {
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;
}
return n;
......
......@@ -106,6 +106,7 @@ static const struct {
{ FS_OPT_ADD_X_NOT_X, "algebraic simplification: ~x + x = -1" },
{ FS_OPT_FP_INV_MUL, "algebraic simplification: x / y = x * (1.0/y)" },
{ FS_OPT_CONST_PHI, "constant evaluation on Phi node" },
{ FS_OPT_PREDICATE, "predicate optimization" },
{ FS_BE_IA32_LEA, "ia32 Backend transformation: Lea was created" },
{ FS_BE_IA32_LOAD_LEA, "ia32 Backend transformation: Load merged with a Lea" },
{ FS_BE_IA32_STORE_LEA, "ia32 Backend transformation: Store 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