-static tarval *computed_value_Min(ir_node *n)
-{
- ir_node *a = get_binop_left(n);
- ir_node *b = get_binop_right(n);
-
- tarval *ta = value_of(a);
- tarval *tb = value_of(b);
-
- if ((ta != tarval_bad) && (tb != tarval_bad) && (get_irn_mode(a) == get_irn_mode(b))) {
- pn_Cmp res = tarval_cmp(ta, tb);
-
- /* beware: there might be Unordered tarvals here, in that
- * case let the backend decide, do NOT optimize */
- if (res == pn_Cmp_Lt)
- return ta;
- if (res == pn_Cmp_Gt || res == pn_Cmp_Eq)
- return tb;
- }
- return tarval_bad;
+static tarval *computed_value_Min(const ir_node *n) {
+ ir_node *a = get_binop_left(n);
+ ir_node *b = get_binop_right(n);
+
+ tarval *ta = value_of(a);
+ tarval *tb = value_of(b);
+
+ if ((ta != tarval_bad) && (tb != tarval_bad) && (get_irn_mode(a) == get_irn_mode(b))) {
+ pn_Cmp res = tarval_cmp(ta, tb);
+
+ /* beware: there might be Unordered tarvals here, in that
+ * case let the backend decide, do NOT optimize */
+ if (res == pn_Cmp_Lt)
+ return ta;
+ if (res == pn_Cmp_Gt || res == pn_Cmp_Eq)
+ return tb;
+ }
+ return tarval_bad;
-static tarval *computed_value_Max(ir_node *n)
-{
- ir_node *a = get_binop_left(n);
- ir_node *b = get_binop_right(n);
-
- tarval *ta = value_of(a);
- tarval *tb = value_of(b);
-
- if ((ta != tarval_bad) && (tb != tarval_bad) && (get_irn_mode(a) == get_irn_mode(b))) {
- pn_Cmp res = tarval_cmp(ta, tb);
-
- /* beware: there might be Unordered tarvals here, in that
- * case let the backend decide, do NOT optimize */
- if (res == pn_Cmp_Gt)
- return ta;
- if (res == pn_Cmp_Lt || res == pn_Cmp_Eq)
- return tb;
- }
- return tarval_bad;
+static tarval *computed_value_Max(const ir_node *n) {
+ ir_node *a = get_binop_left(n);
+ ir_node *b = get_binop_right(n);
+
+ tarval *tb = value_of(b);
+ tarval *ta = value_of(a);
+
+ if ((ta != tarval_bad) && (tb != tarval_bad) && (get_irn_mode(a) == get_irn_mode(b))) {
+ pn_Cmp res = tarval_cmp(ta, tb);
+
+ /* beware: there might be Unordered tarvals here, in that
+ * case let the backend decide, do NOT optimize */
+ if (res == pn_Cmp_Gt)
+ return ta;
+ if (res == pn_Cmp_Lt || res == pn_Cmp_Eq)
+ return tb;
+ }
+ return tarval_bad;
- ir_node *a, *b;
-
- if (settings.minmax_handle_NaN == 0 && mode_is_float(get_irn_mode(n)))
- return n;
-
- a = get_binop_left(n);
- b = get_binop_right(n);
-
- if (a == b) {
- DBG_OPT_ALGSIM0(n, a, FS_OPT_MIN_MAX_EQ);
- return a;
- }
-
- return n;
+ ir_node *a, *b;
+ ir_mode *mode;
+ tarval *tv;
+
+ if (settings.minmax_handle_NaN == 0 && mode_is_float(get_irn_mode(n)))
+ return n;
+
+ a = get_binop_left(n);
+ b = get_binop_right(n);
+
+ if (a == b) {
+ DBG_OPT_ALGSIM0(n, a, FS_OPT_MIN_MAX_EQ);
+ return a;
+ }
+
+ mode = get_irn_mode(n);
+ tv = n->op == op_Max ? get_mode_min(mode) : get_mode_max(mode);
+
+ if (value_of(b) == tv) {
+ DBG_OPT_ALGSIM0(n, a, FS_OPT_MIN_MAX_EQ);
+ return a;
+ }
+ if (value_of(a) == tv) {
+ DBG_OPT_ALGSIM0(n, b, FS_OPT_MIN_MAX_EQ);
+ return b;
+ }
+
+ return n;
- if (settings.enabled_ops & ARCH_OPS_MINMAX) {
- ir_node *oldn = n, *cmp, *proj = get_Mux_sel(n);
- long proj_nr;
-
- if (get_irn_op(proj) != op_Proj)
- return n;
-
- cmp = get_Proj_pred(proj);
- if (get_irn_op(cmp) == op_Cmp) {
- ir_node *a = get_Cmp_left(cmp);
- ir_node *b = get_Cmp_right(cmp);
- ir_node *t = get_Mux_true(n);
- ir_node *f = get_Mux_false(n);
-
- proj_nr = get_Proj_proj(proj);
-
- if (proj_nr == pn_Cmp_Lt || proj_nr == pn_Cmp_Le) {
- if (a == t && b == f) {
- /* a </<= b ? a : b ==> Min(a,b) */
- n = new_rd_Min(get_irn_dbg_info(n),
- current_ir_graph,
- get_nodes_block(n),
- a, b,
- get_irn_mode(n));
-
- DBG_OPT_ALGSIM1(oldn, cmp, proj, n, FS_OPT_MUX_TO_MIN);
- return n;
- }
- else if (a == f && b == t) {
- /* a </<= b ? b : a ==> Max(a,b) */
- n = new_rd_Max(get_irn_dbg_info(n),
- current_ir_graph,
- get_nodes_block(n),
- a, b,
- get_irn_mode(n));
-
- DBG_OPT_ALGSIM1(oldn, cmp, proj, n, FS_OPT_MUX_TO_MAX);
- return n;
- }
- }
- else if (proj_nr == pn_Cmp_Gt || proj_nr == pn_Cmp_Ge) {
- if (a == t && b == f) {
- /* a >/>= b ? a : b ==> Max(a,b) */
- n = new_rd_Max(get_irn_dbg_info(n),
- current_ir_graph,
- get_nodes_block(n),
- a, b,
- get_irn_mode(n));
-
- DBG_OPT_ALGSIM1(oldn, cmp, proj, n, FS_OPT_MUX_TO_MAX);
- return n;
- }
- else if (a == f && b == t) {
- /* a >/>= b ? b : a ==> Min(a,b) */
- n = new_rd_Min(get_irn_dbg_info(n),
- current_ir_graph,
- get_nodes_block(n),
- a, b,
- get_irn_mode(n));
-
- DBG_OPT_ALGSIM1(oldn, cmp, proj, n, FS_OPT_MUX_TO_MIN);
- return n;
- }
- }
- }
- }
- return n;
+ if (settings.enabled_ops & ARCH_OPS_MINMAX) {
+ ir_node *oldn = n, *cmp, *proj = get_Mux_sel(n);
+ long proj_nr;
+
+ if (get_irn_op(proj) != op_Proj)
+ return n;
+
+ cmp = get_Proj_pred(proj);
+ if (get_irn_op(cmp) == op_Cmp) {
+ ir_node *a = get_Cmp_left(cmp);
+ ir_node *b = get_Cmp_right(cmp);
+ ir_node *t = get_Mux_true(n);
+ ir_node *f = get_Mux_false(n);
+
+ proj_nr = get_Proj_proj(proj);
+
+ if (proj_nr == pn_Cmp_Lt || proj_nr == pn_Cmp_Le) {
+ if (a == t && b == f) {
+ /* a </<= b ? a : b ==> Min(a,b) */
+ n = new_rd_Min(get_irn_dbg_info(n),
+ current_ir_graph,
+ get_nodes_block(n),
+ a, b,
+ get_irn_mode(n));
+
+ DBG_OPT_ALGSIM1(oldn, cmp, proj, n, FS_OPT_MUX_TO_MIN);
+ return n;
+ }
+ else if (a == f && b == t) {
+ /* a </<= b ? b : a ==> Max(a,b) */
+ n = new_rd_Max(get_irn_dbg_info(n),
+ current_ir_graph,
+ get_nodes_block(n),
+ a, b,
+ get_irn_mode(n));
+
+ DBG_OPT_ALGSIM1(oldn, cmp, proj, n, FS_OPT_MUX_TO_MAX);
+ return n;
+ }
+ }
+ else if (proj_nr == pn_Cmp_Gt || proj_nr == pn_Cmp_Ge) {
+ if (a == t && b == f) {
+ /* a >/>= b ? a : b ==> Max(a,b) */
+ n = new_rd_Max(get_irn_dbg_info(n),
+ current_ir_graph,
+ get_nodes_block(n),
+ a, b,
+ get_irn_mode(n));
+
+ DBG_OPT_ALGSIM1(oldn, cmp, proj, n, FS_OPT_MUX_TO_MAX);
+ return n;
+ }
+ else if (a == f && b == t) {
+ /* a >/>= b ? b : a ==> Min(a,b) */
+ n = new_rd_Min(get_irn_dbg_info(n),
+ current_ir_graph,
+ get_nodes_block(n),
+ a, b,
+ get_irn_mode(n));
+
+ DBG_OPT_ALGSIM1(oldn, cmp, proj, n, FS_OPT_MUX_TO_MIN);
+ return n;
+ }
+ }
+ }
+ }
+ return n;