FS_OPT_NOT_PLUS_1, /**< ~x + 1 = -x */
FS_OPT_ADD_X_NOT_X, /**< ~x + x = -1 */
FS_OPT_FP_INV_MUL, /**< x / y = x * (1.0/y) */
+ FS_OPT_ABS_MINUS_X, /**< Abs(-x) = Abs(x) */
FS_OPT_CONST_PHI, /**< Constant evaluation on Phi */
FS_OPT_PREDICATE, /**< Predicate optimization */
FS_OPT_DEMORGAN, /**< optimization using DeMorgan's law */
/*$ -fno-inline $*/
#include <stdio.h>
+#include <math.h>
#define CONST 42
}
int phi1(int x) {
- int a = x ? 23 : 42;
- int b = x ? 42 : 23;
- return a + b;
+ int a = x ? 23 : 42;
+ int b = x ? 42 : 23;
+ return a + b;
}
int phi2(int x) {
- int a = x ? 16 : 8;
- int b = x ? 4 : 2;
- return a / b;
+ int a = x ? 16 : 8;
+ int b = x ? 4 : 2;
+ return a / b;
}
int phi3(int x) {
- int a = x ? 5 : 9;
- int b = x ? 2 : 4;
- return a % b;
+ int a = x ? 5 : 9;
+ int b = x ? 2 : 4;
+ return a % b;
}
int phi4(int x) {
- int a = x ? 5 : 9;
- int b = x ? 2 : 4;
- return (a / b) + (a % b);
+ int a = x ? 5 : 9;
+ int b = x ? 2 : 4;
+ return (a / b) + (a % b);
+}
+
+int abs1(int x) {
+ return abs(-x);
}
int main(void)
TU(phi2, 1, 4);
TU(phi3, 1, 1);
TU(phi4, 1, 3);
+ TU(abs1, 1, 1);
}
/**
* Optimize Abs(x) into x if x is Confirmed >= 0
* Optimize Abs(x) into -x if x is Confirmed <= 0
+ * Optimize Abs(-x) int Abs(x)
*/
static ir_node *transform_node_Abs(ir_node *n) {
ir_node *c, *oldn = n;
* not run it in the equivalent_node() context.
*/
n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph,
- get_irn_n(n, -1), a, mode);
+ get_nodes_block(n), a, mode);
DBG_OPT_CONFIRM(oldn, n);
return n;
DBG_OPT_CONFIRM(oldn, n);
return n;
default:
+ break;
+ }
+ if (is_Minus(a)) {
+ /* Abs(-x) = Abs(x) */
+ mode = get_irn_mode(n);
+ n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph,
+ get_nodes_block(n), get_Minus_op(a), mode);
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ABS_MINUS_X);
return n;
}
+ return n;
} /* transform_node_Abs */
/**
{ FS_OPT_NOT_MINUS_1, "algebraic simplification: ~(x - 1) = -x" },
{ FS_OPT_NOT_PLUS_1, "algebraic simplification: ~x + 1 = -x" },
{ 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_FP_INV_MUL, "algebraic simplification: x / y = x * (1.0/y)" },
+ { FS_OPT_ABS_MINUS_X, "algebraic simplification: Abs(-x) = Abs(x)" },
{ FS_OPT_CONST_PHI, "constant evaluation on Phi node" },
{ FS_OPT_PREDICATE, "predicate optimization" },
{ FS_OPT_DEMORGAN, "optimization using DeMorgan's law" },