From patchwork Tue Feb 13 12:41:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 200412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp506558dyb; Tue, 13 Feb 2024 04:42:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWTVouA+ESO0lxnKQUVBAby4tPnQ1WOQat7OXNcWielDc+NcUDE6T/JJlqsAjRf6k0ceg4xF4qlyrIzKxu7LbisikWtIg== X-Google-Smtp-Source: AGHT+IGbRM/gsDqIVv5kL7iCY8eZZ1hLL0t4zZ6+dxeqNWJUryqW5TTehl7blw1DCiZP8+Lc/Tgv X-Received: by 2002:a0c:e442:0:b0:68e:f0ab:46b5 with SMTP id d2-20020a0ce442000000b0068ef0ab46b5mr647312qvm.62.1707828148488; Tue, 13 Feb 2024 04:42:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707828148; cv=pass; d=google.com; s=arc-20160816; b=hI+P9otEQi6oQ6pzmniTyfVq8LnSw3w/2f/duiitvNzojoqymT1J/WXL4RnRjC02B3 uzO1j3N4pTfhfJEf72Xp4G0QqIxPcL6s2VbdbmULxI2tBqOcEJYLG0b7MAMmveOTCXQl nAw3Zm57aeKFpmU6jm6woIYklpU9imgQytQOQKkJx3u+kDf0jXkUNGed1KTY+e1QcXxF 3NfkNlyTtRK3+daNaNvqElaGzlHsSBvac4kT38cbDyFB+7Z5oxE3D2aQSQoB640yYj/v LIibEl+YujXikfDoIASTRqItvUKcIF0qJ8+/xmrXMwfyPOJWuiZ2Qup8Io0HBTwMNxXd 7BzQ== 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 :subject:to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=wPpeIlUv9zeoo8viVFEZ5yei1VEwEMhRawSsemajWCU=; fh=yDUUBCTwe1zz71wI0xboo4irvtsdwmtEDuitHu3ERbU=; b=rgJ/kwWE6osGU5ahnGn15fpyqhcnpRqINqv2h/xbwNCq4+mysUqkErSaqAkhutYYqi qouK3VFJvUNWLtsibXwUEJg+p8pw81gybQEHdsu9IxshW5AZAJB/gF3J3xplheWKkRJH rf0dT797S7LXC7nxr60XlCJKm61EuQXGw0mWnOTOdGiqeXHemFouqRWAm49T0wtvp+mC x/taOk5AXz+yS7M8VqrcTup/KeGdjSuWkjCMPRDjmbVZxn56sOMuJZidKq2aL4zek8eS yh69V9w0qImQOUt94fu0xl5j3v/3upis0bO+vafuiy0WDFRyE2KseYTVJkXtaFVaMGpn y4iA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=kTTFJrH2; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=kTTFJrH2; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de X-Forwarded-Encrypted: i=2; AJvYcCUVYRcnNcr4fxWS3CtNl7nR1FzKyO/QwGo9cIzwGQAaJLGQmxnDPukJmf6xejVcuDl9cpZne74sPlyPA8dcu8RsMYz4AQ== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g8-20020a0562140ac800b0068d039d4f08si2868726qvi.132.2024.02.13.04.42.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 04:42:28 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=kTTFJrH2; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=kTTFJrH2; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (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 33C7F3858295 for ; Tue, 13 Feb 2024 12:42: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 [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id D36EF3858C30 for ; Tue, 13 Feb 2024 12:41:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D36EF3858C30 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 D36EF3858C30 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707828108; cv=none; b=Pqs6MI1ujiNRP+ocxKtGcFPpn4P1vwBBsOKgJZRXUrM6LaEbi6Uo2e6lPGkx5bP84rdbCVUxG/dOaTVmzM2N1RZQxUAllTrupL9J8j5lZ4qwN34v3wXMsUTKIizQRV+5abcMENJJBFwSeOzMdg5qp69vQRSvpvyVpiee3mtBgRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707828108; c=relaxed/simple; bh=5AtDrtuYu7zgSAKlnJ4g8TWT5ZLSUE0qG4KG3BxVkis=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=bOPsCTzSNy4vqxIlrCwwsubHCcs8t1kE1W8G6BCx9yqL/jDGDKDKQ7Aq1um/UuSH710T0Hb40/tPPP3Zz082D83DEjd/rRvFZrEEKdCMrHBQUe8v3eM8rP3A2+b6AXsj/8j4XxbNIY6dGIasFC1SvuqJIuTdlEr0kiXy5MRKQFk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (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 smtp-out1.suse.de (Postfix) with ESMTPS id C9AAF21B27 for ; Tue, 13 Feb 2024 12:41:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707828105; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=wPpeIlUv9zeoo8viVFEZ5yei1VEwEMhRawSsemajWCU=; b=kTTFJrH26RDwlXhZStgIowVVmRszP9iHUMnOaE6u9RzjPWawBdCT7YXcPb54Aviv1q/cTu 1UNKlSuPPJxsB17MgRLssGpR3HMYvGbRSC1UnDcz5kwLDvxjVZdmyFoEcneyBH1K/7gXNV 8h3712i2opk0iP0rK+wYvoP5Spxq9j8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707828105; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=wPpeIlUv9zeoo8viVFEZ5yei1VEwEMhRawSsemajWCU=; b=zRYonpSM1wocTcNhMF1nEZ9Mt1Uvi6E1+vjxMfIS0fJYypftvHIdA/sGJvDpZuc4QoByZv scsrje1o71yvsIBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1707828105; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=wPpeIlUv9zeoo8viVFEZ5yei1VEwEMhRawSsemajWCU=; b=kTTFJrH26RDwlXhZStgIowVVmRszP9iHUMnOaE6u9RzjPWawBdCT7YXcPb54Aviv1q/cTu 1UNKlSuPPJxsB17MgRLssGpR3HMYvGbRSC1UnDcz5kwLDvxjVZdmyFoEcneyBH1K/7gXNV 8h3712i2opk0iP0rK+wYvoP5Spxq9j8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1707828105; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=wPpeIlUv9zeoo8viVFEZ5yei1VEwEMhRawSsemajWCU=; b=zRYonpSM1wocTcNhMF1nEZ9Mt1Uvi6E1+vjxMfIS0fJYypftvHIdA/sGJvDpZuc4QoByZv scsrje1o71yvsIBA== Date: Tue, 13 Feb 2024 13:41:45 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/113895 - copy_reference_ops_from_ref vs. bitfields MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: 0.52 X-Spamd-Result: default: False [0.52 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-0.64)[-0.641]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_SPAM_SHORT(1.76)[0.585]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: <20240213124228.33C7F3858295@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790787608699463444 X-GMAIL-MSGID: 1790787608699463444 The recent enhancement to discover constant array indices by range info used by get_ref_base_and_extent doesn't work when the outermost component reference is to a bitfield because we track the running offset in the reference ops as bytes. The following does as ao_ref_init_from_vn_reference and recovers that manually, tracking the offset for the purpose of discovering the constant array index in bits instead. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/113895 * tree-ssa-sccvn.cc (copy_reference_ops_from_ref): Track offset to discover constant array indices in bits, handle COMPONENT_REF to bitfields. * gcc.dg/torture/pr113895-1.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr113895-1.c | 16 ++++++++++++++ gcc/tree-ssa-sccvn.cc | 26 ++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr113895-1.c diff --git a/gcc/testsuite/gcc.dg/torture/pr113895-1.c b/gcc/testsuite/gcc.dg/torture/pr113895-1.c new file mode 100644 index 00000000000..e96cb2f33e1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr113895-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ + +int main_i; +void transparent_crc(int); +#pragma pack(1) +struct { + signed : 17; + signed : 6; + unsigned : 13; + unsigned f6 : 12; +} g_20[1]; +int main() +{ + transparent_crc(g_20[main_i].f6); + return 0; +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 95670ae2ed6..d6b8c734e7b 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -1119,14 +1119,14 @@ copy_reference_ops_from_ref (tree ref, vec *result) unsigned HOST_WIDE_INT elsz = tree_to_uhwi (op.op2) * vn_ref_op_align_unit (&op); unsigned HOST_WIDE_INT idx - = (coffset / BITS_PER_UNIT - off.to_constant ()) / elsz; + = (coffset - off.to_constant ()) / BITS_PER_UNIT / elsz; if (idx == 0) op.op0 = op.op1; else op.op0 = wide_int_to_tree (TREE_TYPE (op.op0), wi::to_poly_wide (op.op1) + idx); op.off = idx * elsz; - off += op.off; + off += op.off * BITS_PER_UNIT; } else { @@ -1140,10 +1140,30 @@ copy_reference_ops_from_ref (tree ref, vec *result) || TREE_CODE_CLASS (op.opcode) == tcc_constant) /* end-of ref. */ gcc_assert (i == result->length ()); + else if (op.opcode == COMPONENT_REF) + { + /* op.off is tracked in bytes, re-do it manually + because of bitfields. */ + tree field = op.op0; + /* We do not have a complete COMPONENT_REF tree here so we + cannot use component_ref_field_offset. Do the interesting + parts manually. */ + tree this_offset = DECL_FIELD_OFFSET (field); + if (op.op1 || !poly_int_tree_p (this_offset)) + gcc_unreachable (); + else + { + poly_offset_int woffset + = (wi::to_poly_offset (this_offset) + << LOG2_BITS_PER_UNIT); + woffset += wi::to_offset (DECL_FIELD_BIT_OFFSET (field)); + off += woffset.force_shwi (); + } + } else { gcc_assert (known_ne (op.off, -1)); - off += op.off; + off += op.off * BITS_PER_UNIT; } } }