From patchwork Thu Aug 19 15:53:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1518734 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) 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=nW9dSebR; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4Gr8SR1jLCz9sRK for ; Fri, 20 Aug 2021 01:53:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 727FB389802D for ; Thu, 19 Aug 2021 15:53:24 +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 22935385E44A for ; Thu, 19 Aug 2021 15:53:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 22935385E44A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=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=Pr2oTNrvpMMrLtJ0LhqrqVxxoZK3AEWu1K14VwBKhgo=; b=nW9dSebR13kavHryVGXZ8+fRrL zbVf4QK5vtSh0N5eVnIODXrDwUBCKA0fDvn+8hy8N+F/y6XB2n+iXMVrAYkqOK8P9q/BtHOqiXaam vmgNUmNeq5Uv6lUddC/n0x0tTUzIzJEsDLqb6eRiedNmqvK14/3hKegQRgxYYqt+1Ea6HpK6XeKsh hzqF+2WhMIeAmlVjTX70kDS3kwsrefOiQYloJ3ImDRIU+NjrnI2AADmMy0UnvkMeDW2ZYsBvH9KCo mx1mhk7p3A7jy/+c5FMZtM0a+w289C316oAa0DIH5/9IZ1dmYBmawgA5C4+tk2Hi1yWpoh98BFzUj b/Lfppag==; Received: from host109-154-46-127.range109-154.btcentralplus.com ([109.154.46.127]:62606 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mGkLm-0005nX-Kd for gcc-patches@gcc.gnu.org; Thu, 19 Aug 2021 11:53:02 -0400 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] Fold more constants during veclower pass. Date: Thu, 19 Aug 2021 16:53:01 +0100 Message-ID: <02a901d79512$4ac874c0$e0595e40$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdeVEXr6hyWmZugDRJGUd8lqqE5a6Q== 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.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" An issue with a backend patch I've been investigating has revealed a missed optimization opportunity during GCC's vector lowering pass. An unrecognized insn for "(set (reg:SI) (not:SI (const_int 0))" revealed that not only was my expander not expecting a NOT with a constant operand, but also that veclower was producing the dubious tree expression ~0. The attached patch replaces a call to gimple_build_assign with a call to either gimplify_build1 or gimplify_build2 depending upon whether the operation takes one or two operands. The net effect is that where GCC previously produced the following optimized gimple for testsuite/c-c++common/Wunused-var-16.c (notice the ~0 and the "& 0"): void foo () { V x; V y; vector(16) unsigned char _1; unsigned char _7; unsigned char _8; y_2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; x_3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; _7 = ~0; _1 = {_7, _7, _7, _7, _7, _7, _7, _7, _7, _7, _7, _7, _7, _7, _7, _7}; _8 = 0 & _7; y_4 = {_8, _8, _8, _8, _8, _8, _8, _8, _8, _8, _8, _8, _8, _8, _8, _8}; v = y_4; return; } With this patch we now generate: void foo () { V x; V y; vector(16) unsigned char _1; y_2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; x_3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; _1 = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; y_4 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; v = y_4; return; } This patch has been tested on x86_64-pc-linux-gnu with "make bootstrap" and "make -k check". Ok for mainline? 2021-08-18 Roger Sayle gcc/ChangeLog * tree-vect-generic.c (expand_vector_operations_1): Use either gimplify_build1 or gimplify_build2 instead of gimple_build_assign when constructing scalar splat expressions. gcc/testsuite/ChangeLog * c-c++common/Wununsed-var-16.c: Add extra check for that ~0 is optimized away. Roger diff --git a/gcc/testsuite/c-c++-common/Wunused-var-16.c b/gcc/testsuite/c-c++-common/Wunused-var-16.c index 8bdbcd3..31c7db3 100644 --- a/gcc/testsuite/c-c++-common/Wunused-var-16.c +++ b/gcc/testsuite/c-c++-common/Wunused-var-16.c @@ -1,6 +1,6 @@ /* PR c++/78949 */ /* { dg-do compile } */ -/* { dg-options "-Wunused" } */ +/* { dg-options "-Wunused -fdump-tree-optimized" } */ /* { dg-additional-options "-fno-common" { target hppa*-*-hpux* } } */ typedef unsigned char V __attribute__((vector_size(16))); @@ -14,3 +14,5 @@ foo () y &= ~x; v = y; } + +/* { dg-final { scan-tree-dump-not " ~0" "optimized" } } */ diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c index 2e00b3e..0d7f041 100644 --- a/gcc/tree-vect-generic.c +++ b/gcc/tree-vect-generic.c @@ -2162,9 +2162,10 @@ expand_vector_operations_1 (gimple_stmt_iterator *gsi, if (op >= FIRST_NORM_OPTAB && op <= LAST_NORM_OPTAB && optab_handler (op, TYPE_MODE (TREE_TYPE (type))) != CODE_FOR_nothing) { - tree slhs = make_ssa_name (TREE_TYPE (TREE_TYPE (lhs))); - gimple *repl = gimple_build_assign (slhs, code, srhs1, srhs2); - gsi_insert_before (gsi, repl, GSI_SAME_STMT); + tree stype = TREE_TYPE (TREE_TYPE (lhs)); + tree slhs = (rhs2 != NULL_TREE) + ? gimplify_build2 (gsi, code, stype, srhs1, srhs2) + : gimplify_build1 (gsi, code, stype, srhs1); gimple_assign_set_rhs_from_tree (gsi, build_vector_from_val (type, slhs)); update_stmt (stmt);