From patchwork Mon Oct 26 10:08:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 535808 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 B3732140549 for ; Mon, 26 Oct 2015 21:09:13 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=W573GPvp; 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=DI25pHeFLZz0e01R GvYdFUdPbgf8yDz4OwCxeVTZMs3Plbe9hi6pb8DbDPyuNNcQkdS/rcMCrsiAzych MVu5kVUf8NyQ9hA57nSsIAT8OGyknghgI2DY/ekzE0urDIhzNaRagjZiOZyAJZDg 8iDARhVjW8mVfS14oKASBwBLb1g= 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=Sv1qU3LZKhkYAR6cSqoCqq hxOpY=; b=W573GPvpeKwzwDcoJw4NxwifeG2/j+/zDOAZ5Geydfx1n9N4VAVNha OdBUqKJ0ZGypg1Agmtv9A/qWCPLSMlRT0Kf2qFwkkxdE2u/l/jNpcWy64l5aD7UI l9gqE22I3wcQzb9dfwiUM8QCtWzyEFqeZVdzLndlHlJ7coX+AEoNA= Received: (qmail 544 invoked by alias); 26 Oct 2015 10:09:02 -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 527 invoked by uid 89); 26 Oct 2015 10:09:00 -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) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Oct 2015 10:08:59 +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-1-Y4YwwXUXRTahFQOsOH8wrQ-1; Mon, 26 Oct 2015 10:08:54 +0000 Received: from localhost ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 26 Oct 2015 10:08:54 +0000 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Move ldexp, scalbn and scalbln folds to match.pd Date: Mon, 26 Oct 2015 10:08:53 +0000 Message-ID: <87h9leuekq.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: Y4YwwXUXRTahFQOsOH8wrQ-1 Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. OK to install? Thanks, Richard gcc/ * builtins.c (fold_builtin_load_exponent): Rename to... (fold_const_builtin_load_exponent): ...this and only handle constant arguments. (fold_builtin_2): Update accordingly. * match.pd: Add rules previously handled by fold_builtin_load_exponent. gcc/testsuite/ * gcc.dg/torture/builtin-ldexp-1.c: Skip at -O9, diff --git a/gcc/builtins.c b/gcc/builtins.c index 260b66d..248c009 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -8060,20 +8060,11 @@ fold_builtin_frexp (location_t loc, tree arg0, tree arg1, tree rettype) check the mode of the TYPE parameter in certain cases. */ static tree -fold_builtin_load_exponent (location_t loc, tree arg0, tree arg1, - tree type, bool ldexp) +fold_const_builtin_load_exponent (tree arg0, tree arg1, + tree type, bool ldexp) { if (validate_arg (arg0, REAL_TYPE) && validate_arg (arg1, INTEGER_TYPE)) { - STRIP_NOPS (arg0); - STRIP_NOPS (arg1); - - /* If arg0 is 0, Inf or NaN, or if arg1 is 0, then return arg0. */ - if (real_zerop (arg0) || integer_zerop (arg1) - || (TREE_CODE (arg0) == REAL_CST - && !real_isfinite (&TREE_REAL_CST (arg0)))) - return omit_one_operand_loc (loc, type, arg0, arg1); - /* If both arguments are constant, then try to evaluate it. */ if ((ldexp || REAL_MODE_FORMAT (TYPE_MODE (type))->b == 2) && TREE_CODE (arg0) == REAL_CST && !TREE_OVERFLOW (arg0) @@ -9126,11 +9117,12 @@ fold_builtin_2 (location_t loc, tree fndecl, tree arg0, tree arg1) break; CASE_FLT_FN (BUILT_IN_LDEXP): - return fold_builtin_load_exponent (loc, arg0, arg1, type, /*ldexp=*/true); + return fold_const_builtin_load_exponent (arg0, arg1, type, + /*ldexp=*/true); CASE_FLT_FN (BUILT_IN_SCALBN): CASE_FLT_FN (BUILT_IN_SCALBLN): - return fold_builtin_load_exponent (loc, arg0, arg1, - type, /*ldexp=*/false); + return fold_const_builtin_load_exponent (arg0, arg1, type, + /*ldexp=*/false); CASE_FLT_FN (BUILT_IN_FREXP): return fold_builtin_frexp (loc, arg0, arg1, type); diff --git a/gcc/match.pd b/gcc/match.pd index f2e7d64..b15f42f 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -105,6 +105,9 @@ DEFINE_MATH_FN (NEARBYINT) DEFINE_MATH_FN (SIGNBIT) DEFINE_MATH_FN (FMIN) DEFINE_MATH_FN (FMAX) +DEFINE_MATH_FN (LDEXP) +DEFINE_MATH_FN (SCALBN) +DEFINE_MATH_FN (SCALBLN) DEFINE_INT_AND_FLOAT_ROUND_FN (FLOOR) DEFINE_INT_AND_FLOAT_ROUND_FN (CEIL) @@ -2580,6 +2583,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (COPYSIGN @0 tree_expr_nonnegative_p@1) (abs @0)) +(for scale (LDEXP SCALBN SCALBLN) + /* ldexp(0, x) -> 0. */ + (simplify + (scale real_zerop@0 @1) + @0) + /* ldexp(x, 0) -> x. */ + (simplify + (scale @0 integer_zerop@1) + @0) + /* ldexp(x, y) -> x if x is +-Inf or NaN. */ + (simplify + (scale REAL_CST@0 @1) + (if (!real_isfinite (TREE_REAL_CST_PTR (@0))) + @0))) + /* Canonicalization of sequences of math builtins. These rules represent IL simplifications but are not necessarily optimizations. diff --git a/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c b/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c index 94560a8..6412274 100644 --- a/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c +++ b/gcc/testsuite/gcc.dg/torture/builtin-ldexp-1.c @@ -7,6 +7,7 @@ /* { dg-do link } */ /* { dg-options "-fno-finite-math-only" { target sh*-*-* } } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */ extern void link_error(int);