This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Also fold (float)log(x) as logf(x)


This trivial patch adds "log" to the list of built-in math functions
that GCC folds to a narrower type.  These were omitted by accident
in Jan's original patch.  This change is slightly more than a two
lines as it also updates the copyright years, and reorders this
condition to check for optimize first.

The following patch has been tested on i686-pc-linux-gnu with a full
bootstrap, all languages except Ada and treelang, and a complete
"make -k check" with no new regressions.

Ok for mainline?


2003-02-18  Roger Sayle  <roger@eyesopen.com>

	* convert.c (convert_to_real): Also optimize (float)log(x) into
	logf(x) where x is a float, i.e. also handle BUILT_IN_LOG{,L}.


Index: convert.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/convert.c,v
retrieving revision 1.27
diff -c -3 -p -r1.27 convert.c
*** convert.c	25 Jan 2003 11:08:38 -0000	1.27
--- convert.c	18 Feb 2003 15:21:23 -0000
***************
*** 1,6 ****
  /* Utility routines for data type conversion for GNU C.
!    Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1997,
!    1998 Free Software Foundation, Inc.

  This file is part of GCC.

--- 1,6 ----
  /* Utility routines for data type conversion for GNU C.
!    Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1997, 1998,
!    2000, 2001, 2002, 2003 Free Software Foundation, Inc.

  This file is part of GCC.

*************** convert_to_real (type, expr)
*** 133,147 ****
    /* Disable until we figure out how to decide whether the functions are
       present in runtime.  */
    /* Convert (float)sqrt((double)x) where x is float into sqrtf(x) */
!   if ((fcode == BUILT_IN_SQRT
!        || fcode == BUILT_IN_SQRTL
!        || fcode == BUILT_IN_SIN
!        || fcode == BUILT_IN_SINL
!        || fcode == BUILT_IN_COS
!        || fcode == BUILT_IN_COSL
!        || fcode == BUILT_IN_EXP
!        || fcode == BUILT_IN_EXPL)
!       && optimize
        && (TYPE_MODE (type) == TYPE_MODE (double_type_node)
            || TYPE_MODE (type) == TYPE_MODE (float_type_node)))
      {
--- 133,149 ----
    /* Disable until we figure out how to decide whether the functions are
       present in runtime.  */
    /* Convert (float)sqrt((double)x) where x is float into sqrtf(x) */
!   if (optimize
!       && (fcode == BUILT_IN_SQRT
! 	  || fcode == BUILT_IN_SQRTL
! 	  || fcode == BUILT_IN_SIN
! 	  || fcode == BUILT_IN_SINL
! 	  || fcode == BUILT_IN_COS
! 	  || fcode == BUILT_IN_COSL
! 	  || fcode == BUILT_IN_EXP
! 	  || fcode == BUILT_IN_EXPL
! 	  || fcode == BUILT_IN_LOG
! 	  || fcode == BUILT_IN_LOGL)
        && (TYPE_MODE (type) == TYPE_MODE (double_type_node)
            || TYPE_MODE (type) == TYPE_MODE (float_type_node)))
      {

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]