From patchwork Wed Oct 12 17:29:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 1964 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp2725639wrs; Wed, 12 Oct 2022 10:30:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Cu1WR3nctWK4dth6qlXdq9jA/sEiVlQynPGQbfjX6vxDYx+cbhCMa4/mepSzMlQ9decTj X-Received: by 2002:a17:906:7055:b0:78b:9148:6b41 with SMTP id r21-20020a170906705500b0078b91486b41mr23110328ejj.629.1665595806381; Wed, 12 Oct 2022 10:30:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665595806; cv=none; d=google.com; s=arc-20160816; b=Uuz2UcWyR07PJsivtciMRwwQ42LJEdOyhQ+wrfkrxp9ZrlbMDRdGLOYGreM1y1Sj7b E9xKdCYsOixfGOtQRqpm9z6udFACXRrjWaDM9ZvSi0lDNBHXzAJ1G2xy06ZHX4oRZzcw 2pU/gam5DjHehndYahbvB/jt/0TJLb5Neh6sl9zOx3qUB+6nCnM5WAM2enHD9RrIFpzO 4ViUXprw8zP2IFENM4m1Fyv6jC2dyVdpq15wHJNgcLBRqRgIP4Ih5sTAtrF4ioY4zC5m 8/MD8X+8Qe3ogzUo+HAtxW96UOJo2L+1lEgB7eSqmqc+q0OUnsdgkSkfpZ+eYZ2eyhH3 ckMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :to:content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=ZWluQjPMjcNISdrF2vjjEN5L/B6MRKOlHdFi6PUV3PM=; b=zppZXPVtcG9IbZrTFqPaFZmfopi4aiSDilQC2I0WJNWJB0Fb4n2f2FJgIOx1J6HTfc o2wP7/Wu7SuOLtsrbGd8CHHndw3Mr5kX3t+dLlFuYpiTGzlualw2To/x8PnKfgSr6ly7 obEOsHXRBikKSE7KPI9zbpN3vNqu2I7dFDZHSJOGhnSfYQxGF8QDuGFI2mRUHiBX5eDd avXk/IfX11ZIyjhAyTZT3zda5qs98U52U2y0f3pd1lfkaK1L0S7T5XKCogBxNHQETOd7 p1kJbnMyOyuLCb9RqHsAcNAA5p5fVDXBEDpr6RuwW520PcU+uTDaMCqizU9DextiO1od 1a3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=to0N6o6j; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hc32-20020a17090716a000b0078dec48d442si3746416ejc.680.2022.10.12.10.30.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Oct 2022 10:30:06 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=to0N6o6j; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2F3D63858401 for ; Wed, 12 Oct 2022 17:30:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F3D63858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665595805; bh=ZWluQjPMjcNISdrF2vjjEN5L/B6MRKOlHdFi6PUV3PM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=to0N6o6je3tE321w+hEls8cpiPigloSPM00e6Sg7EhJckXLRKP6jo50VItrswMRmF ihDnYP9qJuupVoXdaSFs1S7jSbE79ma0TXh7Ijgm2btxcXOE4k5YmAYjYqL3tcTtUv YcT7r3svBzpQkcF4Hs2PaT1LQR2suJzceFfxYzok= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 19DA83858D38 for ; Wed, 12 Oct 2022 17:29:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 19DA83858D38 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C17BA165C; Wed, 12 Oct 2022 10:29:21 -0700 (PDT) Received: from [10.57.1.129] (unknown [10.57.1.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EE7263F766; Wed, 12 Oct 2022 10:29:14 -0700 (PDT) Message-ID: Date: Wed, 12 Oct 2022 18:29:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Subject: ifcvt: Fix bitpos calculation in bitfield lowering [PR107229] X-Spam-Status: No, score=-20.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Andre Vieira \(lists\) via Gcc-patches" From: "Andre Vieira (lists)" Reply-To: "Andre Vieira \(lists\)" Cc: Richard Sandiford , Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746503788189545947?= X-GMAIL-MSGID: =?utf-8?q?1746503788189545947?= Hi, The bitposition calculation for the bitfield lowering in loop if conversion was not taking DECL_FIELD_OFFSET into account, which meant that it would result in wrong bitpositions for bitfields that did not end up having representations starting at the beginning of the struct. Bootstrappend and regression tested on aarch64-none-linux-gnu and x86_64-pc-linux-gnu. gcc/ChangeLog:     PR tree-optimization/107229     * gcc/tree-if-conv.cc (get_bitfield_rep): Fix bitposition calculation. gcc/testsuite/ChangeLog:     * gcc.dg/vect/pr107229-1.c: New test.     * gcc.dg/vect/pr107229-2.c: New test.     * gcc.dg/vect/pr107229-3.c: New test. diff --git a/gcc/testsuite/gcc.dg/vect/pr107229-1.c b/gcc/testsuite/gcc.dg/vect/pr107229-1.c new file mode 100644 index 0000000000000000000000000000000000000000..67b432383d057a630746aa00af50c25fcb527d8e --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr107229-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* PR tree-optimization/107229. */ + +int a, c; +struct { + long d; + int : 8; + int : 27; + int e : 21; +} f; +void g(int b) { a = a & 1; } +int main() { + while (c) + g(f.e); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr107229-2.c b/gcc/testsuite/gcc.dg/vect/pr107229-2.c new file mode 100644 index 0000000000000000000000000000000000000000..88bffb63d5e8b2d7bcdeae223f4ec6ea4f611bc9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr107229-2.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* PR tree-optimization/107229. */ + +int a, c; +struct { + long f; + long g; + long d; + int : 8; + int : 27; + int e : 21; +} f; +void g(int b) { a = a & 1; } +int main() { + while (c) + g(f.e); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr107229-3.c b/gcc/testsuite/gcc.dg/vect/pr107229-3.c new file mode 100644 index 0000000000000000000000000000000000000000..4abd8c14531b40e9dbe9802a8f9a0eabba673c9f --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr107229-3.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* PR tree-optimization/107229. */ + +int a, c; +struct { + long f; + long g; + long d; + int : 8; + int : 32; + int : 2; + int e : 21; +} f; +void g(int b) { a = a & 1; } +int main() { + while (c) + g(f.e); + return 0; +} diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index e468a4659fa28a3a31c3390cf19bee65f4590b80..33160ddef80cbd75c2a927fb50bddd792bbf5dd4 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -3298,10 +3298,20 @@ get_bitfield_rep (gassign *stmt, bool write, tree *bitpos, *struct_expr = TREE_OPERAND (comp_ref, 0); if (bitpos) - *bitpos - = fold_build2 (MINUS_EXPR, bitsizetype, - DECL_FIELD_BIT_OFFSET (field_decl), - DECL_FIELD_BIT_OFFSET (rep_decl)); + { + tree bf_pos = fold_build2 (MULT_EXPR, bitsizetype, + DECL_FIELD_OFFSET (field_decl), + build_int_cst (bitsizetype, 8)); + bf_pos = fold_build2 (PLUS_EXPR, bitsizetype, bf_pos, + DECL_FIELD_BIT_OFFSET (field_decl)); + tree rep_pos = fold_build2 (MULT_EXPR, bitsizetype, + DECL_FIELD_OFFSET (rep_decl), + build_int_cst (bitsizetype, 8)); + rep_pos = fold_build2 (PLUS_EXPR, bitsizetype, rep_pos, + DECL_FIELD_BIT_OFFSET (rep_decl)); + + *bitpos = fold_build2 (MINUS_EXPR, bitsizetype, bf_pos, rep_pos); + } return rep_decl;