From patchwork Mon Oct 23 13:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 156889 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1300793vqx; Mon, 23 Oct 2023 06:33:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IER56FcDDHNcABQlg0ACKTUwaVnE9+G6vjPKEK0XIiZPNnRv6PsWoOHG1Fl68wUma/wBEYZ X-Received: by 2002:a05:622a:1749:b0:41c:da69:e90a with SMTP id l9-20020a05622a174900b0041cda69e90amr9309597qtk.50.1698068009252; Mon, 23 Oct 2023 06:33:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698068009; cv=pass; d=google.com; s=arc-20160816; b=n52T/67R0rs4zg2zcAGRKZIG+RHYxd1UV0HVEm9Mv3otoBzkobQJDkxCgnQV/hfGKf xDGiHz2Cc3lU8CXu0QtATyEqoRsMdSgrJCXWnPBeXuSA76gQo2bipdFOyPx0i+2nlbtH 9WZ9bzmgCpFsA5GozvAP5vyzT3WbEh4+sfS0bIdmZVGbA89nOB/2Xcq5nOlX0kI9cXkU CRiEzmc4ZDsT33Nd9itgV4FgYaGM71zLjTgVSLciD9WS5pvxCSPAgETfpTfMzVuEIPzy kR+ecNSCbdIdDOEXk03/LgWbM4saS/jCmm308PCimoWTI9fuh7CkU1ZTUp3TZvYDQefc aFZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:subject:to:from:date:arc-filter:dmarc-filter :delivered-to; bh=Y2vm1DA5xrf9OIE0SB03BmNijnOLQb5MarPLh9wCV+A=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=wSP1daMTAuQEpTD3ElZYoe5wwfoPl7J3KKHnuwpp4a9ih5ssMPbDVvUe8IgadEGOQG aOXV2SbzBuxZ7K4SC0fDeOJUFtOEy73yNtayYtpWO01EOh4h0gbvXG+vFnO5WgYUI1NB YTCzBkqyO/Aw6sASN0bG+dlWVlJo2jZyX4hxNvAnbXjbb28VCgWC8BIPdunzOTdYI1hO OI1fQECTO5q0wg3EyyUL2x9rNJI+blTvppLhEIvFqICBluPMi4PVeX1E3MeIw7W+xowT gCctSMulGJFtsWg8XGlWTrBtkHIbuDDf8VEUkiaJoJIvP7KE85I9PNSbiIT5t65+OfiW 090g== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c15-20020ac87dcf000000b003eb14b07a6dsi5469869qte.125.2023.10.23.06.33.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 06:33:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC8E53857012 for ; Mon, 23 Oct 2023 13:33:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 51FE53857C71 for ; Mon, 23 Oct 2023 13:32:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51FE53857C71 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 51FE53857C71 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.28 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698067951; cv=none; b=lHMd9XptVnKQav38SHRUAzJhpyWrTd+rtjRQF38YUUSk8LjyczyHaznLut7Xwi5i6+SsSTKL1WG9hMuOXK6XGdGcG9/p6cxP29rzHdQwYPwvsGkA8Vkw9+GFCtPPrYwXC5uKEnRsAgUGXqqtqB0uHC+OynQ5r/n1Oul1A+8OELg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698067951; c=relaxed/simple; bh=Ok5SHkm2TIkuB6JM1BB9DyMGXRBukQIxG1sVloywMqo=; h=Date:From:To:Subject:MIME-Version; b=uxAfBNHsmuRELoatgOTdKfUHCiGBztoJsuT1X1hWeg8MSoVAlbEvi35f4lXE+WPy37wXezKEeX5UeyZrgYZicK7r9gXSlvwwQAnRynVWmQduUb0fNZDaUK8Sjg8KeU+DudUGDex1k5tVkwCd055wxRX9ewB2YWUVnzJNv1MVGPw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 3DBB021846 for ; Mon, 23 Oct 2023 13:32:29 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 01EA52C8CD for ; Mon, 23 Oct 2023 13:32:29 +0000 (UTC) Date: Mon, 23 Oct 2023 13:32:29 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/111916 - SRA of BIT_FIELD_REF of constant pool entries User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Level: X-Spamd-Bar: / Authentication-Results: smtp-out1.suse.de; dkim=none; dmarc=none; spf=softfail (smtp-out1.suse.de: 149.44.160.134 is neither permitted nor denied by domain of rguenther@suse.de) smtp.mailfrom=rguenther@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [-0.01 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_GOOD(0.00)[149.44.160.134:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-3.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; R_SPF_SOFTFAIL(0.60)[~all:c]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; VIOLATED_DIRECT_SPF(3.50)[]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; DMARC_NA(0.20)[suse.de]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: -0.01 X-Rspamd-Queue-Id: 3DBB021846 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Message-Id: <20231023133328.EC8E53857012@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780553360908480197 X-GMAIL-MSGID: 1780553360908480197 The following adjusts a leftover BIT_FIELD_REF special-casing to only cover the cases general code doesn't handle. Boostrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/111916 * tree-sra.cc (sra_modify_assign): Do not lower all BIT_FIELD_REF reads that are sra_handled_bf_read_p. * gcc.dg/torture/pr111916.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr111916.c | 16 ++++++++++++++++ gcc/tree-sra.cc | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr111916.c diff --git a/gcc/testsuite/gcc.dg/torture/pr111916.c b/gcc/testsuite/gcc.dg/torture/pr111916.c new file mode 100644 index 00000000000..2873045aaa4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr111916.c @@ -0,0 +1,16 @@ +/* { dg-do run } */ + +#pragma pack(1) +struct A { + int b : 4; + int c : 11; + int d : 2; + int e : 5; +} f; +int main() +{ + struct A g = {1, 1, 1, 1}; + while (!g.b) + f = g; + return 0; +} diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc index f8dff8b27d7..b985dee6964 100644 --- a/gcc/tree-sra.cc +++ b/gcc/tree-sra.cc @@ -4275,7 +4275,8 @@ sra_modify_assign (gimple *stmt, gimple_stmt_iterator *gsi) if (TREE_CODE (rhs) == REALPART_EXPR || TREE_CODE (lhs) == REALPART_EXPR || TREE_CODE (rhs) == IMAGPART_EXPR || TREE_CODE (lhs) == IMAGPART_EXPR - || TREE_CODE (rhs) == BIT_FIELD_REF || TREE_CODE (lhs) == BIT_FIELD_REF) + || (TREE_CODE (rhs) == BIT_FIELD_REF && !sra_handled_bf_read_p (rhs)) + || TREE_CODE (lhs) == BIT_FIELD_REF) { modify_this_stmt = sra_modify_expr (gimple_assign_rhs1_ptr (stmt), gsi, false);