From patchwork Wed Jan 31 12:43:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 194731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1862529dyb; Wed, 31 Jan 2024 04:49:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+3Jx/J7c1rC7xvqFJJK9n0Tt0JLni0hSLGOSrbaGQLxCXHqmqkGWKBVJHPCKIQbHlKsti X-Received: by 2002:a05:620a:1671:b0:783:e054:a25e with SMTP id d17-20020a05620a167100b00783e054a25emr1474484qko.54.1706705369417; Wed, 31 Jan 2024 04:49:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706705369; cv=pass; d=google.com; s=arc-20160816; b=tehXD/4HJ8t8mVFqW/+9WiVB1bMiAmljMFGC+l514Kx+gAnhX88uqoIUZORUrI1eMo zk+5wvYGcbE3Tdus7I5qI7UneZp3764fJmgBJnPDtssG6v3WXrhyCjAbi+R8tTEoYEqc FKA2N7Hjgx6WOscdy9fqSCAaH76c3KOjpSzmUviiXB95/NzbCHqJltw6N1YP6P4HpADH 11EDkG8okJdnZZP89ayENCIDevXC08q0N0DXQSRZV9HpBhFSpJPzJDTf4FCu+Lfa55vu Qo3KO82uwtRSqQRQcxomTbEsASAqGlL3jHU+OMkLYkVNVuHPq4IKufotGXZ5OR9GCiQF XGuQ== 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=8LNZqBFV+1JSziN/EyMhPbKCazNECcNmKKch7nIXMHY=; fh=qbDN1DBj7syrMSCHXB5Xre1MEXzShHzOWGbpmokTzb0=; b=hDRMmrWpk7H9ZFX4tyKUuLtZrR8TGsmlToCjgY84IhvR4qWh1NYo6aoUvEe150GpU0 rGBhL5HEH78m/yFnXoh0KLkp0bmW8Z9vs2Jt/4SQnSpIW+iigWXLbrUbMPbTd76hD63B lCF8fjp8cBp4XfqNFbvnvsfe/CQgfBZUO7DopfuhS27spZUM5+Zp/3SinRS+gp1hTNkB jEifbVjD5wAQTUZdb02JX/J9tEEzEJazzsXWVZee4do91I2qFAgji/Jxl7rba/E9JbKF QrTG0IEp7P6VZYl+w+irmi9iIxUaBobnvppxGk4ZOS884K5BfJC8LmJvW6UTVbeClZG9 yuTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=RYlCovkg; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=RYlCovkg; 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 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=suse.de X-Forwarded-Encrypted: i=1; AJvYcCWKTZF1aL4eg3FWrScJuFh7a3yHGxbQ2S72ILHgsfqcu5BDzJV2uK2kIo966CtlRcM9E3Gt/wR362GPmD1tu0KIx+OLEQ== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id r15-20020a05620a298f00b0078331069e2esi12637522qkp.555.2024.01.31.04.49.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 04:49:29 -0800 (PST) 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=@suse.de header.s=susede2_rsa header.b=RYlCovkg; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=RYlCovkg; 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 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=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 099743858C78 for ; Wed, 31 Jan 2024 12:49:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id EAFE93858D20 for ; Wed, 31 Jan 2024 12:48:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAFE93858D20 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 EAFE93858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706705321; cv=none; b=YSvKQwTPeJW8EAjlsYH/7/PPLH9crfl2UG9znS5Pzo7VUHRRGycIZxhvnaKtQLHNCFx0eOmROOycpQE2dlNVfd9QhHCR49DVW6R1t5yX2r7QIwblsow9oMTVTUwuoEcThgqkQEX7XrNA0clTMOi9hehISdY2xXZ6JfFxHOpmLL8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706705321; c=relaxed/simple; bh=sW3npU5+btkbBjgCPuRBWaAtivJM79j0pURZ/g785Do=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=FdsZNGWk71S8bPPw8tUZlb45gJl0CnTK5UfQ2mRr2MKvtXs6hw80QVOwEFsx/MJjnEmL7sTY6gUVtjrT+WsiFBVHY4QBH/ruKeDnfPNeEGrhKMnT71U0m84Z6YsVtNua2/YvJI+VEmVCPjgUL0tK+a3NP9T3gsWxuyqXxQQsUtY= 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-out2.suse.de (Postfix) with ESMTPS id B21261F37C for ; Wed, 31 Jan 2024 12:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706705318; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8LNZqBFV+1JSziN/EyMhPbKCazNECcNmKKch7nIXMHY=; b=RYlCovkgiu+/EvLzwwCOghS18TL8y1zpP63pzjUDJxyVxwyQY3ljPESI5aGV3Glyc0SQ8X Hd7pTlLDhPhgl3QCKXHNT5qqdx6HUVEHNtO9eaOARKP6chGQdLILv+Xp1uStLtSw9ZdKV6 BKw08PAN9lLzw2wlFJt5oXF+lY80T88= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706705318; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8LNZqBFV+1JSziN/EyMhPbKCazNECcNmKKch7nIXMHY=; b=2FtVbosx0cwJDgi2zju56DJ3bbweYOuOz5+dNXD/sU6N8F1s49iWfW/syYkhWD4C3S4061 MM+de6clakP5JaDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706705318; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8LNZqBFV+1JSziN/EyMhPbKCazNECcNmKKch7nIXMHY=; b=RYlCovkgiu+/EvLzwwCOghS18TL8y1zpP63pzjUDJxyVxwyQY3ljPESI5aGV3Glyc0SQ8X Hd7pTlLDhPhgl3QCKXHNT5qqdx6HUVEHNtO9eaOARKP6chGQdLILv+Xp1uStLtSw9ZdKV6 BKw08PAN9lLzw2wlFJt5oXF+lY80T88= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706705318; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8LNZqBFV+1JSziN/EyMhPbKCazNECcNmKKch7nIXMHY=; b=2FtVbosx0cwJDgi2zju56DJ3bbweYOuOz5+dNXD/sU6N8F1s49iWfW/syYkhWD4C3S4061 MM+de6clakP5JaDA== Date: Wed, 31 Jan 2024 13:43:00 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/111444 - avoid insertions when skipping defs MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 5.57 X-Spamd-Result: default: False [5.57 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(3.00)[1.000]; 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_LONG(3.17)[0.906]; 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.7 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: <20240131124929.099743858C78@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789610289525227472 X-GMAIL-MSGID: 1789610289525227472 The following avoids inserting expressions for IPA CP discovered equivalences into the VN hashtables when we are optimistically skipping may-defs in the attempt to prove it's redundant. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/111444 * tree-ssa-sccvn.cc (vn_reference_lookup_3): Do not use vn_reference_lookup_2 when optimistically skipping may-defs. * gcc.dg/torture/pr111444.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr111444.c | 26 +++++++++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 22 ++++++++++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr111444.c diff --git a/gcc/testsuite/gcc.dg/torture/pr111444.c b/gcc/testsuite/gcc.dg/torture/pr111444.c new file mode 100644 index 00000000000..e613f255803 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr111444.c @@ -0,0 +1,26 @@ +/* { dg-do run } */ + +int a = 3, d, e; +int *b = &a; +char c; +short f; +const int **g; +static long h(int **i, int **j) +{ + const int *k[46]; + const int **l = &k[5]; + *j = &e; + g = l; + for (; d; d = d + 1) + ; + **i = 0; + return f; +} +int main() +{ + int *m = &a; + h(&m, &m); + c = *b; + if (c != 3) + __builtin_abort (); +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index f0fa718a723..9bed9b3cc69 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -2790,25 +2790,29 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, } else { - tree *saved_last_vuse_ptr = data->last_vuse_ptr; - /* Do not update last_vuse_ptr in vn_reference_lookup_2. */ - data->last_vuse_ptr = NULL; tree saved_vuse = vr->vuse; hashval_t saved_hashcode = vr->hashcode; - void *res = vn_reference_lookup_2 (ref, gimple_vuse (def_stmt), - data); + if (vr->vuse) + vr->hashcode = vr->hashcode - SSA_NAME_VERSION (vr->vuse); + vr->vuse = vuse_ssa_val (gimple_vuse (def_stmt)); + if (vr->vuse) + vr->hashcode = vr->hashcode + SSA_NAME_VERSION (vr->vuse); + vn_reference_t vnresult = NULL; + /* Do not use vn_reference_lookup_2 since that might perform + expression hashtable insertion but this lookup crosses + a possible may-alias making such insertion conditionally + invalid. */ + vn_reference_lookup_1 (vr, &vnresult); /* Need to restore vr->vuse and vr->hashcode. */ vr->vuse = saved_vuse; vr->hashcode = saved_hashcode; - data->last_vuse_ptr = saved_last_vuse_ptr; - if (res && res != (void *)-1) + if (vnresult) { - vn_reference_t vnresult = (vn_reference_t) res; if (TREE_CODE (rhs) == SSA_NAME) rhs = SSA_VAL (rhs); if (vnresult->result && operand_equal_p (vnresult->result, rhs, 0)) - return res; + return vnresult; } } }