This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed] Convert builtins.c from build to buildN
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 22 May 2004 16:34:56 -0600 (MDT)
- Subject: [Committed] Convert builtins.c from build to buildN
The following clean-up continues the transition of the middle-end
from using "build" to using the new buildN functions, by converting
GCC's builtins.c.
The following patch has been tested on i686-pc-linux-gnu with a
complete "make bootstrap", all default languages, and regression
tested with a top-level "make -k check" with no new failures.
Committed to mainline CVS.
2004-05-22 Roger Sayle <roger@eyesopen.com>
* builtins.c (expand_builtin_strstr, expand_builtin_strchr,
expand_builtin_strrchr, expand_builtin_strpbrk,
expand_builtin_mempcpy, expand_builtin_memcmp,
expand_builtin_strcmp, expand_builtin_strncmp,
expand_builtin_strcat, std_expand_builtin_va_start,
std_expand_builtin_va_arg, expand_builtin_va_copy,
expand_builtin_signbit, fold_builtin_cabs,
fold_builtin_logarithm, fold_builtin_mempcpy,
fold_builtin_signbit, fold_builtin_isascii,
fold_builtin_toascii, fold_builtin_isdigit,
fold_builtin_1, build_function_call_expr,
simplify_builtin_strchr, simplify_builtin_strrchr,
simplify_builtin_strpbrk, simplify_builtin_strncpy,
simplify_builtin_memcmp, simplify_builtin_strcmp,
simplify_builtin_strncmp, simplify_builtin_strncat,
simplify_builtin_strspn, simplify_builtin_strcspn,
simplify_builtin_fputs, simplify_builtin_sprintf): Replace calls
to build with calls to build2, build3 or omit_one_operand.
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.324
diff -c -3 -p -r1.324 builtins.c
*** builtins.c 21 May 2004 16:39:38 -0000 1.324
--- builtins.c 22 May 2004 19:57:20 -0000
*************** expand_builtin_strstr (tree arglist, rtx
*** 2458,2464 ****
else
{
tree s1 = TREE_VALUE (arglist), s2 = TREE_VALUE (TREE_CHAIN (arglist));
! tree fn;
const char *p1, *p2;
p2 = c_getstr (s2);
--- 2458,2464 ----
else
{
tree s1 = TREE_VALUE (arglist), s2 = TREE_VALUE (TREE_CHAIN (arglist));
! tree fn, tmp;
const char *p1, *p2;
p2 = c_getstr (s2);
*************** expand_builtin_strstr (tree arglist, rtx
*** 2474,2483 ****
return const0_rtx;
/* Return an offset into the constant string argument. */
! return expand_expr (fold (build (PLUS_EXPR, TREE_TYPE (s1), s1,
! fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1)))),
! target, mode, EXPAND_NORMAL);
}
if (p2[0] == '\0')
--- 2474,2483 ----
return const0_rtx;
/* Return an offset into the constant string argument. */
! tmp = fold (build2 (PLUS_EXPR, TREE_TYPE (s1), s1,
! fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
! return expand_expr (tmp, target, mode, EXPAND_NORMAL);
}
if (p2[0] == '\0')
*************** expand_builtin_strchr (tree arglist, rtx
*** 2522,2527 ****
--- 2522,2528 ----
{
char c;
const char *r;
+ tree tmp;
if (target_char_cast (s2, &c))
return 0;
*************** expand_builtin_strchr (tree arglist, rtx
*** 2532,2541 ****
return const0_rtx;
/* Return an offset into the constant string argument. */
! return expand_expr (fold (build (PLUS_EXPR, TREE_TYPE (s1), s1,
! fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1)))),
! target, mode, EXPAND_NORMAL);
}
/* FIXME: Should use here strchrM optab so that ports can optimize
--- 2533,2542 ----
return const0_rtx;
/* Return an offset into the constant string argument. */
! tmp = fold (build2 (PLUS_EXPR, TREE_TYPE (s1), s1,
! fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
! return expand_expr (tmp, target, mode, EXPAND_NORMAL);
}
/* FIXME: Should use here strchrM optab so that ports can optimize
*************** expand_builtin_strrchr (tree arglist, rt
*** 2556,2562 ****
else
{
tree s1 = TREE_VALUE (arglist), s2 = TREE_VALUE (TREE_CHAIN (arglist));
! tree fn;
const char *p1;
if (TREE_CODE (s2) != INTEGER_CST)
--- 2557,2563 ----
else
{
tree s1 = TREE_VALUE (arglist), s2 = TREE_VALUE (TREE_CHAIN (arglist));
! tree fn, tmp;
const char *p1;
if (TREE_CODE (s2) != INTEGER_CST)
*************** expand_builtin_strrchr (tree arglist, rt
*** 2577,2586 ****
return const0_rtx;
/* Return an offset into the constant string argument. */
! return expand_expr (fold (build (PLUS_EXPR, TREE_TYPE (s1), s1,
! fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1)))),
! target, mode, EXPAND_NORMAL);
}
if (! integer_zerop (s2))
--- 2578,2587 ----
return const0_rtx;
/* Return an offset into the constant string argument. */
! tmp = fold (build2 (PLUS_EXPR, TREE_TYPE (s1), s1,
! fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
! return expand_expr (tmp, target, mode, EXPAND_NORMAL);
}
if (! integer_zerop (s2))
*************** expand_builtin_strpbrk (tree arglist, rt
*** 2608,2614 ****
else
{
tree s1 = TREE_VALUE (arglist), s2 = TREE_VALUE (TREE_CHAIN (arglist));
! tree fn;
const char *p1, *p2;
p2 = c_getstr (s2);
--- 2609,2615 ----
else
{
tree s1 = TREE_VALUE (arglist), s2 = TREE_VALUE (TREE_CHAIN (arglist));
! tree fn, tmp;
const char *p1, *p2;
p2 = c_getstr (s2);
*************** expand_builtin_strpbrk (tree arglist, rt
*** 2624,2633 ****
return const0_rtx;
/* Return an offset into the constant string argument. */
! return expand_expr (fold (build (PLUS_EXPR, TREE_TYPE (s1), s1,
! fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1)))),
! target, mode, EXPAND_NORMAL);
}
if (p2[0] == '\0')
--- 2625,2634 ----
return const0_rtx;
/* Return an offset into the constant string argument. */
! tmp = fold (build2 (PLUS_EXPR, TREE_TYPE (s1), s1,
! fold_convert (TREE_TYPE (s1),
! ssize_int (r - p1))));
! return expand_expr (tmp, target, mode, EXPAND_NORMAL);
}
if (p2[0] == '\0')
*************** expand_builtin_mempcpy (tree arglist, rt
*** 2812,2821 ****
}
if (endp == 2)
! len = fold (build (MINUS_EXPR, TREE_TYPE (len), dest,
! integer_one_node));
len = fold_convert (TREE_TYPE (dest), len);
! expr = fold (build (PLUS_EXPR, TREE_TYPE (dest), dest, len));
return expand_expr (expr, target, mode, EXPAND_NORMAL);
}
--- 2813,2822 ----
}
if (endp == 2)
! len = fold (build2 (MINUS_EXPR, TREE_TYPE (len), len,
! integer_one_node));
len = fold_convert (TREE_TYPE (dest), len);
! expr = fold (build2 (PLUS_EXPR, TREE_TYPE (dest), dest, len));
return expand_expr (expr, target, mode, EXPAND_NORMAL);
}
*************** expand_builtin_memcmp (tree exp ATTRIBUT
*** 3369,3375 ****
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
fold_convert (cst_uchar_ptr_node, arg2))));
! tree result = fold (build (MINUS_EXPR, integer_type_node, ind1, ind2));
return expand_expr (result, target, mode, EXPAND_NORMAL);
}
--- 3370,3376 ----
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
fold_convert (cst_uchar_ptr_node, arg2))));
! tree result = fold (build2 (MINUS_EXPR, integer_type_node, ind1, ind2));
return expand_expr (result, target, mode, EXPAND_NORMAL);
}
*************** expand_builtin_strcmp (tree exp, rtx tar
*** 3497,3503 ****
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
fold_convert (cst_uchar_ptr_node, arg2))));
! tree result = fold (build (MINUS_EXPR, integer_type_node, ind1, ind2));
return expand_expr (result, target, mode, EXPAND_NORMAL);
}
--- 3498,3504 ----
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
fold_convert (cst_uchar_ptr_node, arg2))));
! tree result = fold (build2 (MINUS_EXPR, integer_type_node, ind1, ind2));
return expand_expr (result, target, mode, EXPAND_NORMAL);
}
*************** expand_builtin_strncmp (tree exp, rtx ta
*** 3662,3668 ****
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
fold_convert (cst_uchar_ptr_node, arg2))));
! tree result = fold (build (MINUS_EXPR, integer_type_node, ind1, ind2));
return expand_expr (result, target, mode, EXPAND_NORMAL);
}
--- 3663,3669 ----
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
fold_convert (cst_uchar_ptr_node, arg2))));
! tree result = fold (build2 (MINUS_EXPR, integer_type_node, ind1, ind2));
return expand_expr (result, target, mode, EXPAND_NORMAL);
}
*************** expand_builtin_strncmp (tree exp, rtx ta
*** 3721,3727 ****
return 0;
/* The actual new length parameter is MIN(len,arg3). */
! len = fold (build (MIN_EXPR, TREE_TYPE (len), len, arg3));
/* If we don't have POINTER_TYPE, call the function. */
if (arg1_align == 0 || arg2_align == 0)
--- 3722,3728 ----
return 0;
/* The actual new length parameter is MIN(len,arg3). */
! len = fold (build2 (MIN_EXPR, TREE_TYPE (len), len, arg3));
/* If we don't have POINTER_TYPE, call the function. */
if (arg1_align == 0 || arg2_align == 0)
*************** expand_builtin_strcat (tree arglist, rtx
*** 3815,3821 ****
build_tree_list (NULL_TREE,
dst)));
/* Create (dst + strlen (dst)). */
! newdst = fold (build (PLUS_EXPR, TREE_TYPE (dst), dst, newdst));
/* Prepend the new dst argument. */
arglist = tree_cons (NULL_TREE, newdst, arglist);
--- 3816,3822 ----
build_tree_list (NULL_TREE,
dst)));
/* Create (dst + strlen (dst)). */
! newdst = fold (build2 (PLUS_EXPR, TREE_TYPE (dst), dst, newdst));
/* Prepend the new dst argument. */
arglist = tree_cons (NULL_TREE, newdst, arglist);
*************** std_expand_builtin_va_start (tree valist
*** 4144,4151 ****
{
tree t;
! t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
! make_tree (ptr_type_node, nextarg));
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
--- 4145,4152 ----
{
tree t;
! t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist,
! make_tree (ptr_type_node, nextarg));
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
*************** std_expand_builtin_va_arg (tree valist,
*** 4200,4214 ****
{
if (!PAD_VARARGS_DOWN)
{
! t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
! build (PLUS_EXPR, TREE_TYPE (valist), valist,
! build_int_2 (boundary / BITS_PER_UNIT - 1, 0)));
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}
! t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
! build (BIT_AND_EXPR, TREE_TYPE (valist), valist,
! build_int_2 (~(boundary / BITS_PER_UNIT - 1), -1)));
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}
--- 4201,4215 ----
{
if (!PAD_VARARGS_DOWN)
{
! t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist,
! build2 (PLUS_EXPR, TREE_TYPE (valist), valist,
! build_int_2 (boundary / BITS_PER_UNIT - 1, 0)));
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}
! t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist,
! build2 (BIT_AND_EXPR, TREE_TYPE (valist), valist,
! build_int_2 (~(boundary / BITS_PER_UNIT - 1), -1)));
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}
*************** std_expand_builtin_va_arg (tree valist,
*** 4217,4243 ****
|| TREE_OVERFLOW (type_size))
rounded_size = size_zero_node;
else
! rounded_size = fold (build (MULT_EXPR, sizetype,
! fold (build (TRUNC_DIV_EXPR, sizetype,
! fold (build (PLUS_EXPR, sizetype,
! type_size, alignm1)),
! align)),
! align));
/* Get AP. */
addr_tree = valist;
if (PAD_VARARGS_DOWN && ! integer_zerop (rounded_size))
{
/* Small args are padded downward. */
! addr_tree = fold (build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
! fold (build (COND_EXPR, sizetype,
! fold (build (GT_EXPR, sizetype,
! rounded_size,
! align)),
! size_zero_node,
! fold (build (MINUS_EXPR, sizetype,
! rounded_size,
! type_size))))));
}
addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
--- 4218,4246 ----
|| TREE_OVERFLOW (type_size))
rounded_size = size_zero_node;
else
! {
! rounded_size = fold (build2 (PLUS_EXPR, sizetype, type_size, alignm1));
! rounded_size = fold (build2 (TRUNC_DIV_EXPR, sizetype,
! rounded_size, align));
! rounded_size = fold (build2 (MULT_EXPR, sizetype,
! rounded_size, align));
! }
/* Get AP. */
addr_tree = valist;
if (PAD_VARARGS_DOWN && ! integer_zerop (rounded_size))
{
/* Small args are padded downward. */
! addr_tree = fold (build2 (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree,
! fold (build3 (COND_EXPR, sizetype,
! fold (build2 (GT_EXPR, sizetype,
! rounded_size,
! align)),
! size_zero_node,
! fold (build2 (MINUS_EXPR,
! sizetype,
! rounded_size,
! type_size))))));
}
addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
*************** std_expand_builtin_va_arg (tree valist,
*** 4246,4254 ****
/* Compute new value for AP. */
if (! integer_zerop (rounded_size))
{
! t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
! build (PLUS_EXPR, TREE_TYPE (valist), valist,
! rounded_size));
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}
--- 4249,4257 ----
/* Compute new value for AP. */
if (! integer_zerop (rounded_size))
{
! t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist,
! build2 (PLUS_EXPR, TREE_TYPE (valist), valist,
! rounded_size));
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}
*************** expand_builtin_va_copy (tree arglist)
*** 4387,4393 ****
if (TREE_CODE (va_list_type_node) != ARRAY_TYPE)
{
! t = build (MODIFY_EXPR, va_list_type_node, dst, src);
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}
--- 4390,4396 ----
if (TREE_CODE (va_list_type_node) != ARRAY_TYPE)
{
! t = build2 (MODIFY_EXPR, va_list_type_node, dst, src);
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}
*************** expand_builtin_signbit (tree exp, rtx ta
*** 5261,5268 ****
if (fmt->has_signed_zero && HONOR_SIGNED_ZEROS (fmode))
return 0;
! arg = fold (build (LT_EXPR, TREE_TYPE (exp), arg,
! build_real (TREE_TYPE (arg), dconst0)));
return expand_expr (arg, target, VOIDmode, EXPAND_NORMAL);
}
--- 5264,5271 ----
if (fmt->has_signed_zero && HONOR_SIGNED_ZEROS (fmode))
return 0;
! arg = fold (build2 (LT_EXPR, TREE_TYPE (exp), arg,
! build_real (TREE_TYPE (arg), dconst0)));
return expand_expr (arg, target, VOIDmode, EXPAND_NORMAL);
}
*************** fold_builtin_cabs (tree arglist, tree ty
*** 6458,6468 ****
rpart = builtin_save_expr (rpart);
ipart = builtin_save_expr (ipart);
! result = fold (build (PLUS_EXPR, type,
! fold (build (MULT_EXPR, type,
! rpart, rpart)),
! fold (build (MULT_EXPR, type,
! ipart, ipart))));
arglist = build_tree_list (NULL_TREE, result);
return build_function_call_expr (sqrtfn, arglist);
--- 6461,6471 ----
rpart = builtin_save_expr (rpart);
ipart = builtin_save_expr (ipart);
! result = fold (build2 (PLUS_EXPR, type,
! fold (build2 (MULT_EXPR, type,
! rpart, rpart)),
! fold (build2 (MULT_EXPR, type,
! ipart, ipart))));
arglist = build_tree_list (NULL_TREE, result);
return build_function_call_expr (sqrtfn, arglist);
*************** fold_builtin_logarithm (tree exp, const
*** 6864,6870 ****
tree logfn;
arglist = build_tree_list (NULL_TREE, x);
logfn = build_function_call_expr (fndecl, arglist);
! return fold (build (MULT_EXPR, type, exponent, logfn));
}
}
}
--- 6867,6873 ----
tree logfn;
arglist = build_tree_list (NULL_TREE, x);
logfn = build_function_call_expr (fndecl, arglist);
! return fold (build2 (MULT_EXPR, type, exponent, logfn));
}
}
}
*************** fold_builtin_mempcpy (tree exp)
*** 6999,7005 ****
if (operand_equal_p (src, dest, 0))
{
tree temp = fold_convert (TREE_TYPE (dest), len);
! temp = fold (build (PLUS_EXPR, TREE_TYPE (dest), dest, temp));
return fold_convert (TREE_TYPE (exp), temp);
}
--- 7002,7008 ----
if (operand_equal_p (src, dest, 0))
{
tree temp = fold_convert (TREE_TYPE (dest), len);
! temp = fold (build2 (PLUS_EXPR, TREE_TYPE (dest), dest, temp));
return fold_convert (TREE_TYPE (exp), temp);
}
*************** fold_builtin_signbit (tree exp)
*** 7231,7238 ****
/* If ARG's format doesn't have signed zeros, return "arg < 0.0". */
if (!HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg))))
! return fold (build (LT_EXPR, TREE_TYPE (exp), arg,
! build_real (TREE_TYPE (arg), dconst0)));
return NULL_TREE;
}
--- 7234,7241 ----
/* If ARG's format doesn't have signed zeros, return "arg < 0.0". */
if (!HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg))))
! return fold (build2 (LT_EXPR, TREE_TYPE (exp), arg,
! build_real (TREE_TYPE (arg), dconst0)));
return NULL_TREE;
}
*************** fold_builtin_isascii (tree arglist)
*** 7249,7259 ****
/* Transform isascii(c) -> ((c & ~0x7f) == 0). */
tree arg = TREE_VALUE (arglist);
! arg = fold (build (EQ_EXPR, integer_type_node,
! build (BIT_AND_EXPR, integer_type_node, arg,
! build_int_2 (~ (unsigned HOST_WIDE_INT) 0x7f,
! ~ (HOST_WIDE_INT) 0)),
! integer_zero_node));
if (in_gimple_form && !TREE_CONSTANT (arg))
return NULL_TREE;
--- 7252,7262 ----
/* Transform isascii(c) -> ((c & ~0x7f) == 0). */
tree arg = TREE_VALUE (arglist);
! arg = fold (build2 (EQ_EXPR, integer_type_node,
! build2 (BIT_AND_EXPR, integer_type_node, arg,
! build_int_2 (~ (unsigned HOST_WIDE_INT) 0x7f,
! ~ (HOST_WIDE_INT) 0)),
! integer_zero_node));
if (in_gimple_form && !TREE_CONSTANT (arg))
return NULL_TREE;
*************** fold_builtin_toascii (tree arglist)
*** 7274,7281 ****
/* Transform toascii(c) -> (c & 0x7f). */
tree arg = TREE_VALUE (arglist);
! return fold (build (BIT_AND_EXPR, integer_type_node, arg,
! build_int_2 (0x7f, 0)));
}
}
--- 7277,7284 ----
/* Transform toascii(c) -> (c & 0x7f). */
tree arg = TREE_VALUE (arglist);
! return fold (build2 (BIT_AND_EXPR, integer_type_node, arg,
! build_int_2 (0x7f, 0)));
}
}
*************** fold_builtin_isdigit (tree arglist)
*** 7292,7302 ****
/* According to the C standard, isdigit is unaffected by locale. */
tree arg = TREE_VALUE (arglist);
arg = fold_convert (unsigned_type_node, arg);
! arg = build (MINUS_EXPR, unsigned_type_node, arg,
! fold_convert (unsigned_type_node,
! build_int_2 (TARGET_DIGIT0, 0)));
! arg = build (LE_EXPR, integer_type_node, arg,
! fold_convert (unsigned_type_node, build_int_2 (9, 0)));
arg = fold (arg);
if (in_gimple_form && !TREE_CONSTANT (arg))
return NULL_TREE;
--- 7295,7305 ----
/* According to the C standard, isdigit is unaffected by locale. */
tree arg = TREE_VALUE (arglist);
arg = fold_convert (unsigned_type_node, arg);
! arg = build2 (MINUS_EXPR, unsigned_type_node, arg,
! fold_convert (unsigned_type_node,
! build_int_2 (TARGET_DIGIT0, 0)));
! arg = build2 (LE_EXPR, integer_type_node, arg,
! fold_convert (unsigned_type_node, build_int_2 (9, 0)));
arg = fold (arg);
if (in_gimple_form && !TREE_CONSTANT (arg))
return NULL_TREE;
*************** fold_builtin_1 (tree exp)
*** 7380,7388 ****
if (flag_unsafe_math_optimizations && BUILTIN_EXPONENT_P (fcode))
{
tree expfn = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
! arg = fold (build (MULT_EXPR, type,
! TREE_VALUE (TREE_OPERAND (arg, 1)),
! build_real (type, dconsthalf)));
arglist = build_tree_list (NULL_TREE, arg);
return build_function_call_expr (expfn, arglist);
}
--- 7383,7391 ----
if (flag_unsafe_math_optimizations && BUILTIN_EXPONENT_P (fcode))
{
tree expfn = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
! arg = fold (build2 (MULT_EXPR, type,
! TREE_VALUE (TREE_OPERAND (arg, 1)),
! build_real (type, dconsthalf)));
arglist = build_tree_list (NULL_TREE, arg);
return build_function_call_expr (expfn, arglist);
}
*************** fold_builtin_1 (tree exp)
*** 7419,7426 ****
tree powfn = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
tree arg0 = TREE_VALUE (TREE_OPERAND (arg, 1));
tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_OPERAND (arg, 1)));
! tree narg1 = fold (build (MULT_EXPR, type, arg1,
! build_real (type, dconsthalf)));
arglist = tree_cons (NULL_TREE, arg0,
build_tree_list (NULL_TREE, narg1));
return build_function_call_expr (powfn, arglist);
--- 7422,7429 ----
tree powfn = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
tree arg0 = TREE_VALUE (TREE_OPERAND (arg, 1));
tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_OPERAND (arg, 1)));
! tree narg1 = fold (build2 (MULT_EXPR, type, arg1,
! build_real (type, dconsthalf)));
arglist = tree_cons (NULL_TREE, arg0,
build_tree_list (NULL_TREE, narg1));
return build_function_call_expr (powfn, arglist);
*************** fold_builtin_1 (tree exp)
*** 7446,7454 ****
tree expfn = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
const REAL_VALUE_TYPE third_trunc =
real_value_truncate (TYPE_MODE (type), dconstthird);
! arg = fold (build (MULT_EXPR, type,
! TREE_VALUE (TREE_OPERAND (arg, 1)),
! build_real (type, third_trunc)));
arglist = build_tree_list (NULL_TREE, arg);
return build_function_call_expr (expfn, arglist);
}
--- 7449,7457 ----
tree expfn = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
const REAL_VALUE_TYPE third_trunc =
real_value_truncate (TYPE_MODE (type), dconstthird);
! arg = fold (build2 (MULT_EXPR, type,
! TREE_VALUE (TREE_OPERAND (arg, 1)),
! build_real (type, third_trunc)));
arglist = build_tree_list (NULL_TREE, arg);
return build_function_call_expr (expfn, arglist);
}
*************** fold_builtin_1 (tree exp)
*** 7618,7626 ****
/* Optimize pow(x,-1.0) = 1.0/x. */
if (REAL_VALUES_EQUAL (c, dconstm1))
! return fold (build (RDIV_EXPR, type,
! build_real (type, dconst1),
! arg0));
/* Optimize pow(x,0.5) = sqrt(x). */
if (flag_unsafe_math_optimizations
--- 7621,7628 ----
/* Optimize pow(x,-1.0) = 1.0/x. */
if (REAL_VALUES_EQUAL (c, dconstm1))
! return fold (build2 (RDIV_EXPR, type,
! build_real (type, dconst1), arg0));
/* Optimize pow(x,0.5) = sqrt(x). */
if (flag_unsafe_math_optimizations
*************** fold_builtin_1 (tree exp)
*** 7664,7670 ****
{
tree expfn = TREE_OPERAND (TREE_OPERAND (arg0, 0), 0);
tree arg = TREE_VALUE (TREE_OPERAND (arg0, 1));
! arg = fold (build (MULT_EXPR, type, arg, arg1));
arglist = build_tree_list (NULL_TREE, arg);
return build_function_call_expr (expfn, arglist);
}
--- 7666,7672 ----
{
tree expfn = TREE_OPERAND (TREE_OPERAND (arg0, 0), 0);
tree arg = TREE_VALUE (TREE_OPERAND (arg0, 1));
! arg = fold (build2 (MULT_EXPR, type, arg, arg1));
arglist = build_tree_list (NULL_TREE, arg);
return build_function_call_expr (expfn, arglist);
}
*************** fold_builtin_1 (tree exp)
*** 7673,7680 ****
if (flag_unsafe_math_optimizations && BUILTIN_SQRT_P (fcode))
{
tree narg0 = TREE_VALUE (TREE_OPERAND (arg0, 1));
! tree narg1 = fold (build (MULT_EXPR, type, arg1,
! build_real (type, dconsthalf)));
arglist = tree_cons (NULL_TREE, narg0,
build_tree_list (NULL_TREE, narg1));
--- 7675,7682 ----
if (flag_unsafe_math_optimizations && BUILTIN_SQRT_P (fcode))
{
tree narg0 = TREE_VALUE (TREE_OPERAND (arg0, 1));
! tree narg1 = fold (build2 (MULT_EXPR, type, arg1,
! build_real (type, dconsthalf)));
arglist = tree_cons (NULL_TREE, narg0,
build_tree_list (NULL_TREE, narg1));
*************** fold_builtin_1 (tree exp)
*** 7689,7695 ****
{
tree arg00 = TREE_VALUE (TREE_OPERAND (arg0, 1));
tree arg01 = TREE_VALUE (TREE_CHAIN (TREE_OPERAND (arg0, 1)));
! tree narg1 = fold (build (MULT_EXPR, type, arg01, arg1));
arglist = tree_cons (NULL_TREE, arg00,
build_tree_list (NULL_TREE, narg1));
return build_function_call_expr (fndecl, arglist);
--- 7691,7697 ----
{
tree arg00 = TREE_VALUE (TREE_OPERAND (arg0, 1));
tree arg01 = TREE_VALUE (TREE_CHAIN (TREE_OPERAND (arg0, 1)));
! tree narg1 = fold (build2 (MULT_EXPR, type, arg01, arg1));
arglist = tree_cons (NULL_TREE, arg00,
build_tree_list (NULL_TREE, narg1));
return build_function_call_expr (fndecl, arglist);
*************** build_function_call_expr (tree fn, tree
*** 7849,7856 ****
tree call_expr;
call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
! call_expr = build (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
! call_expr, arglist, NULL_TREE);
return fold (call_expr);
}
--- 7851,7858 ----
tree call_expr;
call_expr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (fn)), fn);
! call_expr = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (fn)),
! call_expr, arglist, NULL_TREE);
return fold (call_expr);
}
*************** simplify_builtin_strchr (tree arglist)
*** 8133,8141 ****
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
--- 8135,8143 ----
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))));
}
/* FIXME: Should use here strchrM optab so that ports can optimize
*************** simplify_builtin_strrchr (tree arglist)
*** 8190,8198 ****
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))
--- 8192,8200 ----
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 (! integer_zerop (s2))
*************** simplify_builtin_strpbrk (tree arglist)
*** 8248,8266 ****
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')
! {
! /* strpbrk(x, "") == NULL.
! Evaluate and ignore the arguments in case they had
! side-effects. */
! return build (COMPOUND_EXPR, integer_type_node, s1,
! integer_zero_node);
! }
if (p2[1] != '\0')
return 0; /* Really call strpbrk. */
--- 8250,8264 ----
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')
! /* strpbrk(x, "") == NULL.
! Evaluate and ignore s1 in case it had side-effects. */
! return omit_one_operand (TREE_TYPE (s1), integer_zero_node, s1);
if (p2[1] != '\0')
return 0; /* Really call strpbrk. */
*************** simplify_builtin_strncpy (tree arglist,
*** 8358,8370 ****
/* If the len parameter is zero, return the dst parameter. */
if (integer_zerop (len))
! {
! /* Evaluate and ignore the src argument in case it has
! side-effects and return the dst parameter. */
! return build (COMPOUND_EXPR, TREE_TYPE (TREE_VALUE (arglist)),
! TREE_VALUE (TREE_CHAIN (arglist)),
! TREE_VALUE (arglist));
! }
if (!slen)
slen = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)), 0);
--- 8356,8366 ----
/* If the len parameter is zero, return the dst parameter. */
if (integer_zerop (len))
! /* Evaluate and ignore the src argument in case it has
! side-effects and return the dst parameter. */
! return omit_one_operand (TREE_TYPE (TREE_VALUE (arglist)),
! TREE_VALUE (arglist),
! TREE_VALUE (TREE_CHAIN (arglist)));
if (!slen)
slen = c_strlen (TREE_VALUE (TREE_CHAIN (arglist)), 0);
*************** simplify_builtin_memcmp (tree arglist)
*** 8425,8433 ****
{
/* Evaluate and ignore arg1 and arg2 in case they have
side-effects. */
! return build (COMPOUND_EXPR, integer_type_node, arg1,
! build (COMPOUND_EXPR, integer_type_node,
! arg2, integer_zero_node));
}
p1 = c_getstr (arg1);
--- 8421,8429 ----
{
/* Evaluate and ignore arg1 and arg2 in case they have
side-effects. */
! return build2 (COMPOUND_EXPR, integer_type_node, arg1,
! build2 (COMPOUND_EXPR, integer_type_node,
! arg2, integer_zero_node));
}
p1 = c_getstr (arg1);
*************** simplify_builtin_memcmp (tree arglist)
*** 8460,8466 ****
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
build1 (NOP_EXPR, cst_uchar_ptr_node, arg2))));
! return fold (build (MINUS_EXPR, integer_type_node, ind1, ind2));
}
return 0;
--- 8456,8462 ----
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
build1 (NOP_EXPR, cst_uchar_ptr_node, arg2))));
! return fold (build2 (MINUS_EXPR, integer_type_node, ind1, ind2));
}
return 0;
*************** simplify_builtin_strcmp (tree arglist)
*** 8524,8530 ****
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
build1 (NOP_EXPR, cst_uchar_ptr_node, arg2))));
! return fold (build (MINUS_EXPR, integer_type_node, ind1, ind2));
}
return 0;
--- 8520,8526 ----
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
build1 (NOP_EXPR, cst_uchar_ptr_node, arg2))));
! return fold (build2 (MINUS_EXPR, integer_type_node, ind1, ind2));
}
return 0;
*************** simplify_builtin_strncmp (tree arglist)
*** 8566,8582 ****
{
/* Evaluate and ignore arg1 and arg2 in case they have
side-effects. */
! return build (COMPOUND_EXPR, integer_type_node, arg1,
! build (COMPOUND_EXPR, integer_type_node,
! arg2, integer_zero_node));
}
/* If arg1 and arg2 are equal (and not volatile), return zero. */
if (operand_equal_p (arg1, arg2, 0))
! {
! /* Evaluate and ignore arg3 in case it has side-effects. */
! return build (COMPOUND_EXPR, integer_type_node, arg3, integer_zero_node);
! }
p1 = c_getstr (arg1);
p2 = c_getstr (arg2);
--- 8562,8576 ----
{
/* Evaluate and ignore arg1 and arg2 in case they have
side-effects. */
! return build2 (COMPOUND_EXPR, integer_type_node, arg1,
! build2 (COMPOUND_EXPR, integer_type_node,
! arg2, integer_zero_node));
}
/* If arg1 and arg2 are equal (and not volatile), return zero. */
if (operand_equal_p (arg1, arg2, 0))
! /* Evaluate and ignore arg3 in case it has side-effects. */
! return omit_one_operand (integer_type_node, integer_zero_node, arg3);
p1 = c_getstr (arg1);
p2 = c_getstr (arg2);
*************** simplify_builtin_strncmp (tree arglist)
*** 8607,8613 ****
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
build1 (NOP_EXPR, cst_uchar_ptr_node, arg2))));
! return fold (build (MINUS_EXPR, integer_type_node, ind1, ind2));
}
return 0;
--- 8601,8607 ----
fold (build1 (CONVERT_EXPR, integer_type_node,
build1 (INDIRECT_REF, cst_uchar_node,
build1 (NOP_EXPR, cst_uchar_ptr_node, arg2))));
! return fold (build2 (MINUS_EXPR, integer_type_node, ind1, ind2));
}
return 0;
*************** simplify_builtin_strncat (tree arglist)
*** 8682,8689 ****
/* If the requested length is zero, or the src parameter string
length is zero, return the dst parameter. */
if (integer_zerop (len) || (p && *p == '\0'))
! return build (COMPOUND_EXPR, TREE_TYPE (dst), src,
! build (COMPOUND_EXPR, integer_type_node, len, dst));
/* If the requested len is greater than or equal to the string
length, call strcat. */
--- 8676,8683 ----
/* If the requested length is zero, or the src parameter string
length is zero, return the dst parameter. */
if (integer_zerop (len) || (p && *p == '\0'))
! return build2 (COMPOUND_EXPR, TREE_TYPE (dst), src,
! build2 (COMPOUND_EXPR, integer_type_node, len, dst));
/* If the requested len is greater than or equal to the string
length, call strcat. */
*************** simplify_builtin_strspn (tree arglist)
*** 8744,8752 ****
{
/* Evaluate and ignore both arguments in case either one has
side-effects. */
! return build (COMPOUND_EXPR, integer_type_node, s1,
! build (COMPOUND_EXPR, integer_type_node,
! s2, integer_zero_node));
}
return 0;
}
--- 8738,8746 ----
{
/* Evaluate and ignore both arguments in case either one has
side-effects. */
! return build2 (COMPOUND_EXPR, integer_type_node, s1,
! build2 (COMPOUND_EXPR, integer_type_node,
! s2, integer_zero_node));
}
return 0;
}
*************** simplify_builtin_strcspn (tree arglist)
*** 8791,8798 ****
{
/* Evaluate and ignore argument s2 in case it has
side-effects. */
! return build (COMPOUND_EXPR, integer_type_node,
! s2, integer_zero_node);
}
/* If the second argument is "", return __builtin_strlen(s1). */
--- 8785,8792 ----
{
/* Evaluate and ignore argument s2 in case it has
side-effects. */
! return omit_one_operand (integer_type_node,
! integer_zero_node, s2);
}
/* If the second argument is "", return __builtin_strlen(s1). */
*************** simplify_builtin_fputs (tree arglist, in
*** 8862,8871 ****
switch (compare_tree_int (len, 1))
{
case -1: /* length is 0, delete the call entirely . */
! {
! return build (COMPOUND_EXPR, integer_type_node,
! TREE_VALUE (TREE_CHAIN (arglist)), integer_zero_node);
! }
case 0: /* length is 1, call fputc. */
{
const char *p = c_getstr (TREE_VALUE (arglist));
--- 8856,8864 ----
switch (compare_tree_int (len, 1))
{
case -1: /* length is 0, delete the call entirely . */
! return omit_one_operand (integer_type_node, integer_zero_node,
! TREE_VALUE (TREE_CHAIN (arglist)));
!
case 0: /* length is 1, call fputc. */
{
const char *p = c_getstr (TREE_VALUE (arglist));
*************** simplify_builtin_sprintf (tree arglist,
*** 9028,9034 ****
retval = convert
(TREE_TYPE (TREE_TYPE (implicit_built_in_decls[BUILT_IN_SPRINTF])),
retval);
! return build (COMPOUND_EXPR, TREE_TYPE (retval), call, retval);
}
else
return call;
--- 9021,9027 ----
retval = convert
(TREE_TYPE (TREE_TYPE (implicit_built_in_decls[BUILT_IN_SPRINTF])),
retval);
! return build2 (COMPOUND_EXPR, TREE_TYPE (retval), call, retval);
}
else
return call;
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