* @author Christian Schaefer, Goetz Lindenmaier, Michael Beck
* @version $Id$
*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
#include <string.h>
#include "irhooks.h"
#include "irarch.h"
#include "hashptr.h"
-#include "archop.h"
#include "opt_confirms.h"
#include "opt_polymorphy.h"
#include "irtools.h"
-#include "xmalloc.h"
+#include "irhooks.h"
+#include "array_t.h"
/* Make types visible to allow most efficient access */
#include "entity_t.h"
tarval *ta;
tarval *tb;
- /* a - a */
- if (a == b && !is_Bad(a))
- return get_mode_null(mode);
+ /* NaN - NaN != 0 */
+ if (! mode_is_float(mode)) {
+ /* a - a = 0 */
+ if (a == b)
+ return get_mode_null(mode);
+ }
ta = value_of(a);
tb = value_of(b);
if (ta != tarval_bad && tb != tarval_bad) {
return tarval_mul(ta, tb);
} else {
- /* a*0 = 0 or 0*b = 0 */
- if (ta == get_mode_null(mode))
- return ta;
- if (tb == get_mode_null(mode))
- return tb;
+ /* a * 0 != 0 if a == NaN or a == Inf */
+ if (!mode_is_float(mode)) {
+ /* a*0 = 0 or 0*b = 0 */
+ if (ta == get_mode_null(mode))
+ return ta;
+ if (tb == get_mode_null(mode))
+ return tb;
+ }
}
return tarval_bad;
} /* computed_value_Mul */
ir_node *oldn = n;
int n_preds;
- /* don't optimize dead blocks */
- if (is_Block_dead(n))
+ /* don't optimize dead or labeled blocks */
+ if (is_Block_dead(n) || has_Block_label(n))
return n;
n_preds = get_Block_n_cfgpreds(n);
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_AND);
return n;
}
- /* constants are cormalized to right, check this site first */
+ /* constants are normalized to right, check this site first */
tv = value_of(b);
if (tarval_is_all_one(tv)) {
n = a;
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND);
return n;
}
+ if (tv != get_tarval_bad()) {
+ ir_mode *mode = get_irn_mode(n);
+ if (!mode_is_signed(mode) && is_Conv(a)) {
+ ir_node *convop = get_Conv_op(a);
+ ir_mode *convopmode = get_irn_mode(convop);
+ if (!mode_is_signed(convopmode)) {
+ if (tarval_is_all_one(tarval_convert_to(tv, convopmode))) {
+ /* Conv(X) & all_one(mode(X)) = Conv(X) */
+ n = a;
+ DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND);
+ return n;
+ }
+ }
+ }
+ }
tv = value_of(a);
if (tarval_is_all_one(tv)) {
n = b;
restart:
if (n_mode == a_mode) { /* No Conv necessary */
if (get_Conv_strict(n)) {
- /* special case: the predecessor might be a also a Conv */
+ ir_node *p = a;
+
+ /* neither Minus nor Abs nor Confirm change the precision,
+ so we can "look-through" */
+ for (;;) {
+ if (is_Minus(p)) {
+ p = get_Minus_op(p);
+ } else if (is_Abs(p)) {
+ p = get_Abs_op(p);
+ } else if (is_Confirm(p)) {
+ p = get_Confirm_value(p);
+ } else {
+ /* stop here */
+ break;
+ }
+ }
+ if (is_Conv(p) && get_Conv_strict(p)) {
+ /* we known already, that a_mode == n_mode, and neither
+ Abs nor Minus change the mode, so the second Conv
+ can be kicked */
+ assert(get_irn_mode(p) == n_mode);
+ n = a;
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
+ return n;
+ }
+ if (is_Proj(p)) {
+ ir_node *pred = get_Proj_pred(p);
+ if (is_Load(pred)) {
+ /* Loads always return with the exact precision of n_mode */
+ assert(get_Load_mode(pred) == n_mode);
+ n = a;
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
+ return n;
+ }
+ if (is_Proj(pred) && get_Proj_proj(pred) == pn_Start_T_args) {
+ pred = get_Proj_pred(pred);
+ if (is_Start(pred)) {
+ /* Arguments always return with the exact precision,
+ as strictConv's are place before Call -- if the
+ caller was compiled with the same setting.
+ Otherwise, the semantics is probably still right. */
+ assert(get_irn_mode(p) == n_mode);
+ n = a;
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
+ return n;
+ }
+ }
+ }
if (is_Conv(a)) {
+ /* special case: the immediate predecessor is also a Conv */
if (! get_Conv_strict(a)) {
/* first one is not strict, kick it */
a = get_Conv_op(a);
goto restart;
}
/* else both are strict conv, second is superfluous */
- } else {
- if (is_Proj(a)) {
- ir_node *pred = get_Proj_pred(a);
- if (is_Load(pred)) {
- /* loads always return with the exact precision of n_mode */
- assert(get_Load_mode(pred) == n_mode);
- return a;
- }
- }
- /* leave strict floating point Conv's */
+ n = a;
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
return n;
}
+ } else {
+ n = a;
+ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
+ return n;
}
- n = a;
- DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
} else if (is_Conv(a)) { /* Conv(Conv(b)) */
ir_node *b = get_Conv_op(a);
ir_mode *b_mode = get_irn_mode(b);
if (n_mode == mode_b) {
n = b; /* Convb(Conv*(xxxb(...))) == xxxb(...) */
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
+ return n;
} else if (get_mode_arithmetic(n_mode) == get_mode_arithmetic(a_mode)) {
- if (smaller_mode(b_mode, a_mode)) {
+ if (values_in_mode(b_mode, a_mode)) {
n = b; /* ConvS(ConvL(xxxS(...))) == xxxS(...) */
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
+ return n;
}
}
}
- if (mode_is_int(n_mode) && mode_is_float(a_mode)) {
+ if (mode_is_int(n_mode) && get_mode_arithmetic(a_mode) == irma_ieee754) {
/* ConvI(ConvF(I)) -> I, iff float mantissa >= int mode */
- size_t int_mantissa = get_mode_size_bits(n_mode) - (mode_is_signed(n_mode) ? 1 : 0);
- size_t float_mantissa;
- /* FIXME There is no way to get the mantissa size of a mode */
- switch (get_mode_size_bits(a_mode)) {
- case 32: float_mantissa = 23 + 1; break; // + 1 for implicit 1
- case 64: float_mantissa = 52 + 1; break;
- case 80: float_mantissa = 64; break;
- default: float_mantissa = 0; break;
- }
+ unsigned int_mantissa = get_mode_size_bits(n_mode) - (mode_is_signed(n_mode) ? 1 : 0);
+ unsigned float_mantissa = tarval_ieee754_get_mantissa_size(a_mode);
+
if (float_mantissa >= int_mantissa) {
n = b;
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
set_Conv_strict(b, 1);
n = b; /* ConvA(ConvB(ConvA(...))) == ConvA(...) */
DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
+ return n;
}
}
}
if (! is_Phi(n) || get_irn_arity(n) == 0)
return 0;
- for (i = get_irn_arity(n) - 1; i >= 0; --i)
+ for (i = get_irn_arity(n) - 1; i >= 0; --i) {
if (! is_Const(get_irn_n(n, i)))
return 0;
- return 1;
+ }
+ return 1;
} /* is_const_Phi */
typedef tarval *(*tarval_sub_type)(tarval *a, tarval *b, ir_mode *mode);
irg = current_ir_graph;
for (i = 0; i < n; ++i) {
pred = get_irn_n(phi, i);
- res[i] = new_r_Const_type(irg, get_irg_start_block(irg),
- mode, res[i], get_Const_type(pred));
+ res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred));
}
return new_r_Phi(irg, get_nodes_block(phi), n, (ir_node **)res, mode);
} /* apply_binop_on_phi */
irg = current_ir_graph;
for (i = 0; i < n; ++i) {
pred = get_irn_n(a, i);
- res[i] = new_r_Const_type(irg, get_irg_start_block(irg), mode, res[i], get_Const_type(pred));
+ res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred));
}
return new_r_Phi(irg, get_nodes_block(a), n, (ir_node **)res, mode);
} /* apply_binop_on_2_phis */
irg = current_ir_graph;
for (i = 0; i < n; ++i) {
pred = get_irn_n(phi, i);
- res[i] = new_r_Const_type(irg, get_irg_start_block(irg),
- mode, res[i], get_Const_type(pred));
+ res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred));
}
return new_r_Phi(irg, get_nodes_block(phi), n, (ir_node **)res, mode);
} /* apply_unop_on_phi */
irg = current_ir_graph;
for (i = 0; i < n; ++i) {
pred = get_irn_n(phi, i);
- res[i] = new_r_Const_type(irg, get_irg_start_block(irg),
- mode, res[i], get_Const_type(pred));
+ res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred));
}
return new_r_Phi(irg, get_nodes_block(phi), n, (ir_node **)res, mode);
} /* apply_conv_on_phi */
current_ir_graph,
block,
a,
- new_r_Const_long(current_ir_graph, block, mode, 2),
+ new_Const_long(mode, 2),
mode);
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_A_A);
return n;
}
if (op == b) {
/* ~x + x = -1 */
- ir_node *blk = get_nodes_block(n);
- n = new_r_Const(current_ir_graph, blk, mode, get_mode_minus_one(mode));
+ n = new_Const(get_mode_minus_one(mode));
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_X_NOT_X);
return n;
}
if (op == a) {
/* x + ~x = -1 */
- ir_node *blk = get_nodes_block(n);
- n = new_r_Const(current_ir_graph, blk, mode, get_mode_minus_one(mode));
+ n = new_Const(get_mode_minus_one(mode));
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_X_NOT_X);
return n;
}
tarval *tv = tarval_neg(get_Const_tarval(cnst));
dbg_info *dbgi = get_irn_dbg_info(cnst);
ir_graph *irg = get_irn_irg(cnst);
- ir_node *block = get_nodes_block(cnst);
- ir_mode *mode = get_irn_mode(cnst);
if (tv == tarval_bad) return NULL;
- return new_rd_Const(dbgi, irg, block, mode, tv);
+ return new_rd_Const(dbgi, irg, tv);
}
/**
if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic))
return n;
- if (is_Const(b) && get_irn_mode(b) != mode_P) {
+ if (is_Const(b) && !mode_is_reference(get_irn_mode(b))) {
/* a - C -> a + (-C) */
ir_node *cnst = const_negate(b);
if (cnst != NULL) {
ir_node *s_left = get_Sub_left(b);
ir_node *s_right = get_Sub_right(b);
ir_mode *s_mode = get_irn_mode(b);
- if (s_mode == mode_P) {
+ if (mode_is_reference(s_mode)) {
ir_node *sub = new_rd_Sub(s_dbg, irg, s_block, a, s_left, mode);
dbg_info *a_dbg = get_irn_dbg_info(n);
ir_node *a_block = get_nodes_block(n);
get_irn_dbg_info(n),
current_ir_graph, blk,
mb,
- new_r_Const_long(current_ir_graph, blk, mode, 1),
+ new_Const_long(mode, 1),
mode),
mode);
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_MUL_A_X_A);
get_irn_dbg_info(n),
current_ir_graph, blk,
ma,
- new_r_Const_long(current_ir_graph, blk, mode, 1),
+ new_Const_long(mode, 1),
mode),
mode);
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_MUL_A_X_A);
tv = tarval_add(tv, get_mode_one(mode));
if (tv != tarval_bad) {
ir_node *blk = get_nodes_block(n);
- ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv);
+ ir_node *c = new_Const(tv);
n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, blk, get_Not_op(b), c, mode);
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_C_NOT_X);
return n;
value = n;
tv = value_of(n);
if (tv != tarval_bad) {
- value = new_Const(get_tarval_mode(tv), tv);
+ value = new_Const(tv);
DBG_OPT_CSTEVAL(n, value);
goto make_tuple;
if (a == b && value_not_zero(a, &dummy)) {
/* BEWARE: we can optimize a/a to 1 only if this cannot cause a exception */
- value = new_Const(mode, get_mode_one(mode));
+ value = new_Const(get_mode_one(mode));
DBG_OPT_CSTEVAL(n, value);
goto make_tuple;
} else {
value = n;
tv = value_of(n);
if (tv != tarval_bad) {
- value = new_Const(get_tarval_mode(tv), tv);
+ value = new_Const(tv);
DBG_OPT_CSTEVAL(n, value);
goto make_tuple;
if (a == b && value_not_zero(a, &dummy)) {
/* BEWARE: we can optimize a%a to 0 only if this cannot cause a exception */
- value = new_Const(mode, get_mode_null(mode));
+ value = new_Const(get_mode_null(mode));
DBG_OPT_CSTEVAL(n, value);
goto make_tuple;
} else {
if (tv == get_mode_minus_one(mode)) {
/* a % -1 = 0 */
- value = new_Const(mode, get_mode_null(mode));
+ value = new_Const(get_mode_null(mode));
DBG_OPT_CSTEVAL(n, value);
goto make_tuple;
}
if (tb != tarval_bad) {
if (tb == get_mode_one(get_tarval_mode(tb))) {
va = a;
- vb = new_Const(mode, get_mode_null(mode));
+ vb = new_Const(get_mode_null(mode));
DBG_OPT_CSTEVAL(n, vb);
goto make_tuple;
} else if (ta != tarval_bad) {
Jmp for X result!? */
resb = tarval_mod(ta, tb);
if (resb == tarval_bad) return n; /* Causes exception! */
- va = new_Const(mode, resa);
- vb = new_Const(mode, resb);
+ va = new_Const(resa);
+ vb = new_Const(resb);
DBG_OPT_CSTEVAL(n, va);
DBG_OPT_CSTEVAL(n, vb);
goto make_tuple;
} else if (mode_is_signed(mode) && tb == get_mode_minus_one(mode)) {
va = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n), a, mode);
- vb = new_Const(mode, get_mode_null(mode));
+ vb = new_Const(get_mode_null(mode));
DBG_OPT_CSTEVAL(n, va);
DBG_OPT_CSTEVAL(n, vb);
goto make_tuple;
} else if (a == b) {
if (value_not_zero(a, &dummy)) {
/* a/a && a != 0 */
- va = new_Const(mode, get_mode_one(mode));
- vb = new_Const(mode, get_mode_null(mode));
+ va = new_Const(get_mode_one(mode));
+ vb = new_Const(get_mode_null(mode));
DBG_OPT_CSTEVAL(n, va);
DBG_OPT_CSTEVAL(n, vb);
goto make_tuple;
tarval *tv = value_of(b);
if (tv != tarval_bad) {
- int rem;
+ int rem = tarval_fp_ops_enabled();
/*
* Floating point constant folding might be disabled here to
* However, as we check for exact result, doing it is safe.
* Switch it on.
*/
- rem = tarval_enable_fp_ops(1);
+ tarval_enable_fp_ops(1);
tv = tarval_quo(get_mode_one(mode), tv);
- (void)tarval_enable_fp_ops(rem);
+ tarval_enable_fp_ops(rem);
/* Do the transformation if the result is either exact or we are not
using strict rules. */
if (tv != tarval_bad &&
(tarval_ieee754_get_exact() || (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic) == 0)) {
ir_node *blk = get_nodes_block(n);
- ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv);
+ ir_node *c = new_Const(tv);
ir_node *a = get_Quot_left(n);
ir_node *m = new_rd_Mul(get_irn_dbg_info(n), current_ir_graph, blk, a, c, mode);
ir_node *mem = get_Quot_mem(n);
if (a == b) {
/* a ^ a = 0 */
- n = new_rd_Const(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n),
- mode, get_mode_null(mode));
+ n = new_rd_Const(get_irn_dbg_info(n), current_ir_graph,
+ get_mode_null(mode));
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_A_A);
} else if (mode == mode_b &&
is_Proj(a) &&
DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_TO_NOT_BOOL);
} else if (is_Const(b)) {
if (is_Not(a)) { /* ~x ^ const -> x ^ ~const */
- ir_node *cnst = new_Const(mode, tarval_not(get_Const_tarval(b)));
+ ir_node *cnst = new_Const(tarval_not(get_Const_tarval(b)));
ir_node *not_op = get_Not_op(a);
dbg_info *dbg = get_irn_dbg_info(n);
ir_graph *irg = current_ir_graph;
if (is_Eor(a)) {
ir_node *eor_b = get_Eor_right(a);
if (is_Const(eor_b)) { /* ~(x ^ const) -> x ^ ~const */
- ir_node *cnst = new_Const(mode, tarval_not(get_Const_tarval(eor_b)));
+ ir_node *cnst = new_Const(tarval_not(get_Const_tarval(eor_b)));
ir_node *eor_a = get_Eor_left(a);
dbg_info *dbg = get_irn_dbg_info(n);
ir_graph *irg = current_ir_graph;
ir_graph *irg = current_ir_graph;
ir_node *block = get_nodes_block(n);
ir_node *add_l = get_Minus_op(a);
- ir_node *add_r = new_rd_Const(dbg, irg, block, mode, get_mode_minus_one(mode));
+ ir_node *add_r = new_rd_Const(dbg, irg, get_mode_minus_one(mode));
n = new_rd_Add(dbg, irg, block, add_l, add_r, mode);
} else if (is_Add(a)) {
ir_node *add_r = get_Add_right(a);
ir_node *op = get_Not_op(a);
tarval *tv = get_mode_one(mode);
ir_node *blk = get_nodes_block(n);
- ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv);
+ ir_node *c = new_Const(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 (tv != tarval_bad) {
tv = tarval_neg(tv);
if (tv != tarval_bad) {
- ir_node *cnst = new_Const(mode, tv);
+ ir_node *cnst = new_Const(tv);
dbg_info *dbg = get_irn_dbg_info(a);
ir_graph *irg = current_ir_graph;
ir_node *block = get_nodes_block(a);
ir_type *tp = get_irn_type(n);
if (is_Const(pred) && get_Const_type(pred) != tp) {
- n = new_rd_Const_type(NULL, current_ir_graph, get_irn_n(pred, -1), get_irn_mode(pred),
- get_Const_tarval(pred), tp);
+ n = new_rd_Const_type(NULL, current_ir_graph, get_Const_tarval(pred), tp);
DBG_OPT_CSTEVAL(oldn, n);
} else if (is_SymConst(pred) && get_SymConst_value_type(pred) != tp) {
n = new_rd_SymConst_type(NULL, current_ir_graph, get_irn_n(pred, -1), get_irn_mode(pred),
if (get_Mod_left(mod) == b) {
/* a % a = 0 if a != 0 */
ir_mode *mode = get_irn_mode(proj);
- ir_node *res = new_Const(mode, get_mode_null(mode));
+ ir_node *res = new_Const(get_mode_null(mode));
DBG_OPT_CSTEVAL(mod, res);
return res;
if (get_DivMod_left(divmod) == b) {
/* a % a = 0 if a != 0 */
ir_mode *mode = get_irn_mode(proj);
- ir_node *res = new_Const(mode, get_mode_null(mode));
+ ir_node *res = new_Const(get_mode_null(mode));
DBG_OPT_CSTEVAL(divmod, res);
return res;
/* we have a constant switch */
long num = get_Proj_proj(proj);
- if (num != get_Cond_defaultProj(n)) { /* we cannot optimize default Proj's yet */
+ if (num != get_Cond_default_proj(n)) { /* we cannot optimize default Proj's yet */
if (get_tarval_long(tb) == num) {
/* Do NOT create a jump here, or we will have 2 control flow ops
* in a block. This case is optimized away in optimize_cf(). */
*/
static ir_node *create_zero_const(ir_mode *mode) {
tarval *tv = get_mode_null(mode);
- ir_node *cnst = new_Const(mode, tv);
+ ir_node *cnst = new_Const(tv);
return cnst;
}
/* we can evaluate some cases directly */
switch (proj_nr) {
case pn_Cmp_False:
- return new_Const(mode_b, get_tarval_b_false());
+ return new_Const(get_tarval_b_false());
case pn_Cmp_True:
- return new_Const(mode_b, get_tarval_b_true());
+ return new_Const(get_tarval_b_true());
case pn_Cmp_Leg:
if (!mode_is_float(get_irn_mode(left)))
- return new_Const(mode_b, get_tarval_b_true());
+ return new_Const(get_tarval_b_true());
break;
default:
break;
DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_OP_OP);
}
}
+ if (is_And(left) && is_Const(right)) {
+ ir_node *ll = get_binop_left(left);
+ ir_node *lr = get_binop_right(left);
+ if (is_Shr(ll) && is_Const(lr)) {
+ /* Cmp((x >>u c1) & c2, c3) = Cmp(x & (c2 << c1), c3 << c1) */
+ ir_node *block = get_nodes_block(n);
+ ir_mode *mode = get_irn_mode(left);
+
+ ir_node *llr = get_Shr_right(ll);
+ if (is_Const(llr)) {
+ ir_graph *irg = current_ir_graph;
+ dbg_info *dbg = get_irn_dbg_info(left);
+
+ tarval *c1 = get_Const_tarval(llr);
+ tarval *c2 = get_Const_tarval(lr);
+ tarval *c3 = get_Const_tarval(right);
+ tarval *mask = tarval_shl(c2, c1);
+ tarval *value = tarval_shl(c3, c1);
+
+ left = new_rd_And(dbg, irg, block, get_Shr_left(ll), new_Const(mask), mode);
+ right = new_Const(value);
+ changed |= 1;
+ }
+ }
+ }
} /* mode_is_int(...) */
} /* proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg */
else if (proj_nr == pn_Cmp_Le || proj_nr == pn_Cmp_Lt) {
if (tv != tarval_bad) {
/* c >= 0 : Abs(a) <= c ==> (unsigned)(a + c) <= 2*c */
- if (get_irn_op(left) == op_Abs) { // TODO something is missing here
+ if (is_Abs(left)) { // TODO something is missing here
}
}
}
if (mask != tv) {
/* TODO: move to constant evaluation */
tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true();
- c1 = new_Const(mode_b, tv);
+ c1 = new_Const(tv);
DBG_OPT_CSTEVAL(proj, c1);
return c1;
}
if (! tarval_is_null(get_Const_tarval(c1))) {
/* TODO: move to constant evaluation */
tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true();
- c1 = new_Const(mode_b, tv);
+ c1 = new_Const(tv);
DBG_OPT_CSTEVAL(proj, c1);
return c1;
}
if (tarval_and(tv, cmask) != tv) {
/* condition not met */
tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true();
- c1 = new_Const(mode_b, tv);
+ c1 = new_Const(tv);
DBG_OPT_CSTEVAL(proj, c1);
return c1;
}
sl = get_Shl_left(left);
blk = get_nodes_block(n);
- left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(mode, amask), mode);
+ left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(amask), mode);
tv = tarval_shr(tv, tv1);
changed |= 2;
DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_SHF_TO_AND);
if (tarval_and(tv, cmask) != tv) {
/* condition not met */
tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true();
- c1 = new_Const(mode_b, tv);
+ c1 = new_Const(tv);
DBG_OPT_CSTEVAL(proj, c1);
return c1;
}
sl = get_Shr_left(left);
blk = get_nodes_block(n);
- left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(mode, amask), mode);
+ left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(amask), mode);
tv = tarval_shl(tv, tv1);
changed |= 2;
DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_SHF_TO_AND);
if (!tarval_is_all_one(cond) && !tarval_is_null(cond)) {
/* condition not met */
tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true();
- c1 = new_Const(mode_b, tv);
+ c1 = new_Const(tv);
DBG_OPT_CSTEVAL(proj, c1);
return c1;
}
sl = get_Shrs_left(left);
blk = get_nodes_block(n);
- left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(mode, amask), mode);
+ left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(amask), mode);
tv = tarval_shl(tv, tv1);
changed |= 2;
DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_SHF_TO_AND);
}
if (changed & 2) /* need a new Const */
- right = new_Const(mode, tv);
+ right = new_Const(tv);
if ((proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg) && is_Const(right) && is_Const_null(right) && is_Proj(left)) {
ir_node *op = get_Proj_pred(left);
ir_mode *mode = get_irn_mode(v);
tv = tarval_sub(tv, get_mode_one(mode), NULL);
- left = new_rd_And(get_irn_dbg_info(op), current_ir_graph, blk, v, new_Const(mode, tv), mode);
+ left = new_rd_And(get_irn_dbg_info(op), current_ir_graph, blk, v, new_Const(tv), mode);
changed |= 1;
DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_MOD_TO_AND);
}
block = get_irn_n(or, -1);
new_and = new_r_And(current_ir_graph, block,
- value, new_r_Const(current_ir_graph, block, mode, tarval_and(tv4, tv2)), mode);
+ value, new_Const(tarval_and(tv4, tv2)), mode);
- new_const = new_r_Const(current_ir_graph, block, mode, tarval_or(tv3, tv1));
+ new_const = new_Const(tarval_or(tv3, tv1));
set_Or_left(or, new_and);
set_Or_right(or, new_const);
/* beware: a simple replacement works only, if res < modulo shift */
if (!is_Rotl(n)) {
int modulo_shf = get_mode_modulo_shift(mode);
- assert(modulo_shf >= (int) get_mode_size_bits(mode));
if (modulo_shf > 0) {
tarval *modulo = new_tarval_from_long(modulo_shf,
get_tarval_mode(res));
+ assert(modulo_shf >= (int) get_mode_size_bits(mode));
+
/* shifting too much */
if (!(tarval_cmp(res, modulo) & pn_Cmp_Lt)) {
if (is_Shrs(n)) {
ir_graph *irg = get_irn_irg(n);
ir_node *block = get_nodes_block(n);
dbg_info *dbgi = get_irn_dbg_info(n);
- ir_node *cnst = new_Const(mode_Iu, new_tarval_from_long(get_mode_size_bits(mode)-1, mode_Iu));
+ ir_mode *smode = get_irn_mode(right);
+ ir_node *cnst = new_Const_long(smode, get_mode_size_bits(mode) - 1);
return new_rd_Shrs(dbgi, irg, block, get_binop_left(left),
cnst, mode);
}
- return new_Const(mode, get_mode_null(mode));
+ return new_Const(get_mode_null(mode));
}
}
} else {
block = get_nodes_block(n);
in[0] = get_binop_left(left);
- in[1] = new_r_Const(current_ir_graph, block, get_tarval_mode(res), res);
+ in[1] = new_Const(res);
irn = new_ir_node(NULL, current_ir_graph, block, get_irn_op(n), mode, 2, in);
}
assert(get_tarval_mode(tv_shift) == mode);
- new_const = new_Const(mode, tv_shift);
+ new_const = new_Const(tv_shift);
if (op_left == op_And) {
new_bitop = new_rd_And(dbgi, irg, block, new_shift, new_const, mode);
return n;
}
- assert(get_tarval_mode(tv_shl) == get_tarval_mode(tv_shr));
+ if (get_tarval_mode(tv_shl) != get_tarval_mode(tv_shr)) {
+ tv_shl = tarval_convert_to(tv_shl, get_tarval_mode(tv_shr));
+ }
+
assert(tv_mask != tarval_bad);
assert(get_tarval_mode(tv_mask) == mode);
pnc = tarval_cmp(tv_shl, tv_shr);
if (pnc == pn_Cmp_Lt || pnc == pn_Cmp_Eq) {
tv_shift = tarval_sub(tv_shr, tv_shl, NULL);
- new_const = new_Const(get_tarval_mode(tv_shift), tv_shift);
+ new_const = new_Const(tv_shift);
if (need_shrs) {
new_shift = new_rd_Shrs(dbgi, irg, block, x, new_const, mode);
} else {
} else {
assert(pnc == pn_Cmp_Gt);
tv_shift = tarval_sub(tv_shl, tv_shr, NULL);
- new_const = new_Const(get_tarval_mode(tv_shift), tv_shift);
+ new_const = new_Const(tv_shift);
new_shift = new_rd_Shl(dbgi, irg, block, x, new_const, mode);
}
- new_const = new_Const(mode, tv_mask);
+ new_const = new_Const(tv_mask);
new_and = new_rd_And(dbgi, irg, block, new_shift, new_const, mode);
return new_and;
*/
static ir_node *transform_node_Conv(ir_node *n) {
ir_node *c, *oldn = n;
- ir_node *a = get_Conv_op(n);
+ ir_mode *mode = get_irn_mode(n);
+ ir_node *a = get_Conv_op(n);
- if (is_const_Phi(a)) {
- c = apply_conv_on_phi(a, get_irn_mode(n));
+ if (mode != mode_b && is_const_Phi(a)) {
+ /* Do NOT optimize mode_b Conv's, this leads to remaining
+ * Phib nodes later, because the conv_b_lower operation
+ * is instantly reverted, when it tries to insert a Convb.
+ */
+ c = apply_conv_on_phi(a, mode);
if (c) {
DBG_OPT_ALGSIM0(oldn, c, FS_OPT_CONST_PHI);
return c;
}
if (is_Unknown(a)) { /* Conv_A(Unknown_B) -> Unknown_A */
- ir_mode *mode = get_irn_mode(n);
return new_r_Unknown(current_ir_graph, mode);
}
+ if (mode_is_reference(mode) &&
+ get_mode_size_bits(mode) == get_mode_size_bits(get_irn_mode(a)) &&
+ is_Add(a)) {
+ ir_node *l = get_Add_left(a);
+ ir_node *r = get_Add_right(a);
+ dbg_info *dbgi = get_irn_dbg_info(a);
+ ir_node *block = get_nodes_block(n);
+ if(is_Conv(l)) {
+ ir_node *lop = get_Conv_op(l);
+ if(get_irn_mode(lop) == mode) {
+ /* ConvP(AddI(ConvI(P), x)) -> AddP(P, x) */
+ n = new_rd_Add(dbgi, current_ir_graph, block, lop, r, mode);
+ return n;
+ }
+ }
+ if(is_Conv(r)) {
+ ir_node *rop = get_Conv_op(r);
+ if(get_irn_mode(rop) == mode) {
+ /* ConvP(AddI(x, ConvI(P))) -> AddP(x, P) */
+ n = new_rd_Add(dbgi, current_ir_graph, block, l, rop, mode);
+ return n;
+ }
+ }
+ }
+
return n;
} /* transform_node_Conv */
continue;
} else if (is_irn_pinned_in_irg(ka) && is_Block_dead(get_nodes_block(ka))) {
continue;
+ } else if (is_Bad(ka)) {
+ /* no need to keep Bad */
+ continue;
}
- /* FIXME: beabi need to keep a Proj(M) */
- if (is_Phi(ka) || is_irn_keep(ka) || is_Proj(ka))
- in[j++] = ka;
+ in[j++] = ka;
}
if (j != n_keepalives)
set_End_keepalives(n, j, in);
dbg_info *dbg = get_irn_dbg_info(n);
ir_node *block = get_nodes_block(n);
ir_graph *irg = current_ir_graph;
- ir_node *t = new_Const(mode, tarval_sub(a, min, NULL));
- ir_node *f = new_Const(mode, tarval_sub(b, min, NULL));
+ ir_node *t = new_Const(tarval_sub(a, min, NULL));
+ ir_node *f = new_Const(tarval_sub(b, min, NULL));
n = new_rd_Mux(dbg, irg, block, sel, f, t, mode);
- n = new_rd_Add(dbg, irg, block, n, new_Const(mode, min), mode);
+ n = new_rd_Add(dbg, irg, block, n, new_Const(min), mode);
return n;
}
}
}
}
}
- return arch_transform_node_Mux(n);
+
+ return n;
} /* transform_node_Mux */
/**
add_identities(current_ir_graph->value_table, n);
return n;
-}
+} /* transform_node_Sync */
+
+/**
+ * optimize a trampoline Call into a direct Call
+ */
+static ir_node *transform_node_Call(ir_node *call) {
+ ir_node *callee = get_Call_ptr(call);
+ ir_node *adr, *mem, *res, *bl, **in;
+ ir_type *ctp, *mtp, *tp;
+ ident *id;
+ dbg_info *db;
+ int i, n_res, n_param;
+ ir_variadicity var;
+
+ if (! is_Proj(callee))
+ return call;
+ callee = get_Proj_pred(callee);
+ if (! is_Builtin(callee))
+ return call;
+ if (get_Builtin_kind(callee) != ir_bk_inner_trampoline)
+ return call;
+
+ mem = get_Call_mem(call);
+
+ if (skip_Proj(mem) == callee) {
+ /* memory is routed to the trampoline, skip */
+ mem = get_Builtin_mem(callee);
+ }
+
+ /* build a new call type */
+ mtp = get_Call_type(call);
+ id = get_type_ident(mtp);
+ id = id_mangle(new_id_from_chars("T_", 2), id);
+ db = get_type_dbg_info(mtp);
+
+ n_res = get_method_n_ress(mtp);
+ n_param = get_method_n_params(mtp);
+ ctp = new_d_type_method(id, n_param + 1, n_res, db);
+
+ for (i = 0; i < n_res; ++i)
+ set_method_res_type(ctp, i, get_method_res_type(mtp, i));
+
+ NEW_ARR_A(ir_node *, in, n_param + 1);
+
+ /* FIXME: we don't need a new pointer type in every step */
+ tp = get_irg_frame_type(current_ir_graph);
+ id = id_mangle(get_type_ident(tp), new_id_from_chars("_ptr", 4));
+ tp = new_type_pointer(id, tp, mode_P_data);
+ set_method_param_type(ctp, 0, tp);
+
+ in[0] = get_Builtin_param(callee, 2);
+ for (i = 0; i < n_param; ++i) {
+ set_method_param_type(ctp, i + 1, get_method_param_type(mtp, i));
+ in[i + 1] = get_Call_param(call, i);
+ }
+ var = get_method_variadicity(mtp);
+ set_method_variadicity(ctp, var);
+ if (var == variadicity_variadic) {
+ set_method_first_variadic_param_index(ctp, get_method_first_variadic_param_index(mtp) + 1);
+ }
+ /* When we resolve a trampoline, the function must be called by a this-call */
+ set_method_calling_convention(ctp, get_method_calling_convention(mtp) | cc_this_call);
+ set_method_additional_properties(ctp, get_method_additional_properties(mtp));
+
+ adr = get_Builtin_param(callee, 1);
+
+ db = get_irn_dbg_info(call);
+ bl = get_nodes_block(call);
+
+ res = new_rd_Call(db, current_ir_graph, bl, mem, adr, n_param + 1, in, ctp);
+ if (get_irn_pinned(call) == op_pin_state_floats)
+ set_irn_pinned(res, op_pin_state_floats);
+ return res;
+} /* transform_node_Call */
/**
* Tries several [inplace] [optimizing] transformations and returns an
CASE(End);
CASE(Mux);
CASE(Sync);
+ CASE(Call);
default:
/* leave NULL */;
}
const divmod_attr *ma = get_irn_divmod_attr(a);
const divmod_attr *mb = get_irn_divmod_attr(b);
return ma->exc.pin_state != mb->exc.pin_state ||
- ma->res_mode != mb->res_mode ||
+ ma->resmode != mb->resmode ||
ma->no_remainder != mb->no_remainder;
} /* node_cmp_attr_Div */
const divmod_attr *ma = get_irn_divmod_attr(a);
const divmod_attr *mb = get_irn_divmod_attr(b);
return ma->exc.pin_state != mb->exc.pin_state ||
- ma->res_mode != mb->res_mode;
+ ma->resmode != mb->resmode;
} /* node_cmp_attr_DivMod */
/** Compares the attributes of two Mod nodes. */
const divmod_attr *ma = get_irn_divmod_attr(a);
const divmod_attr *mb = get_irn_divmod_attr(b);
return ma->exc.pin_state != mb->exc.pin_state ||
- ma->res_mode != mb->res_mode;
+ ma->resmode != mb->resmode;
} /* node_cmp_attr_Mod */
/** Compares the attributes of two Quot nodes. */
const divmod_attr *ma = get_irn_divmod_attr(a);
const divmod_attr *mb = get_irn_divmod_attr(b);
return ma->exc.pin_state != mb->exc.pin_state ||
- ma->res_mode != mb->res_mode;
+ ma->resmode != mb->resmode;
} /* node_cmp_attr_Quot */
/** Compares the attributes of two Confirm nodes. */
static int node_cmp_attr_Confirm(ir_node *a, ir_node *b) {
+ /* no need to compare the bound, as this is a input */
return (get_Confirm_cmp(a) != get_Confirm_cmp(b));
} /* node_cmp_attr_Confirm */
+/** Compares the attributes of two Builtin nodes. */
+static int node_cmp_attr_Builtin(ir_node *a, ir_node *b) {
+ const builtin_attr *ma = get_irn_builtin_attr(a);
+ const builtin_attr *mb = get_irn_builtin_attr(b);
+
+ /* no need to compare the type, equal kind means equal type */
+ return ma->kind != mb->kind;
+} /* node_cmp_attr_Builtin */
+
/** Compares the attributes of two ASM nodes. */
static int node_cmp_attr_ASM(ir_node *a, ir_node *b) {
int i, n;
return 0;
} /* node_cmp_attr_ASM */
+/** Compares the inexistent attributes of two Dummy nodes. */
+static int node_cmp_attr_Dummy(ir_node *a, ir_node *b)
+{
+ (void) a;
+ (void) b;
+ return 1;
+}
+
/**
* Set the default node attribute compare operation for an ir_op_ops.
*
CASE(Mod);
CASE(Quot);
CASE(Bound);
+ CASE(Builtin);
+ CASE(Dummy);
/* FIXME CopyB */
default:
/* leave NULL */;
del_pset(value_table);
} /* del_identities */
-/**
- * Normalize a node by putting constants (and operands with larger
- * node index) on the right (operator side).
- *
- * @param n The node to normalize
- */
-static void normalize_node(ir_node *n) {
+/* Normalize a node by putting constants (and operands with larger
+ * node index) on the right (operator side). */
+void ir_normalize_node(ir_node *n) {
if (is_op_commutative(get_irn_op(n))) {
ir_node *l = get_binop_left(n);
ir_node *r = get_binop_right(n);
if (!operands_are_normalized(l, r)) {
set_binop_left(n, r);
set_binop_right(n, l);
+ hook_normalize(n);
}
}
-} /* normalize_node */
+} /* ir_normalize_node */
/**
* Update the nodes after a match in the value table. If both nodes have
if (!value_table) return n;
- normalize_node(n);
+ ir_normalize_node(n);
/* lookup or insert in hash table with given hash key. */
o = pset_insert(value_table, n, ir_node_hash(n));
* @param value_table The value table
* @param n The node to lookup
*/
-static INLINE ir_node *identify_cons(pset *value_table, ir_node *n) {
+static inline ir_node *identify_cons(pset *value_table, ir_node *n) {
ir_node *old = n;
n = identify_remember(value_table, n);
/* neither constants nor Tuple values can be evaluated */
if (iro != iro_Const && (get_irn_mode(n) != mode_T)) {
unsigned fp_model = get_irg_fp_model(current_ir_graph);
- int old_fp_mode = tarval_enable_fp_ops((fp_model & fp_strict_algebraic) == 0);
+ int old_fp_mode = tarval_fp_ops_enabled();
+
+ tarval_enable_fp_ops(! (fp_model & fp_no_float_fold));
+
/* try to evaluate */
tv = computed_value(n);
if (tv != tarval_bad) {
/* evaluation was successful -- replace the node. */
irg_kill_node(current_ir_graph, n);
- nw = new_Const(get_tarval_mode(tv), tv);
+ nw = new_Const(tv);
if (old_tp && get_type_mode(old_tp) == get_tarval_mode(tv))
set_Const_type(nw, old_tp);
/* neither constants nor Tuple values can be evaluated */
if (iro != iro_Const && get_irn_mode(n) != mode_T) {
unsigned fp_model = get_irg_fp_model(current_ir_graph);
- int old_fp_mode = tarval_enable_fp_ops((fp_model & fp_strict_algebraic) == 0);
+ int old_fp_mode = tarval_fp_ops_enabled();
+
+ tarval_enable_fp_ops((fp_model & fp_strict_algebraic) == 0);
/* try to evaluate */
tv = computed_value(n);
if (tv != tarval_bad) {
for (i = 0; i < arity && !old_tp; ++i)
old_tp = get_irn_type(get_irn_n(n, i));
- n = new_Const(get_tarval_mode(tv), tv);
+ n = new_Const(tv);
if (old_tp && get_type_mode(old_tp) == get_tarval_mode(tv))
set_Const_type(n, old_tp);