From patchwork Fri Oct 20 13:38:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 1852547 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SBlzf6d69z20cX for ; Sat, 21 Oct 2023 00:38:53 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92BC73858D39 for ; Fri, 20 Oct 2023 13:38:51 +0000 (GMT) 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 C937E3858D20 for ; Fri, 20 Oct 2023 13:38:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C937E3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C937E3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697809120; cv=none; b=Hf6aPAMNKd1AVebSANYzxL+rVZtT6+4jJDJ9ZmQNPlLEmEQfX+Ok7o7HlTYPJOfZ60T2G+4+psyVsMHwh1tCcc3+IBPFG+e+r5agVlS9wb7VFB+uoobjIiAsvEaG9AFTrYRHY7B+wfGWyegxMTUQfM9Fr/Z+NWE+t0KDtOK6QPk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697809120; c=relaxed/simple; bh=h5XTWGv0N6f7zT8jl/QyeS/9Gn0yXXld/8631zR1xAg=; h=Message-ID:Date:MIME-Version:To:From:Subject; b=Y2voatv4BGLIea4MszAXPiXiKjfnsl5Uxh8nReTh+VpQn5S5tq7L9x4uOy0MYJ8sghzwVRtZWI+eL0aMw60Rd8KT3YP/JLU80YjPfuO4OlK475kAfz0er0kG0+JazFcu1Ikxtnkfq2DHUKg1Te6LfokRS6DEWD586IRNwnFeXkg= ARC-Authentication-Results: i=1; server2.sourceware.org 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 BE6562F4; Fri, 20 Oct 2023 06:39:18 -0700 (PDT) Received: from [10.57.67.225] (unknown [10.57.67.225]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AB54E3F5A1; Fri, 20 Oct 2023 06:38:36 -0700 (PDT) Message-ID: <29e81713-e0a7-47da-bb4b-01b6629962c1@arm.com> Date: Fri, 20 Oct 2023 14:38:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Cc: Richard Biener From: "Andre Vieira (lists)" Subject: [PATCH] ifcvt: Don't lower bitfields with non-constant offsets [PR 111882] X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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.30 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 Hi, This patch stops lowering of bitfields by ifcvt when they have non-constant offsets as we are not likely to be able to do anything useful with those during vectorization. That also fixes the issue reported in PR 111882, which was being caused by an offset with a side-effect being lowered, but constants have no side-effects so we will no longer run into that problem. Bootstrapped and regression tested on aarch64-unknown-linux-gnu. OK for trunk? gcc/ChangeLog: PR tree-optimization/111882 * tree-if-conv.cc (get_bitfield_rep): Return NULL_TREE for bitfields with non-constant offsets. gcc/testsuite/ChangeLog: * gcc.dg/vect/pr111882.c: New test. diff --git a/gcc/testsuite/gcc.dg/vect/pr111882.c b/gcc/testsuite/gcc.dg/vect/pr111882.c new file mode 100644 index 0000000000000000000000000000000000000000..024ad57b6930dd1f516e9c8127e2b440016360c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr111882.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-additional-options { -fdump-tree-ifcvt-all } } */ + +static void __attribute__((noipa)) f(int n) { + int i, j; + struct S { char d[n]; int a; int b : 17; int c : 12; }; + struct S A[100][1111]; + for (i = 0; i < 100; i++) { + asm volatile("" : : "g"(&A[0][0]) : "memory"); + for (j = 0; j < 1111; j++) A[i][j].b = 2; + } +} +void g(void) { f(1); } + +/* { dg-final { scan-tree-dump-not "Bitfield OK to lower" "ifcvt" } } */ diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index dab7eeb7707ae8f1f342a571f8e5c99e0ef39309..66f3c882cb688049224b344b81637e7b1ae7e36c 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -3495,6 +3495,7 @@ get_bitfield_rep (gassign *stmt, bool write, tree *bitpos, : gimple_assign_rhs1 (stmt); tree field_decl = TREE_OPERAND (comp_ref, 1); + tree ref_offset = component_ref_field_offset (comp_ref); tree rep_decl = DECL_BIT_FIELD_REPRESENTATIVE (field_decl); /* Bail out if the representative is not a suitable type for a scalar @@ -3509,6 +3510,12 @@ get_bitfield_rep (gassign *stmt, bool write, tree *bitpos, if (compare_tree_int (DECL_SIZE (field_decl), bf_prec) != 0) return NULL_TREE; + if (!TREE_CONSTANT (DECL_FIELD_OFFSET (rep_decl)) + || !TREE_CONSTANT (DECL_FIELD_BIT_OFFSET (rep_decl)) + || !TREE_CONSTANT (ref_offset) + || !TREE_CONSTANT (DECL_FIELD_BIT_OFFSET (field_decl))) + return NULL_TREE; + if (struct_expr) *struct_expr = TREE_OPERAND (comp_ref, 0); @@ -3529,7 +3536,7 @@ get_bitfield_rep (gassign *stmt, bool write, tree *bitpos, the structure and the container from the number of bits from the start of the structure and the actual bitfield member. */ tree bf_pos = fold_build2 (MULT_EXPR, bitsizetype, - DECL_FIELD_OFFSET (field_decl), + ref_offset, build_int_cst (bitsizetype, BITS_PER_UNIT)); bf_pos = fold_build2 (PLUS_EXPR, bitsizetype, bf_pos, DECL_FIELD_BIT_OFFSET (field_decl));