From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31008 invoked by alias); 6 Nov 2002 17:54:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 30895 invoked from network); 6 Nov 2002 17:54:44 -0000 Received: from unknown (HELO nikam.ms.mff.cuni.cz) (195.113.18.106) by sources.redhat.com with SMTP; 6 Nov 2002 17:54:44 -0000 Received: from camelot.ms.mff.cuni.cz (kampanus.ms.mff.cuni.cz [195.113.18.107]) by nikam.ms.mff.cuni.cz (Postfix) with SMTP id 6120D4E29B; Wed, 6 Nov 2002 18:54:44 +0100 (CET) Received: by camelot.ms.mff.cuni.cz (sSMTP sendmail emulation); Wed, 6 Nov 2002 18:54:41 +0100 Date: Wed, 06 Nov 2002 09:54:00 -0000 From: Jan Hubicka To: Jan Hubicka Cc: Richard Henderson , gcc-patches@gcc.gnu.org, aj@suse.de Subject: Re: Simplify floating point conversions II Message-ID: <20021106175441.GZ22059@kam.mff.cuni.cz> References: <20021105171400.GX14655@kam.mff.cuni.cz> <20021105173800.GD20534@redhat.com> <20021106092310.GE22059@kam.mff.cuni.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20021106092310.GE22059@kam.mff.cuni.cz> User-Agent: Mutt/1.3.28i X-SW-Source: 2002-11/txt/msg00293.txt.bz2 Hi, I've noticed that one line of patch got lost for some reason. Honza Wed Nov 6 10:17:44 CET 2002 Jan Hubicka * convert.c (convert_to_real): Simplify some special cases. Index: convert.c =================================================================== RCS file: /cvs/gcc/egcs/gcc/convert.c,v retrieving revision 1.19 diff -c -3 -p -r1.19 convert.c *** convert.c 4 Jul 2002 06:38:54 -0000 1.19 --- convert.c 6 Nov 2002 17:53:09 -0000 *************** tree *** 80,85 **** --- 80,223 ---- convert_to_real (type, expr) tree type, expr; { + enum built_in_function fcode = builtin_mathfn_code (expr); + tree itype = TREE_TYPE (expr); + + /* Convert (float)sqrt((double)x) into sqrtf(x) + For fast math it would be safe probably to convert (float)sqrt(x) + into sqrt((float)x), but in strict mode the argument can overflow. */ + 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) + && (TYPE_MODE (type) == TYPE_MODE (double_type_node) + || TYPE_MODE (type) == TYPE_MODE (float_type_node))) + { + tree arg0 = TREE_VALUE (TREE_OPERAND (expr, 1)); + tree newtype = type; + + /* Wind away possible cast. */ + if (TREE_CODE (arg0) == NOP_EXPR) + arg0 = TREE_OPERAND (arg0, 0); + + /* We have (outertype)sqrt((innertype)x). Choose the wider mode from + the both as the safe type for operation. */ + if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (type)) + newtype = TREE_TYPE (arg0); + + /* Be curefull about integer to fp conversions. + These may overflow still. */ + if (FLOAT_TYPE_P (TREE_TYPE (arg0)) + && TYPE_PRECISION (newtype) <= TYPE_PRECISION (itype) + && (TYPE_MODE (newtype) == TYPE_MODE (double_type_node) + || TYPE_MODE (newtype) == TYPE_MODE (float_type_node))) + { + tree arglist, decl; + if (TYPE_MODE (type) == TYPE_MODE (float_type_node)) + switch (fcode) + { + case BUILT_IN_SQRT: + case BUILT_IN_SQRTL: + fcode = BUILT_IN_SQRTF; + break; + case BUILT_IN_SIN: + case BUILT_IN_SINL: + fcode = BUILT_IN_SINF; + break; + case BUILT_IN_COS: + case BUILT_IN_COSL: + fcode = BUILT_IN_COSF; + break; + case BUILT_IN_EXP: + case BUILT_IN_EXPL: + fcode = BUILT_IN_EXPF; + break; + default: + abort (); + } + else + switch (fcode) + { + case BUILT_IN_SQRT: + case BUILT_IN_SQRTL: + fcode = BUILT_IN_SQRT; + break; + case BUILT_IN_SIN: + case BUILT_IN_SINL: + fcode = BUILT_IN_SIN; + break; + case BUILT_IN_COS: + case BUILT_IN_COSL: + fcode = BUILT_IN_COS; + break; + case BUILT_IN_EXP: + case BUILT_IN_EXPL: + fcode = BUILT_IN_EXP; + break; + default: + abort (); + } + + /* ??? Fortran frontend does not initialize built_in_decls. + For some reason creating the decl using builtin_function does not + work as it should. */ + if (built_in_decls [fcode]) + { + arglist = build_tree_list (NULL_TREE, fold (convert_to_real (newtype, arg0))); + return build_function_call_expr (built_in_decls [fcode], arglist); + } + } + } + + /* Propagate the cast into the operation. */ + if (itype != type && FLOAT_TYPE_P (type)) + switch (TREE_CODE (expr)) + { + /* convert (float)-x into -(float)x. This is always safe. */ + case ABS_EXPR: + case NEGATE_EXPR: + return build1 (TREE_CODE (expr), type, + fold (convert_to_real (type, + TREE_OPERAND (expr, 0)))); + /* convert (outertype)((innertype0)a+(innertype1)b) + into ((newtype)a+(newtype)b) where newtype + is the widest mode from all of these. */ + case PLUS_EXPR: + case MINUS_EXPR: + case MULT_EXPR: + case RDIV_EXPR: + { + tree arg0 = TREE_OPERAND (expr, 0); + tree arg1 = TREE_OPERAND (expr, 1); + + /* Unwind possible casts. */ + if (TREE_CODE (arg0) == NOP_EXPR) + arg0 = TREE_OPERAND (arg0, 0); + if (TREE_CODE (arg1) == NOP_EXPR) + arg1 = TREE_OPERAND (arg1, 0); + if (FLOAT_TYPE_P (TREE_TYPE (arg0)) + && FLOAT_TYPE_P (TREE_TYPE (arg1))) + { + tree newtype = type; + if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (newtype)) + newtype = TREE_TYPE (arg0); + if (TYPE_PRECISION (TREE_TYPE (arg1)) > TYPE_PRECISION (newtype)) + newtype = TREE_TYPE (arg1); + if (TYPE_PRECISION (newtype) < TYPE_PRECISION (itype)) + return build (TREE_CODE (expr), newtype, + fold (convert_to_real (newtype, arg0)), + fold (convert_to_real (newtype, arg1))); + } + } + break; + default: + break; + } + switch (TREE_CODE (TREE_TYPE (expr))) { case REAL_TYPE: