From patchwork Sun Jun 14 22:39:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1309107 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=M8I9gnLY; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49lTtC3QWZz9sQx for ; Mon, 15 Jun 2020 08:39:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5AD153851C1D; Sun, 14 Jun 2020 22:39:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id ADDEB3858D34; Sun, 14 Jun 2020 22:39:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ADDEB3858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=roger@nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=xPbF1nEBR7+OgFwh9zurILxnw2fbCTgD6I1UT2QHu/Q=; b=M8I9gnLYLiyIiRUevy9EpEq+ND 5pcB/qSmefzLm6EVQZDlS6cpRPxl4xOH2l9XeA6XbNZ/ZSlhUhpT/TQriy1+RxHUVKG6qYHgsdOI5 aY3QqyUGkKESQzs/Bfb/RCW3+i3QdaAHd+ClaZqT+LfI4FTOdaVfUJ4SuM4/x6ejbKZZ8X9B8aOsI To4XuKZi3zGsl9E4nV9LjOOQ+SebHzHbbFE/zbIdSEYu4rVhvyvwOxBskc7CVpcXAP8mOcyyK9+0s 2ey87MDOctrZqOyuJkrVZjwRV1+RtxVmWQ05k5Sf4nCtW/xm5ZHFrD1B/rDKB/EIXsLWQedvi0uMe bfXNqcUQ==; Received: from host86-137-89-56.range86-137.btcentralplus.com ([86.137.89.56]:64883 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jkbHp-0007us-UT; Sun, 14 Jun 2020 18:39:34 -0400 From: "Roger Sayle" To: , Subject: [PATCH] gfortran: Improve translation of POPPAR intrinsic Date: Sun, 14 Jun 2020 23:39:32 +0100 Message-ID: <00f201d6429c$ad4fae20$07ef0a60$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdZCmU6OR/ZJ2Q5SQrSWBBgrRJPqig== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The following patch to gfortran's trans-instrinsic.c tweaks the generic that is produced for popcnt on integer(kind=16). Currently, the double word popcnt is implemented as parityll(hipart(x))^parityll(lopart(x)), but with this patch this is now translated as parityll(hipart(x)^lopart(x)). This will be just an aesthetic change once my tree-level parity optimization patch of 12th June is reviewed and accepted, but generating the more efficient form initially, avoids a tiny bit of garbage collection when the middle-end cleans this up into its preferred form. The semantics/correctness of this change are tested by the run-time tests in gfortran.dg/popcnt_poppar_2.F90 This patch has been tested with "make bootstrap" and "make -k check" on x86_64-pc-linux-gnu with no regressions. If approved, I'd very much appreciate it if the (gfortran) reviewer could commit this change for me. 2020-06-14 Roger Sayle * trans-intrinsic.c (gfc_conv_intrinsic_popcnt_poppar): Translate poppar(kind=16) as parityll(hipart(x)^lopart(x)) instead of parityll(hipart(x))^parityll(lopart(x)). Thanks in advance, Roger --- Roger Sayle NextMove Software Cambridge, UK diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index fd88099..363874e 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -7153,35 +7153,39 @@ gfc_conv_intrinsic_popcnt_poppar (gfc_se * se, gfc_expr *expr, int parity) as 'long long'. */ gcc_assert (argsize == 2 * LONG_LONG_TYPE_SIZE); - func = builtin_decl_explicit (parity - ? BUILT_IN_PARITYLL - : BUILT_IN_POPCOUNTLL); - /* Convert it to an integer, and store into a variable. */ utype = gfc_build_uint_type (argsize); arg = fold_convert (utype, arg); arg = gfc_evaluate_now (arg, &se->pre); - - /* Call the builtin twice. */ - call1 = build_call_expr_loc (input_location, func, 1, - fold_convert (long_long_unsigned_type_node, - arg)); - - arg2 = fold_build2_loc (input_location, RSHIFT_EXPR, utype, arg, - build_int_cst (utype, LONG_LONG_TYPE_SIZE)); - call2 = build_call_expr_loc (input_location, func, 1, - fold_convert (long_long_unsigned_type_node, - arg2)); + arg_type = long_long_unsigned_type_node; /* Combine the results. */ if (parity) - se->expr = fold_build2_loc (input_location, BIT_XOR_EXPR, result_type, - call1, call2); + { + /* Construct parityll (LOPART (arg) ^ HIPART (arg)) */ + arg2 = fold_build2_loc (input_location, RSHIFT_EXPR, utype, arg, + build_int_cst (utype, LONG_LONG_TYPE_SIZE)); + arg = fold_build2_loc (input_location, BIT_XOR_EXPR, arg_type, + fold_convert (arg_type, arg), + fold_convert (arg_type, arg2)); + func = builtin_decl_explicit (BUILT_IN_PARITYLL); + argsize = LONG_LONG_TYPE_SIZE; + } else - se->expr = fold_build2_loc (input_location, PLUS_EXPR, result_type, - call1, call2); - - return; + { + func = builtin_decl_explicit (BUILT_IN_POPCOUNTLL); + + /* Call the builtin twice. */ + call1 = build_call_expr_loc (input_location, func, 1, + fold_convert (arg_type, arg)); + arg2 = fold_build2_loc (input_location, RSHIFT_EXPR, utype, arg, + build_int_cst (utype, LONG_LONG_TYPE_SIZE)); + call2 = build_call_expr_loc (input_location, func, 1, + fold_convert (arg_type, arg2)); + se->expr = fold_build2_loc (input_location, PLUS_EXPR, result_type, + call1, call2); + return; + } } /* Convert the actual argument twice: first, to the unsigned type of the