From patchwork Mon Feb 28 09:34:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1598573 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=yMnjmBGd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4K6ZwL2pVlz9sGV for ; Mon, 28 Feb 2022 20:34:42 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 36FF13858003 for ; Mon, 28 Feb 2022 09:34:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36FF13858003 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1646040880; bh=vvSGVutEgoEokiz+6Dug1zv/CchhJj/6h1tp0AuVJ70=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yMnjmBGd2JxeZGEHExjaZVRAsMrq7h+h2n0cZf9pA6H40X+MW7xbzj2d4omaP7+Jk uJTrEsypaEEA31aF1nyy/Em+4w/I92qt3B91N0d9U9ZDQn4wsOU0Hri4ltQ0Pb8C9T BQEMdpOT1/4MFsNqkPAdQ9qKFeGUPj5wKH9g6jeI= 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 [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 2F4293858C3A for ; Mon, 28 Feb 2022 09:34:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F4293858C3A Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 30AF91F3AA for ; Mon, 28 Feb 2022 09:34:19 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1D92213AA8 for ; Mon, 28 Feb 2022 09:34:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KBL/BRuXHGKBWAAAMHmgww (envelope-from ) for ; Mon, 28 Feb 2022 09:34:19 +0000 Date: Mon, 28 Feb 2022 10:34:18 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/104700 - adjust constant handling in PRE MIME-Version: 1.0 Message-Id: <20220228093419.1D92213AA8@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The following refactors find_or_generate_expression to more properly handle constant valued SSA names thereby simplifying the code and avoiding ICEing after the last change to NARY processing. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2022-02-28 Richard Biener PR tree-optimization/104700 * tree-ssa-pre.cc (get_or_alloc_expr_for): Remove and inline into ... (find_or_generate_expression): ... here, simplifying code. * gcc.dg/pr104700-2.c: New testcase. * gcc.dg/torture/pr104700-1.c: Likewise. --- gcc/testsuite/gcc.dg/pr104700-2.c | 21 +++++++++++++ gcc/testsuite/gcc.dg/torture/pr104700-1.c | 38 +++++++++++++++++++++++ gcc/tree-ssa-pre.cc | 26 +++++++--------- 3 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr104700-2.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr104700-1.c diff --git a/gcc/testsuite/gcc.dg/pr104700-2.c b/gcc/testsuite/gcc.dg/pr104700-2.c new file mode 100644 index 00000000000..e0759cca70f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr104700-2.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-ccp -fno-tree-dce -fno-tree-vrp" } */ + +int a, b; +int main() { + int c = 2, d, e = 0; + if (a) + e = 2; + int f, g = -(1L | (e && f && f & e)); + if (g) + L: + g = c; + c = 0; + d = e * g; + if (d) + goto L; + while (e) { + int i = (a && b) * i; + } + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr104700-1.c b/gcc/testsuite/gcc.dg/torture/pr104700-1.c new file mode 100644 index 00000000000..7b864d6628b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr104700-1.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ftree-pre" } */ + +int printf(const char *, ...); +int a, b, c = 2, d, e, *f, g; +void o() { + unsigned h = 1; + int j = -1, k, l = 1, m = 2, i; + while (c < 2) + ; +L1: + k = h; + h = -1; + if (k < 2 && !c) { + printf("%d", k); + goto L1; + } + if (!j) + l = printf("0"); + if (g) + k = 0; + if (a && k) + goto L2; + while (f) { + m = a; + d = i; + i = e; + f = &j; + L2: + if (d == l && !m) + l = b; + } + unsigned *n[1] = {&h}; +} +int main() { + o(); + return 0; +} diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc index d6c83a72dd8..ca034ff7153 100644 --- a/gcc/tree-ssa-pre.cc +++ b/gcc/tree-ssa-pre.cc @@ -1197,18 +1197,6 @@ get_or_alloc_expr_for_constant (tree constant) return newexpr; } -/* Get or allocate a pre_expr for a piece of GIMPLE, and return it. - Currently only supports constants and SSA_NAMES. */ -static pre_expr -get_or_alloc_expr_for (tree t) -{ - if (TREE_CODE (t) == SSA_NAME) - return get_or_alloc_expr_for_name (t); - else if (is_gimple_min_invariant (t)) - return get_or_alloc_expr_for_constant (t); - gcc_unreachable (); -} - /* Return the folded version of T if T, when folded, is a gimple min_invariant or an SSA name. Otherwise, return T. */ @@ -2779,8 +2767,16 @@ create_component_ref_by_pieces (basic_block block, vn_reference_t ref, static tree find_or_generate_expression (basic_block block, tree op, gimple_seq *stmts) { - pre_expr expr = get_or_alloc_expr_for (op); - unsigned int lookfor = get_expr_value_id (expr); + /* Constants are always leaders. */ + if (is_gimple_min_invariant (op)) + return op; + + gcc_assert (TREE_CODE (op) == SSA_NAME); + vn_ssa_aux_t info = VN_INFO (op); + unsigned int lookfor = info->value_id; + if (value_id_constant_p (lookfor)) + return info->valnum; + pre_expr leader = bitmap_find_leader (AVAIL_OUT (block), lookfor); if (leader) { @@ -2808,7 +2804,7 @@ find_or_generate_expression (basic_block block, tree op, gimple_seq *stmts) its operand values. */ if (temp->kind == NARY) return create_expression_by_pieces (block, temp, stmts, - get_expr_type (expr)); + TREE_TYPE (op)); } /* Defer. */