From patchwork Fri Nov 6 15:08:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 541007 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 2C76F1402B4 for ; Sat, 7 Nov 2015 02:09:07 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=aqrlhSyd; 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=S14HgUpajYWw3H8q fdwGeoM6xe7a983Ii0TTmNGNBLbEceVp5XTzS43DPyFHDhQROl3DoaEgHCnpwDWB lUkR25M3z1X8wBsN9UTQ1F5PrXBKTqaJsN2dEcZiG9Y9h9QqZuCbNQOEMqwuAAHJ 0IVnOFQKzJwnnXMI/ijdSrL9Q3E= 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=9MK2tgD6GyvAJ/0MCPfYzi b+hVE=; b=aqrlhSydzruXXVBdm6QOh4o9VzZ/ehaGiU/2ZwN25HdJF/b5x8RC2o hGks/QOuIsVtfSUsp4JtOo2O9Mq/VHRBmHCAZHMQfjZWW/UbT8/GlNI1/ZQPCpZZ khYCbaTzz7XHcNTTf6AiXr8x/gxghg/sbyn7D1ctatNYgLK9qMomw= Received: (qmail 92850 invoked by alias); 6 Nov 2015 15:08:56 -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 92753 invoked by uid 89); 6 Nov 2015 15:08:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 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; Fri, 06 Nov 2015 15:08:53 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-2-9hNeNdw-Rc-A80kyJv6Izw-1; Fri, 06 Nov 2015 15:08:48 +0000 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 6 Nov 2015 15:08:47 +0000 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Handle constant fp classifications in fold-const-call.c Date: Fri, 06 Nov 2015 15:08:47 +0000 Message-ID: <87611ftbb4.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: 9hNeNdw-Rc-A80kyJv6Izw-1 Move the constant "is finite", "is infinite" and "is nan" queries to fold-const-call.c. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. OK to install? Thanks, Richard gcc/ * builtins.c (fold_builtin_classify): Move constant cases to... * fold-const-call.c (fold_const_call_ss): ...here. diff --git a/gcc/builtins.c b/gcc/builtins.c index 69c56e7..6eefd54 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -8018,7 +8018,6 @@ static tree fold_builtin_classify (location_t loc, tree fndecl, tree arg, int builtin_index) { tree type = TREE_TYPE (TREE_TYPE (fndecl)); - REAL_VALUE_TYPE r; if (!validate_arg (arg, REAL_TYPE)) return NULL_TREE; @@ -8029,16 +8028,6 @@ fold_builtin_classify (location_t loc, tree fndecl, tree arg, int builtin_index) if (!HONOR_INFINITIES (arg)) return omit_one_operand_loc (loc, type, integer_zero_node, arg); - if (TREE_CODE (arg) == REAL_CST) - { - r = TREE_REAL_CST (arg); - if (real_isinf (&r)) - return real_compare (GT_EXPR, &r, &dconst0) - ? integer_one_node : integer_minus_one_node; - else - return integer_zero_node; - } - return NULL_TREE; case BUILT_IN_ISINF_SIGN: @@ -8078,24 +8067,12 @@ fold_builtin_classify (location_t loc, tree fndecl, tree arg, int builtin_index) && !HONOR_INFINITIES (arg)) return omit_one_operand_loc (loc, type, integer_one_node, arg); - if (TREE_CODE (arg) == REAL_CST) - { - r = TREE_REAL_CST (arg); - return real_isfinite (&r) ? integer_one_node : integer_zero_node; - } - return NULL_TREE; case BUILT_IN_ISNAN: if (!HONOR_NANS (arg)) return omit_one_operand_loc (loc, type, integer_zero_node, arg); - if (TREE_CODE (arg) == REAL_CST) - { - r = TREE_REAL_CST (arg); - return real_isnan (&r) ? integer_one_node : integer_zero_node; - } - arg = builtin_save_expr (arg); return fold_build2_loc (loc, UNORDERED_EXPR, type, arg, arg); diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c index 5af2c63..c277d2b 100644 --- a/gcc/fold-const-call.c +++ b/gcc/fold-const-call.c @@ -736,6 +736,31 @@ fold_const_call_ss (wide_int *result, built_in_function fn, /* Not yet folded to a constant. */ return false; + CASE_FLT_FN (BUILT_IN_FINITE): + case BUILT_IN_FINITED32: + case BUILT_IN_FINITED64: + case BUILT_IN_FINITED128: + case BUILT_IN_ISFINITE: + *result = wi::shwi (real_isfinite (arg) ? 1 : 0, precision); + return true; + + CASE_FLT_FN (BUILT_IN_ISINF): + case BUILT_IN_ISINFD32: + case BUILT_IN_ISINFD64: + case BUILT_IN_ISINFD128: + if (real_isinf (arg)) + *result = wi::shwi (arg->sign ? -1 : 1, precision); + else + *result = wi::shwi (0, precision); + return true; + + CASE_FLT_FN (BUILT_IN_ISNAN): + case BUILT_IN_ISNAND32: + case BUILT_IN_ISNAND64: + case BUILT_IN_ISNAND128: + *result = wi::shwi (real_isnan (arg) ? 1 : 0, precision); + return true; + default: return false; }