From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 558F13972405; Tue, 17 Nov 2020 07:07:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 558F13972405 From: "luoxhu at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/22326] promotions (from float to double) are not removed when they should be able to Date: Tue, 17 Nov 2020 07:07:36 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.1.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: luoxhu at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Nov 2020 07:07:36 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D22326 luoxhu at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |luoxhu at gcc dot gnu.org, | |pinskia at gcc dot gnu.org, | |segher at kernel dot crash= ing.org --- Comment #4 from luoxhu at gcc dot gnu.org --- float foo(float f, float x, float y) { return (fabs(f)*x+y); } the input of fabs is float type, so use fabsf is enough here, drafted a pat= ch to avoid double promotion when generating gimple if fabs could be replaced = by fabsf as argument[0] is float type. diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index ecc3d2119fa..1a2d7e624cc 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -10470,6 +10470,20 @@ c_parser_postfix_expression_after_primary (c_parser *parser, && fndecl_built_in_p (expr.value, BUILT_IN_NORMAL) && vec_safe_length (exprlist) =3D=3D 1) warn_for_abs (expr_loc, expr.value, (*exprlist)[0]); + + if (fndecl_built_in_p (expr.value, BUILT_IN_NORMAL) + && DECL_FUNCTION_CODE (expr.value) =3D=3D BUILT_IN_FABS) + { + tree arg0 =3D (*exprlist)[0]; + if (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (expr.value))) + > TYPE_PRECISION (TREE_TYPE (arg0)) + && TYPE_MODE (TREE_TYPE (arg0)) =3D=3D E_SFmode) + { + tree abs_fun =3D get_identifier ("fabsf"); + expr.value =3D build_external_ref (expr_loc, abs_fun,= true, + &expr.original_type); + } + } } start =3D expr.get_start (); .006t.gimple: __attribute__((noinline)) foo (float f, float x, float y) { float D.4347; _1 =3D ABS_EXPR ; _2 =3D x * _1; D.4347 =3D y + _2; return D.4347; } foo: .LFB0: .cfi_startproc fabs 1,1 fmadds 1,1,2,3 blr=