Commit 1a61ee97 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Make Sub of two pointers more strict.

The pointer modes must be identical now.
parent 654f4a73
......@@ -132,21 +132,6 @@ static bool check_mode_same_input(const ir_node *n, int input,
return true;
}
static bool check_mode_ptrdiff_input(const ir_node *n, int input,
const char *inputname)
{
ir_node *in = get_irn_n(n, input);
ir_mode *in_mode = get_irn_mode(in);
ir_mode *expected = get_reference_offset_mode(in_mode);
ir_mode *mode = get_irn_mode(n);
if (mode != expected) {
warn(n, "Sub with mode %+F at input %s expected mode %+F but has %+F",
in_mode, inputname, expected, mode);
return false;
}
return true;
}
/**
* Displays error message that a wrong proj number was found and returns false.
*/
......@@ -686,10 +671,9 @@ static int verify_node_Sub(const ir_node *n)
if (mode_is_num(mode)) {
ir_mode *mode_left = get_irn_mode(get_Sub_left(n));
if (mode_is_reference(mode_left)) {
fine &= check_input_func(n, n_Sub_left, "left", mode_is_reference, "reference");
fine &= check_input_func(n, n_Sub_right, "right", mode_is_reference, "reference");
fine &= check_mode_ptrdiff_input(n, n_Sub_left, "left");
fine &= check_mode_ptrdiff_input(n, n_Sub_right, "right");
fine &= check_input_mode(n, n_Sub_right, "right", mode_left);
ir_mode *const offset_mode = get_reference_offset_mode(mode_left);
fine &= check_mode(n, offset_mode);
} else {
fine &= check_mode_same_input(n, n_Sub_left, "left");
fine &= check_mode_same_input(n, n_Sub_right, "right");
......
......@@ -1106,22 +1106,16 @@ static ir_node *equivalent_node_Add(ir_node *n)
ir_node *left = get_Add_left(n);
if (is_Sub(left) && get_Sub_right(left) == right) {
/* (a - x) + x */
/* (a - x) + x -> a */
n = get_Sub_left(left);
if (mode == get_irn_mode(n)) {
DBG_OPT_ALGSIM1(oldn, left, right, n);
return n;
}
DBG_OPT_ALGSIM1(oldn, left, right, n);
return n;
}
if (is_Sub(right) && get_Sub_right(right) == left) {
/* x + (a - x) */
/* x + (a - x) -> a */
n = get_Sub_left(right);
if (mode == get_irn_mode(n)) {
DBG_OPT_ALGSIM1(oldn, left, right, n);
return n;
}
DBG_OPT_ALGSIM1(oldn, left, right, n);
return n;
}
return n;
}
......@@ -3451,22 +3445,16 @@ static ir_node *transform_node_Sub(ir_node *n)
/* check if it's allowed to skip the conv */
ir_mode *ma = get_irn_mode(op_a);
ir_mode *mb = get_irn_mode(op_b);
if (mode_is_reference(ma) && mode_is_reference(mb)) {
unsigned const mode_size = get_mode_size_bits(mode);
unsigned const ma_size = get_mode_size_bits(ma);
unsigned const mb_size = get_mode_size_bits(mb);
ir_mode *const offset_mode_a = get_reference_offset_mode(ma);
ir_mode *const offset_mode_b = get_reference_offset_mode(mb);
if (ma_size == mode_size && mb_size == mode_size
&& offset_mode_a == offset_mode_b) {
if (mode_is_reference(ma) && ma == get_irn_mode(op_b)) {
unsigned const mode_size = get_mode_size_bits(mode);
unsigned const ma_size = get_mode_size_bits(ma);
if (ma_size == mode_size) {
ir_mode *const offset_mode = get_reference_offset_mode(ma);
/* SubInt(ConvInt(aP), ConvInt(bP)) -> SubInt(aP,bP) */
dbg_info *const dbgi = get_irn_dbg_info(n);
ir_node *const block = get_nodes_block(n);
ir_node *const new_sub
= new_rd_Sub(dbgi, block, op_a, op_b, offset_mode_a);
= new_rd_Sub(dbgi, block, op_a, op_b, offset_mode);
ir_node *const conv
= new_rd_Conv(dbgi, block, new_sub, mode);
return conv;
......
Markdown is supported
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