Commit cf16446f authored by yb9976's avatar yb9976
Browse files

Do not perform optimization in case of overflows.

This fixes opt/fehler222.c.
parent c6c182ad
......@@ -4080,23 +4080,32 @@ static ir_node *transform_node_Cmp(ir_node *n)
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)) {
dbg_info *dbg = get_irn_dbg_info(left);
ir_graph *irg = get_irn_irg(left);
ir_tarval *c1 = get_Const_tarval(llr);
ir_tarval *c2 = get_Const_tarval(lr);
ir_tarval *c3 = get_Const_tarval(right);
ir_tarval *mask = tarval_shl(c2, c1);
ir_tarval *value = tarval_shl(c3, c1);
left = new_rd_And(dbg, block, get_Shr_left(ll), new_r_Const(irg, mask), mode);
right = new_r_Const(irg, value);
changed = true;
if (is_Const(llr)) {
ir_tarval *c1 = get_Const_tarval(llr);
ir_tarval *c2 = get_Const_tarval(lr);
ir_tarval *c3 = get_Const_tarval(right);
assert(tarval_is_long(c1));
ir_mode *mode = get_irn_mode(left);
long l1 = get_tarval_long(c1);
long h2 = get_tarval_highest_bit(c2);
long h3 = get_tarval_highest_bit(c3);
long bits = get_mode_size_bits(mode);
if (l1 + h2 < bits && l1 + h3 < bits) {
dbg_info *dbg = get_irn_dbg_info(left);
ir_graph *irg = get_irn_irg(left);
ir_node *block = get_nodes_block(n);
ir_tarval *mask = tarval_shl(c2, c1);
ir_tarval *value = tarval_shl(c3, c1);
left = new_rd_And(dbg, block, get_Shr_left(ll), new_r_Const(irg, mask), mode);
right = new_r_Const(irg, value);
changed = true;
}
}
}
}
......
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