From patchwork Thu Nov 9 10:50:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 163346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b129:0:b0:403:3b70:6f57 with SMTP id q9csp348999vqs; Thu, 9 Nov 2023 02:51:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVC0BSBcO3IT03pS+A9lx9cp6IS1j3r9ICYzMZ+YRmPQArnJsVSs51nSRDW6L2xBhok1Te X-Received: by 2002:a05:6214:2304:b0:66d:4bfe:ad33 with SMTP id gc4-20020a056214230400b0066d4bfead33mr4553568qvb.33.1699527074436; Thu, 09 Nov 2023 02:51:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699527074; cv=pass; d=google.com; s=arc-20160816; b=tzzOL4ukMeVxifrzymv+Jo66E2HLixk1jMDc7nfptBR7eVizhhbtEf3/Xq95f0DXOD E1QtkAAXk6EUmJS+BfOMtcrGioSKFKf13jf6SMOi4O9aXmSQLtAsa9+2VsD52E+2Ykex qab2mzO9DlNWu+BJ6dMuY8dHPqcHBFYlrnyNcchzgya6CRqisSkUqzLv753XqPsZ7U3O 6bcF1pnJSB2hT2bN8SZk5d5EHlZy3hpX1LUFXYwIIx3j6CTHICzqNqgAZC305fwvvfks xN3ZZT69zVaiX/9FGEvyWTJbP1joG3f+vXtCq8pZmPeHST1U8FKgTnA9gHQ6PE7DmcBl dN/g== 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:dkim-signature:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=4b09DNrK8zP6gVmjkt0DJlcA+BlXde/y3EhX7uejtYw=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=e9VEQNQr4P6nYl4Z2NviMxP3CqUos0WtylvuChpIf93/tdkVXXkYHTYnJWQpCKdWgG SuY8Zf451fN8+WhUnhR9Mh2DmG7jPjxVe49UixuFMURxXaaceJZOQmxUf8x2rj/9kfJv U9ArDKadBey1tXOev7K2L8OBI9Ef7bc6c+Wz/k9B/RNcMTpFUh0VXKexDqp98eX57a5v bmcXXWLHdll9BLja98T3cpyZlRONvE7VjXABwGUlES18riJE4eRBwcORvgKjmwuXj32E b8LN1OfWowreCKWGP8YbDoFTEEsRYZiKENKtK1GzRBgCIv+MKwjvLr0zyKoeQkFyYgFo SUFQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=FNpq3dje; dkim=neutral (no key) header.i=@suse.de; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ev13-20020a0562140a8d00b0066485804976si2589182qvb.115.2023.11.09.02.51.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Nov 2023 02:51:14 -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=FNpq3dje; dkim=neutral (no key) header.i=@suse.de; 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 3A7EC385B800 for ; Thu, 9 Nov 2023 10:51:14 +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 282D33858D33 for ; Thu, 9 Nov 2023 10:50:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 282D33858D33 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 282D33858D33 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=1699527051; cv=none; b=BX2zO+F/6+hcZGty+iK1hgv+kbLYqICOiUm/EwvQ15O+5X+NFpylmpVz5zRkXxb4GRc1bCD3pRBn6XnexkmQq1bR0uUVNJOgwksVCHmT4T7SKHz1f+RH9/IBjSX4A8Arx1O4pzSNLKpnSzFlvFPL+u1Zad96V6aL37RU54Sj+jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699527051; c=relaxed/simple; bh=SmM1ulpkwNjJR3COzlg+v4kg9QlvTdgCjjo2qEVanak=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version; b=RPdGiaBZk65llkRzrms1LCdoIKXpEDy2wAXZHg7aFVHWxMvkpxt06PZ9gwZS9MLTciaDCDKA0vwd17quNMWbkVQQzHuwnqWrQgRIDsWq+l14UJsNkubKliRsoogF7UlV+kZD2GNzu9R6nZqEbB0JFDoI9iMH3XjxY0+1n8xPfMo= 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 414C021985 for ; Thu, 9 Nov 2023 10:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1699527048; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=4b09DNrK8zP6gVmjkt0DJlcA+BlXde/y3EhX7uejtYw=; b=FNpq3djeQEtmImvVSpwIr+QQczoIBBOh+/4oDEoBR/R7T8slmBpqYlsWLK6BkPQMEL2Xm4 7agrdGI62/5CfXMJmOQ35WuC0nvj3HmcyFghKJiII01FuiDuSos3whmCTXgyz0ONmp7evf nfn6sLunLWbQkT37CmdBfJq2znRj+Pc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1699527048; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=4b09DNrK8zP6gVmjkt0DJlcA+BlXde/y3EhX7uejtYw=; b=iPWhwxl4ezvGK2bcNVpmumJwMr1UIFprZxa4HHuo57zbExIH9eaqRLbIQJg/kJ2Ms4Vmmt C3ISFJFR/aXWldBg== 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 161B32C867 for ; Thu, 9 Nov 2023 10:50:48 +0000 (UTC) Date: Thu, 9 Nov 2023 10:50:48 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/112444 - avoid bougs PHI value-numbering User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 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: <20231109105114.3A7EC385B800@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782083301855590178 X-GMAIL-MSGID: 1782083301855590178 With .DEFERRED_INIT ssa_undefined_value_p () can return true for values we did not visit (because they proved unreachable) but are not .VN_TOP. Avoid using those as value which, because they are not visited, are assumed to be defined outside of the region. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/112444 * tree-ssa-sccvn.cc (visit_phi): Avoid using not visited defs as undefined vals. * gcc.dg/torture/pr112444.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr112444.c | 65 +++++++++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 16 +++++- 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr112444.c diff --git a/gcc/testsuite/gcc.dg/torture/pr112444.c b/gcc/testsuite/gcc.dg/torture/pr112444.c new file mode 100644 index 00000000000..61c7ec9b22e --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112444.c @@ -0,0 +1,65 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ftrivial-auto-var-init=zero" } */ + +int qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_offset, + qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_init_offset, + qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_error, + qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_phonebooks_i; + +int g_string_new(), g_string_append_len(), qmi_message_tlv_read_guint8(); + +void qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message() { + int printable = g_string_new(); + for (;;) { + { + if (__builtin_expect(({ + int _g_boolean_var_4; + if (printable) + _g_boolean_var_4 = 1; + else + _g_boolean_var_4 = 0; + _g_boolean_var_4; + }), + 0)) + g_string_append_len(); + } + unsigned char tmp; + qmi_message_tlv_read_guint8( + qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_init_offset, + qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_offset, + tmp, + qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_error); + { + { + if (__builtin_expect(({ + int _g_boolean_var_4; + if (printable) + _g_boolean_var_4 = 1; + else + _g_boolean_var_4 = 0; + _g_boolean_var_4; + }), + 0)) + g_string_append_len(); + } + } + for ( + ; + qmi_message_pbm_get_all_capabilities_output_capability_basic_information_get_printable_message_phonebooks_i;) { + unsigned char tmp; + qmi_message_tlv_read_guint8(&tmp); + { + if (__builtin_expect(({ + int _g_boolean_var_4; + if (printable) + _g_boolean_var_4 = 1; + else + _g_boolean_var_4 = 0; + _g_boolean_var_4; + }), + 0)) + g_string_append_len(); + } + } + } +} diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 0b2c10dcc1a..11537fa3e0b 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -5911,6 +5911,7 @@ static bool visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) { tree result, sameval = VN_TOP, seen_undef = NULL_TREE; + bool seen_undef_visited = false; tree backedge_val = NULL_TREE; bool seen_non_backedge = false; tree sameval_base = NULL_TREE; @@ -5941,10 +5942,12 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) if (def == PHI_RESULT (phi)) continue; ++n_executable; + bool visited = true; if (TREE_CODE (def) == SSA_NAME) { + tree val = SSA_VAL (def, &visited); if (!backedges_varying_p || !(e->flags & EDGE_DFS_BACK)) - def = SSA_VAL (def); + def = val; if (e->flags & EDGE_DFS_BACK) backedge_val = def; } @@ -5956,7 +5959,16 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p) else if (TREE_CODE (def) == SSA_NAME && ! virtual_operand_p (def) && ssa_undefined_value_p (def, false)) - seen_undef = def; + { + if (!seen_undef + /* Avoid having not visited undefined defs if we also have + a visited one. */ + || (!seen_undef_visited && visited)) + { + seen_undef = def; + seen_undef_visited = visited; + } + } else if (sameval == VN_TOP) { sameval = def;