This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Clean up builtin expansion logic
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Tue, 5 Aug 2003 16:02:51 -0600 (MDT)
- Subject: [PATCH] Clean up builtin expansion logic
The following clean-up and simplication was recently suggested by Kaveh.
The function "expand_builtin" maintains an explicit list of all of GCC's
builtins that should call the corresponding library function when not
optimizing. This large list is a pain to maintain, and it is not uncommon
to forget to add functions to it when implementing inline intrinsics.
The conclussion that Kaveh and I came to was that as a rule, we should
call the library function (when not optimizing) whenever the builtin has
a library function that can be called!
The only exception to this rule seems to be alloca. Its not too hard
to see that although we intercept calls to alloca, we really shouldn't
try to implement it using a real call :>. Without this exception, the
patch belows fails for 20010122-1.c, 20020314-1.c and 941202-1.c all
in gcc.c-torture/execute at -O0.
The patch also contains the removal of a non-printable character from
a comment in expand_builtin.
The following patch has been tested on i686-pc-linux-gnu with a complete
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures.
Ok for mainline?
2003-08-05 Roger Sayle <roger@eyesopen.com>
* builtins.c (expand_builtin): When not optimizing, call the library
function for all builtins that have a library function (with the
single exception of alloca).
Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.235
diff -c -3 -p -r1.235 builtins.c
*** builtins.c 1 Aug 2003 00:36:52 -0000 1.235
--- builtins.c 5 Aug 2003 18:33:15 -0000
*************** expand_builtin (tree exp, rtx target, rt
*** 4879,4885 ****
enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
enum machine_mode target_mode = TYPE_MODE (TREE_TYPE (exp));
! /* Perform postincrements before expanding builtin functions. */
emit_queue ();
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
--- 4879,4885 ----
enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
enum machine_mode target_mode = TYPE_MODE (TREE_TYPE (exp));
! /* Perform postincrements before expanding builtin functions. */
emit_queue ();
if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
*************** expand_builtin (tree exp, rtx target, rt
*** 4887,4982 ****
/* When not optimizing, generate calls to library functions for a certain
set of builtins. */
! if (!optimize && !CALLED_AS_BUILT_IN (fndecl))
! switch (fcode)
! {
! case BUILT_IN_SQRT:
! case BUILT_IN_SQRTF:
! case BUILT_IN_SQRTL:
! case BUILT_IN_SIN:
! case BUILT_IN_SINF:
! case BUILT_IN_SINL:
! case BUILT_IN_COS:
! case BUILT_IN_COSF:
! case BUILT_IN_COSL:
! case BUILT_IN_EXP:
! case BUILT_IN_EXPF:
! case BUILT_IN_EXPL:
! case BUILT_IN_LOG:
! case BUILT_IN_LOGF:
! case BUILT_IN_LOGL:
! case BUILT_IN_TAN:
! case BUILT_IN_TANF:
! case BUILT_IN_TANL:
! case BUILT_IN_ATAN:
! case BUILT_IN_ATANF:
! case BUILT_IN_ATANL:
! case BUILT_IN_POW:
! case BUILT_IN_POWF:
! case BUILT_IN_POWL:
! case BUILT_IN_ATAN2:
! case BUILT_IN_ATAN2F:
! case BUILT_IN_ATAN2L:
! case BUILT_IN_MEMSET:
! case BUILT_IN_MEMCPY:
! case BUILT_IN_MEMCMP:
! case BUILT_IN_MEMPCPY:
! case BUILT_IN_MEMMOVE:
! case BUILT_IN_BCMP:
! case BUILT_IN_BZERO:
! case BUILT_IN_BCOPY:
! case BUILT_IN_INDEX:
! case BUILT_IN_RINDEX:
! case BUILT_IN_SPRINTF:
! case BUILT_IN_STPCPY:
! case BUILT_IN_STRCHR:
! case BUILT_IN_STRRCHR:
! case BUILT_IN_STRLEN:
! case BUILT_IN_STRCPY:
! case BUILT_IN_STRNCPY:
! case BUILT_IN_STRNCMP:
! case BUILT_IN_STRSTR:
! case BUILT_IN_STRPBRK:
! case BUILT_IN_STRCAT:
! case BUILT_IN_STRNCAT:
! case BUILT_IN_STRSPN:
! case BUILT_IN_STRCSPN:
! case BUILT_IN_STRCMP:
! case BUILT_IN_FFS:
! case BUILT_IN_PUTCHAR:
! case BUILT_IN_PUTS:
! case BUILT_IN_PRINTF:
! case BUILT_IN_FPUTC:
! case BUILT_IN_FPUTS:
! case BUILT_IN_FWRITE:
! case BUILT_IN_FPRINTF:
! case BUILT_IN_PUTCHAR_UNLOCKED:
! case BUILT_IN_PUTS_UNLOCKED:
! case BUILT_IN_PRINTF_UNLOCKED:
! case BUILT_IN_FPUTC_UNLOCKED:
! case BUILT_IN_FPUTS_UNLOCKED:
! case BUILT_IN_FWRITE_UNLOCKED:
! case BUILT_IN_FPRINTF_UNLOCKED:
! case BUILT_IN_FLOOR:
! case BUILT_IN_FLOORF:
! case BUILT_IN_FLOORL:
! case BUILT_IN_CEIL:
! case BUILT_IN_CEILF:
! case BUILT_IN_CEILL:
! case BUILT_IN_TRUNC:
! case BUILT_IN_TRUNCF:
! case BUILT_IN_TRUNCL:
! case BUILT_IN_ROUND:
! case BUILT_IN_ROUNDF:
! case BUILT_IN_ROUNDL:
! case BUILT_IN_NEARBYINT:
! case BUILT_IN_NEARBYINTF:
! case BUILT_IN_NEARBYINTL:
! return expand_call (exp, target, ignore);
!
! default:
! break;
! }
/* The built-in function expanders test for target == const0_rtx
to determine whether the function's result will be ignored. */
--- 4887,4897 ----
/* When not optimizing, generate calls to library functions for a certain
set of builtins. */
! if (!optimize
! && !CALLED_AS_BUILT_IN (fndecl)
! && DECL_ASSEMBLER_NAME_SET_P (fndecl)
! && fcode != BUILT_IN_ALLOCA)
! return expand_call (exp, target, ignore);
/* The built-in function expanders test for target == const0_rtx
to determine whether the function's result will be ignored. */
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