Commit d8cfa4ee by Richard Kenner

(get_condition): Check for overflow when canonicalizing comparison.

From-SVN: r2863
parent 2af69b62
...@@ -6386,34 +6386,43 @@ get_condition (jump, earliest) ...@@ -6386,34 +6386,43 @@ get_condition (jump, earliest)
if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC) if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC)
return 0; return 0;
/* Canonicalize any ordered comparison with integers involving equality. */ /* Canonicalize any ordered comparison with integers involving equality
if (GET_CODE (op1) == CONST_INT) if we can do computations in the relevant mode and we do not
overflow. */
if (GET_CODE (op1) == CONST_INT
&& GET_MODE (op0) != VOIDmode
&& GET_MODE_BITSIZE (GET_MODE (op0)) <= HOST_BITS_PER_WIDE_INT)
{ {
HOST_WIDE_INT const_val = INTVAL (op1); HOST_WIDE_INT const_val = INTVAL (op1);
unsigned HOST_WIDE_INT uconst_val = const_val; unsigned HOST_WIDE_INT uconst_val = const_val;
unsigned HOST_WIDE_INT max_val
= (unsigned HOST_WIDE_INT) GET_MODE_MASK (GET_MODE (op0));
switch (code) switch (code)
{ {
case LE: case LE:
code = LT; if (const_val != max_val >> 1)
op1 = GEN_INT (const_val + 1); code = LT, op1 = GEN_INT (const_val + 1);
break; break;
case GE: case GE:
code = GT; if (const_val
op1 = GEN_INT (const_val - 1); != (((HOST_WIDE_INT) 1
break; << (GET_MODE_BITSIZE (GET_MODE (op0)) - 1))))
code = GT, op1 = GEN_INT (const_val - 1);
break;
case LEU: case LEU:
code = LTU; if (uconst_val != max_val)
op1 = GEN_INT (uconst_val + 1); code = LTU, op1 = GEN_INT (uconst_val + 1);
break; break;
case GEU: case GEU:
code = GTU; if (uconst_val != 0)
op1 = GEN_INT (uconst_val - 1); code = GTU, op1 = GEN_INT (uconst_val - 1);
break; break;
} }
} }
/* If this was floating-point and we reversed anything other than an /* If this was floating-point and we reversed anything other than an
......
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