From patchwork Tue Oct 20 09:14:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 532854 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9DE211401AF for ; Tue, 20 Oct 2015 20:14:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=yQ95t0gE; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=pQMK1HfM0cNiXzeN kLt7xOQwDYxD8uy/yC2gVLeNxUizyddiBuBqI/VRsr4TK7r8n78j5q7HPwo/ABbi oGj9Dn6d5JHqZWfyb0LCerix7aFMwE/LLmNH3vOjUVOTCGo8+mfbqQh3lAsqPaLJ jXAOxAFCms1OV8rDb6z9eZHMS/Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=dHIfyU2Ioe3Jy70bPjwZ29 iq7cw=; b=yQ95t0gEBq6SSFFgS61l05ub4P3epojmp8MqJ2JEG96xQS5SJRv1Tx TWlrdjVnDcig0yBhBFUULYrTaXj70/r4+UN5UmzKl9AY7av4EYWtJYu4fNe6M542 qSbiHjAm1VzuLCnAkM9KplA5KCiiKWDW/VbawRmh0XXUqUKPVajAk= Received: (qmail 54742 invoked by alias); 20 Oct 2015 09:14:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 54721 invoked by uid 89); 20 Oct 2015 09:14:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 20 Oct 2015 09:14:38 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-12-kANMmew0RqWiGNUVYkS60g-1; Tue, 20 Oct 2015 10:14:33 +0100 Received: from localhost ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 20 Oct 2015 10:14:33 +0100 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Move tan simplifications to match.pd Date: Tue, 20 Oct 2015 10:14:32 +0100 Message-ID: <87a8rdzytj.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: kANMmew0RqWiGNUVYkS60g-1 Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. OK to install? Thanks, Richard gcc/ * builtins.c (fold_builtin_tab): Delete. (fold_builtin_1): Handle constant tan arguments here. * match.pd: Simplify (tan (atan x)) to x. diff --git a/gcc/builtins.c b/gcc/builtins.c index 16f3bfd..3244538 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -160,7 +160,6 @@ static rtx expand_builtin_fabs (tree, rtx, rtx); static rtx expand_builtin_signbit (tree, rtx); static tree fold_builtin_pow (location_t, tree, tree, tree, tree); static tree fold_builtin_powi (location_t, tree, tree, tree, tree); -static tree fold_builtin_tan (tree, tree); static tree fold_builtin_trunc (location_t, tree, tree); static tree fold_builtin_floor (location_t, tree, tree); static tree fold_builtin_ceil (location_t, tree, tree); @@ -7539,33 +7538,6 @@ fold_fixed_mathfn (location_t loc, tree fndecl, tree arg) return NULL_TREE; } -/* Fold function call to builtin tan, tanf, or tanl with argument ARG. - Return NULL_TREE if no simplification can be made. */ - -static tree -fold_builtin_tan (tree arg, tree type) -{ - enum built_in_function fcode; - tree res; - - if (!validate_arg (arg, REAL_TYPE)) - return NULL_TREE; - - /* Calculate the result when the argument is a constant. */ - if ((res = do_mpfr_arg1 (arg, type, mpfr_tan, NULL, NULL, 0))) - return res; - - /* Optimize tan(atan(x)) = x. */ - fcode = builtin_mathfn_code (arg); - if (flag_unsafe_math_optimizations - && (fcode == BUILT_IN_ATAN - || fcode == BUILT_IN_ATANF - || fcode == BUILT_IN_ATANL)) - return CALL_EXPR_ARG (arg, 0); - - return NULL_TREE; -} - /* Fold function call to builtin sincos, sincosf, or sincosl. Return NULL_TREE if no simplification can be made. */ @@ -9613,7 +9585,9 @@ fold_builtin_1 (location_t loc, tree fndecl, tree arg0) break; CASE_FLT_FN (BUILT_IN_TAN): - return fold_builtin_tan (arg0, type); + if (validate_arg (arg0, REAL_TYPE)) + return do_mpfr_arg1 (arg0, type, mpfr_tan, NULL, NULL, 0); + break; CASE_FLT_FN (BUILT_IN_CEXP): return fold_builtin_cexp (loc, arg0, type); diff --git a/gcc/match.pd b/gcc/match.pd index 7d16c52..cd02b04 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -59,6 +59,7 @@ along with GCC; see the file COPYING3. If not see (define_operator_list SIN BUILT_IN_SINF BUILT_IN_SIN BUILT_IN_SINL) (define_operator_list COS BUILT_IN_COSF BUILT_IN_COS BUILT_IN_COSL) (define_operator_list TAN BUILT_IN_TANF BUILT_IN_TAN BUILT_IN_TANL) +(define_operator_list ATAN BUILT_IN_ATANF BUILT_IN_ATAN BUILT_IN_ATANL) (define_operator_list COSH BUILT_IN_COSHF BUILT_IN_COSH BUILT_IN_COSHL) (define_operator_list CEXPI BUILT_IN_CEXPIF BUILT_IN_CEXPI BUILT_IN_CEXPIL) (define_operator_list CPROJ BUILT_IN_CPROJF BUILT_IN_CPROJ BUILT_IN_CPROJL) @@ -2343,7 +2344,14 @@ along with GCC; see the file COPYING3. If not see /* cbrt(expN(x)) -> expN(x/3). */ (simplify (cbrts (exps @0)) - (exps (mult @0 { build_real_truncate (type, dconst_third ()); }))))) + (exps (mult @0 { build_real_truncate (type, dconst_third ()); })))) + + /* tan(atan(x)) -> x. */ + (for tans (TAN) + atans (ATAN) + (simplify + (tans (atans @0)) + @0))) /* cabs(x+0i) or cabs(0+xi) -> abs(x). */ (simplify