This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
patch for simplify-rtx.c signed/unsigned mismatches
- To: gcc-patches at gcc dot gnu dot org
- Subject: patch for simplify-rtx.c signed/unsigned mismatches
- From: Zack Weinberg <zack at wolery dot cumb dot org>
- Date: Mon, 22 May 2000 11:58:21 -0700
This patch corrects the signed/unsigned mismatch warnings in
simplify-rtx.c. They're mostly complaining about code where we do
arithmetic on a 2N-bit integer represented as a pair of N-bit integers
(where N is host word size). The lower word of the pair should be
considered unsigned except when doing sign extension.
Bootstrapped on i386-linux. I'd appreciate review and/or testing on
non-Intel hardware.
zw
* simplify-rtx.c (SIGN_EXTEND): New macro.
(simplify_unary_operation, simplify_binary_operation,
simplify_relational_operation): Use SIGN_EXTEND. Make low
halves of (low, high) pairs unsigned if they weren't already.
(simplify_ternary_operation): Cast INTVAL to unsigned before
comparing to a MODE_BITSIZE.
===================================================================
Index: simplify-rtx.c
--- simplify-rtx.c 2000/05/22 08:20:47 1.17
+++ simplify-rtx.c 2000/05/22 18:54:12
@@ -92,6 +92,12 @@ Boston, MA 02111-1307, USA. */
|| XEXP (X, 0) == virtual_outgoing_args_rtx)) \
|| GET_CODE (X) == ADDRESSOF)
+/* Much code operates on (low, high) pairs; the low value is an
+ unsigned wide int, the high value a signed wide int. We
+ occasionally need to sign extend from low to high as if low were a
+ signed wide int. */
+#define SIGN_EXTEND(low) \
+ ((((HOST_WIDE_INT) low) < 0) ? ((HOST_WIDE_INT) -1) : ((HOST_WIDE_INT) 0))
static rtx simplify_plus_minus PARAMS ((enum rtx_code,
enum machine_mode, rtx, rtx));
@@ -246,7 +252,7 @@ simplify_unary_operation (code, mode, op
REAL_VALUE_TYPE d;
if (GET_CODE (op) == CONST_INT)
- lv = INTVAL (op), hv = INTVAL (op) < 0 ? -1 : 0;
+ lv = INTVAL (op), hv = SIGN_EXTEND (lv);
else
lv = CONST_DOUBLE_LOW (op), hv = CONST_DOUBLE_HIGH (op);
@@ -279,7 +285,7 @@ simplify_unary_operation (code, mode, op
REAL_VALUE_TYPE d;
if (GET_CODE (op) == CONST_INT)
- lv = INTVAL (op), hv = INTVAL (op) < 0 ? -1 : 0;
+ lv = INTVAL (op), hv = SIGN_EXTEND (lv);
else
lv = CONST_DOUBLE_LOW (op), hv = CONST_DOUBLE_HIGH (op);
@@ -399,12 +405,13 @@ simplify_unary_operation (code, mode, op
else if (GET_MODE (op) == VOIDmode && width <= HOST_BITS_PER_INT * 2
&& (GET_CODE (op) == CONST_DOUBLE || GET_CODE (op) == CONST_INT))
{
- HOST_WIDE_INT l1, h1, lv, hv;
+ unsigned HOST_WIDE_INT l1, lv;
+ HOST_WIDE_INT h1, hv;
if (GET_CODE (op) == CONST_DOUBLE)
l1 = CONST_DOUBLE_LOW (op), h1 = CONST_DOUBLE_HIGH (op);
else
- l1 = INTVAL (op), h1 = l1 < 0 ? -1 : 0;
+ l1 = INTVAL (op), h1 = SIGN_EXTEND (l1);
switch (code)
{
@@ -458,7 +465,7 @@ simplify_unary_operation (code, mode, op
<< (GET_MODE_BITSIZE (op_mode) - 1))) != 0)
lv -= (HOST_WIDE_INT) 1 << GET_MODE_BITSIZE (op_mode);
- hv = (lv < 0) ? ~ (HOST_WIDE_INT) 0 : 0;
+ hv = SIGN_EXTEND (lv);
}
break;
@@ -709,17 +716,18 @@ simplify_binary_operation (code, mode, o
&& (GET_CODE (op0) == CONST_DOUBLE || GET_CODE (op0) == CONST_INT)
&& (GET_CODE (op1) == CONST_DOUBLE || GET_CODE (op1) == CONST_INT))
{
- HOST_WIDE_INT l1, l2, h1, h2, lv, hv;
+ unsigned HOST_WIDE_INT l1, l2, lv;
+ HOST_WIDE_INT h1, h2, hv;
if (GET_CODE (op0) == CONST_DOUBLE)
l1 = CONST_DOUBLE_LOW (op0), h1 = CONST_DOUBLE_HIGH (op0);
else
- l1 = INTVAL (op0), h1 = l1 < 0 ? -1 : 0;
+ l1 = INTVAL (op0), h1 = SIGN_EXTEND (l1);
if (GET_CODE (op1) == CONST_DOUBLE)
l2 = CONST_DOUBLE_LOW (op1), h2 = CONST_DOUBLE_HIGH (op1);
else
- l2 = INTVAL (op1), h2 = l2 < 0 ? -1 : 0;
+ l2 = INTVAL (op1), h2 = SIGN_EXTEND (l2);
switch (code)
{
@@ -803,7 +811,7 @@ simplify_binary_operation (code, mode, o
l2 &= (GET_MODE_BITSIZE (mode) - 1), h2 = 0;
#endif
- if (h2 != 0 || l2 < 0 || l2 >= GET_MODE_BITSIZE (mode))
+ if (h2 != 0 || l2 >= GET_MODE_BITSIZE (mode))
return 0;
if (code == LSHIFTRT || code == ASHIFTRT)
@@ -1752,7 +1760,7 @@ simplify_relational_operation (code, mod
else
{
l0u = l0s = INTVAL (op0);
- h0u = h0s = l0s < 0 ? -1 : 0;
+ h0u = h0s = SIGN_EXTEND (l0s);
}
if (GET_CODE (op1) == CONST_DOUBLE)
@@ -1763,13 +1771,13 @@ simplify_relational_operation (code, mod
else
{
l1u = l1s = INTVAL (op1);
- h1u = h1s = l1s < 0 ? -1 : 0;
+ h1u = h1s = SIGN_EXTEND (l1s);
}
/* If WIDTH is nonzero and smaller than HOST_BITS_PER_WIDE_INT,
we have to sign or zero-extend the values. */
if (width != 0 && width <= HOST_BITS_PER_WIDE_INT)
- h0u = h1u = 0, h0s = l0s < 0 ? -1 : 0, h1s = l1s < 0 ? -1 : 0;
+ h0u = h1u = 0, h0s = SIGN_EXTEND (l0s), h1s = SIGN_EXTEND (l1s);
if (width != 0 && width < HOST_BITS_PER_WIDE_INT)
{
@@ -1904,7 +1912,8 @@ simplify_ternary_operation (code, mode,
if (GET_CODE (op0) == CONST_INT
&& GET_CODE (op1) == CONST_INT
&& GET_CODE (op2) == CONST_INT
- && INTVAL (op1) + INTVAL (op2) <= GET_MODE_BITSIZE (op0_mode)
+ && ((unsigned) INTVAL (op1) + (unsigned) INTVAL (op2)
+ <= GET_MODE_BITSIZE (op0_mode))
&& width <= (unsigned) HOST_BITS_PER_WIDE_INT)
{
/* Extracting a bit-field from a constant */