This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed] Prefer fold_convert to convert in middle-end
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 21 May 2004 10:44:54 -0600 (MDT)
- Subject: [Committed] Prefer fold_convert to convert in middle-end
The following patch replaces a number of uses of "convert" to use
the preferred language-independent fold_convert in both fold-const.c
and builtins.c. It also fixes a number of places where builtins.c
was returning integer_zero_node without converting it to the required
type.
The following patch was tested on i686-pc-linux-gnu with a complete
"make bootstrap", all current languages, and regression tested with
a top-level "make -k check" with no new failures. Committed to
mainline CVS.
2004-05-21 Roger Sayle <roger@eyesopen.com>
* fold-const.c (fold, fold_relational_hi_lo,
nondestructive_fold_binary_to_constant,
fold_read_from_constant_string): Use fold_convert instead of convert.
* builtins.c (simplify_builtin, simplify_builtin_strstr,
simplify_builtin_strchr, simplify_builtin_strrchr,
simplify_builtin_strpbrk): Use fold_convert instead of convert.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.379
diff -c -3 -p -r1.379 fold-const.c
*** fold-const.c 21 May 2004 00:54:35 -0000 1.379
--- fold-const.c 21 May 2004 13:09:10 -0000
*************** fold (tree expr)
*** 5831,5837 ****
tree s1 = TYPE_SIZE (tt1);
if (s0 && s1 && operand_equal_p (s0, s1, OEP_ONLY_CONST))
! return build2 (TREE_CODE (arg0), t0, convert (t0, arg00),
TREE_OPERAND (arg0, 1));
}
--- 5831,5837 ----
tree s1 = TYPE_SIZE (tt1);
if (s0 && s1 && operand_equal_p (s0, s1, OEP_ONLY_CONST))
! return build2 (TREE_CODE (arg0), t0, fold_convert (t0, arg00),
TREE_OPERAND (arg0, 1));
}
*************** fold_relational_hi_lo (enum tree_code *c
*** 9147,9160 ****
{
case GT_EXPR:
return omit_one_operand (type,
! convert (type, integer_zero_node),
op0);
case GE_EXPR:
*code_p = EQ_EXPR;
break;
case LE_EXPR:
return omit_one_operand (type,
! convert (type, integer_one_node),
op0);
case LT_EXPR:
*code_p = NE_EXPR;
--- 9147,9160 ----
{
case GT_EXPR:
return omit_one_operand (type,
! fold_convert (type, integer_zero_node),
op0);
case GE_EXPR:
*code_p = EQ_EXPR;
break;
case LE_EXPR:
return omit_one_operand (type,
! fold_convert (type, integer_one_node),
op0);
case LT_EXPR:
*code_p = NE_EXPR;
*************** fold_relational_hi_lo (enum tree_code *c
*** 9187,9193 ****
{
case LT_EXPR:
return omit_one_operand (type,
! convert (type, integer_zero_node),
op0);
case LE_EXPR:
*code_p = EQ_EXPR;
--- 9187,9193 ----
{
case LT_EXPR:
return omit_one_operand (type,
! fold_convert (type, integer_zero_node),
op0);
case LE_EXPR:
*code_p = EQ_EXPR;
*************** fold_relational_hi_lo (enum tree_code *c
*** 9195,9201 ****
case GE_EXPR:
return omit_one_operand (type,
! convert (type, integer_one_node),
op0);
case GT_EXPR:
*code_p = NE_EXPR;
--- 9195,9201 ----
case GE_EXPR:
return omit_one_operand (type,
! fold_convert (type, integer_one_node),
op0);
case GT_EXPR:
*code_p = NE_EXPR;
*************** fold_relational_hi_lo (enum tree_code *c
*** 9236,9243 ****
exp = build2 (code == LE_EXPR ? GE_EXPR: LT_EXPR,
type,
! convert (st0, op0),
! convert (st1, integer_zero_node));
retval
= nondestructive_fold_binary_to_constant (TREE_CODE (exp),
--- 9236,9243 ----
exp = build2 (code == LE_EXPR ? GE_EXPR: LT_EXPR,
type,
! fold_convert (st0, op0),
! fold_convert (st1, integer_zero_node));
retval
= nondestructive_fold_binary_to_constant (TREE_CODE (exp),
*************** nondestructive_fold_binary_to_constant (
*** 9341,9347 ****
/* The return value should always have the same type as
the original expression. */
if (TREE_TYPE (tem) != type)
! tem = convert (type, tem);
return tem;
}
--- 9341,9347 ----
/* The return value should always have the same type as
the original expression. */
if (TREE_TYPE (tem) != type)
! tem = fold_convert (type, tem);
return tem;
}
*************** nondestructive_fold_binary_to_constant (
*** 9354,9360 ****
Also note that operand_equal_p is always false if an
operand is volatile. */
if (! FLOAT_TYPE_P (type) && operand_equal_p (op0, op1, 0))
! return convert (type, integer_zero_node);
goto binary;
--- 9354,9360 ----
Also note that operand_equal_p is always false if an
operand is volatile. */
if (! FLOAT_TYPE_P (type) && operand_equal_p (op0, op1, 0))
! return fold_convert (type, integer_zero_node);
goto binary;
*************** fold_read_from_constant_string (tree exp
*** 9670,9676 ****
{
tree domain = TYPE_DOMAIN (TREE_TYPE (exp1));
tree low_bound = domain ? TYPE_MIN_VALUE (domain) : integer_zero_node;
! index = convert (sizetype, TREE_OPERAND (exp, 1));
/* Optimize the special-case of a zero lower bound.
--- 9670,9676 ----
{
tree domain = TYPE_DOMAIN (TREE_TYPE (exp1));
tree low_bound = domain ? TYPE_MIN_VALUE (domain) : integer_zero_node;
! index = fold_convert (sizetype, TREE_OPERAND (exp, 1));
/* Optimize the special-case of a zero lower bound.
*************** fold_read_from_constant_string (tree exp
*** 9680,9686 ****
+(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
+INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
if (! integer_zerop (low_bound))
! index = size_diffop (index, convert (sizetype, low_bound));
string = exp1;
}
--- 9680,9686 ----
+(INDEX-(unsigned char)1)) becomes ((ARRAY+(-(unsigned char)1))
+INDEX), which becomes (ARRAY+255+INDEX). Opps!) */
if (! integer_zerop (low_bound))
! index = size_diffop (index, fold_convert (sizetype, low_bound));
string = exp1;
}
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.323
diff -c -3 -p -r1.323 builtins.c
*** builtins.c 15 May 2004 18:17:20 -0000 1.323
--- builtins.c 21 May 2004 13:09:12 -0000
*************** simplify_builtin (tree exp, int ignore)
*** 8020,8026 ****
}
if (val)
! val = convert (TREE_TYPE (exp), val);
return val;
}
--- 8020,8026 ----
}
if (val)
! val = fold_convert (TREE_TYPE (exp), val);
return val;
}
*************** simplify_builtin_strstr (tree arglist)
*** 8061,8073 ****
{
const char *r = strstr (p1, p2);
- /* Return an offset into the constant string argument. */
if (r == NULL)
! return integer_zero_node;
! else
! return fold (build (PLUS_EXPR, TREE_TYPE (s1),
! s1, convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
}
if (p2[0] == '\0')
--- 8061,8073 ----
{
const char *r = strstr (p1, p2);
if (r == NULL)
! return fold_convert (TREE_TYPE (s1), integer_zero_node);
!
! /* Return an offset into the constant string argument. */
! return fold (build2 (PLUS_EXPR, TREE_TYPE (s1),
! s1, fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
}
if (p2[0] == '\0')
*************** simplify_builtin_strchr (tree arglist)
*** 8130,8141 ****
r = strchr (p1, c);
if (r == NULL)
! return integer_zero_node;
/* Return an offset into the constant string argument. */
return fold (build (PLUS_EXPR, TREE_TYPE (s1),
! s1, convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
}
/* FIXME: Should use here strchrM optab so that ports can optimize
--- 8130,8141 ----
r = strchr (p1, c);
if (r == NULL)
! return fold_convert (TREE_TYPE (s1), integer_zero_node);
/* Return an offset into the constant string argument. */
return fold (build (PLUS_EXPR, TREE_TYPE (s1),
! s1, fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
}
/* FIXME: Should use here strchrM optab so that ports can optimize
*************** simplify_builtin_strrchr (tree arglist)
*** 8187,8198 ****
r = strrchr (p1, c);
if (r == NULL)
! return integer_zero_node;
/* Return an offset into the constant string argument. */
return fold (build (PLUS_EXPR, TREE_TYPE (s1),
! s1, convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
}
if (! integer_zerop (s2))
--- 8187,8198 ----
r = strrchr (p1, c);
if (r == NULL)
! return fold_convert (TREE_TYPE (s1), integer_zero_node);
/* Return an offset into the constant string argument. */
return fold (build (PLUS_EXPR, TREE_TYPE (s1),
! s1, fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
}
if (! integer_zerop (s2))
*************** simplify_builtin_strpbrk (tree arglist)
*** 8245,8256 ****
const char *r = strpbrk (p1, p2);
if (r == NULL)
! return integer_zero_node;
/* Return an offset into the constant string argument. */
return fold (build (PLUS_EXPR, TREE_TYPE (s1),
! s1, convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
}
if (p2[0] == '\0')
--- 8245,8256 ----
const char *r = strpbrk (p1, p2);
if (r == NULL)
! return fold_convert (TREE_TYPE (s1), integer_zero_node);
/* Return an offset into the constant string argument. */
return fold (build (PLUS_EXPR, TREE_TYPE (s1),
! s1, fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
}
if (p2[0] == '\0')
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833