From patchwork Tue Jan 21 11:52:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1226409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-517871-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=hxU6pYNX; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4826NX5mGvz9sRG for ; Tue, 21 Jan 2020 22:52:42 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=YlNgKZfr6ZulplXmmWSCm2zCYg2f1FoHlVVnu9vqlD+Z5gbyCLoOS z8bRDCFvnJ41exgduJk32lxOJOCMhHOP1/nWyRh4/jRbUq8o7fyTZUmHe6wuMAhl u+ozGEWjbB/YSt4OO8SjF0fmXf98iia1B4L8TcJcNEX//C1kymJD54= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=R9t88agX/zL6RT0u9xiPhGQwDLM=; b=hxU6pYNX417sa3l/aR0R 10mI1pnqHPncd++aA3Zij1oNjPpQHfXRxbSgS5y779C9LeOaVaOupdPom5JUk0rM 8m0SqaWcj0dEO3wcOdQlKwCkFlddkAchtRY8D16T8kapYfjz33p5KKQM8B4t+jLt h14u9POeGKXUTpTqrPJHHL8= Received: (qmail 10768 invoked by alias); 21 Jan 2020 11:52:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 10755 invoked by uid 89); 21 Jan 2020 11:52:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=U*rguenther, rguenthersusede, rguenther@suse.de, sk:rguenth X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Jan 2020 11:52:24 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 28F65AE8A for ; Tue, 21 Jan 2020 11:52:22 +0000 (UTC) Date: Tue, 21 Jan 2020 12:52:22 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/92328 fix value-number with bogus type Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 We were actually value-numbering two entities with different type the same rather than just having the same representation in the hashtable. The following fixes that by wrapping the value in a to be inserted VIEW_CONVERT_EXPR. Bootstrapped & tested on x86_64-unknown-linux-gnu, pushed. Richard. 2020-01-21 Richard Biener PR tree-optimization/92328 * tree-ssa-sccvn.c (vn_reference_lookup_3): Preserve type when value-numbering same-sized store by inserting a VIEW_CONVERT_EXPR. (eliminate_dom_walker::eliminate_stmt): When eliminating a redundant store handle bit-reinterpretation of the same value. * gcc.dg/torture/pr92328.c: New testcase. diff --git a/gcc/testsuite/gcc.dg/torture/pr92328.c b/gcc/testsuite/gcc.dg/torture/pr92328.c new file mode 100644 index 00000000000..7898b9efe80 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr92328.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ftree-pre -Wno-div-by-zero" } */ + +int nt; + +void +ja (int os) +{ + int *ku = &os, *id = &os; + unsigned int qr = 0; + + for (;;) + { + if (os == *ku) + { + *id = 0; + qr += os != *ku; + id = &qr; + } + + *id &= qr; + + if (os != 0) + { + nt /= 0; + ku = &qr; + } + } +} diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 4d1301593d7..0b8ee586139 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -2712,26 +2712,30 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_, || known_eq (ref->size, TYPE_PRECISION (vr->type))) && multiple_p (ref->size, BITS_PER_UNIT)) { - if (known_eq (ref->size, size2)) - return vn_reference_lookup_or_insert_for_pieces - (vuse, get_alias_set (lhs), vr->type, vr->operands, - SSA_VAL (def_rhs)); - else if (! INTEGRAL_TYPE_P (TREE_TYPE (def_rhs)) - || type_has_mode_precision_p (TREE_TYPE (def_rhs))) + tree val = NULL_TREE; + if (! INTEGRAL_TYPE_P (TREE_TYPE (def_rhs)) + || type_has_mode_precision_p (TREE_TYPE (def_rhs))) { gimple_match_op op (gimple_match_cond::UNCOND, BIT_FIELD_REF, vr->type, SSA_VAL (def_rhs), bitsize_int (ref->size), bitsize_int (offset - offset2)); - tree val = vn_nary_build_or_lookup (&op); - if (val - && (TREE_CODE (val) != SSA_NAME - || ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val))) - return vn_reference_lookup_or_insert_for_pieces - (vuse, get_alias_set (lhs), vr->type, - vr->operands, val); + val = vn_nary_build_or_lookup (&op); } + else if (known_eq (ref->size, size2)) + { + gimple_match_op op (gimple_match_cond::UNCOND, + VIEW_CONVERT_EXPR, vr->type, + SSA_VAL (def_rhs)); + val = vn_nary_build_or_lookup (&op); + } + if (val + && (TREE_CODE (val) != SSA_NAME + || ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val))) + return vn_reference_lookup_or_insert_for_pieces + (vuse, get_alias_set (lhs), vr->type, + vr->operands, val); } else if (maxsize.is_constant (&maxsizei) && maxsizei % BITS_PER_UNIT == 0 @@ -5599,7 +5603,6 @@ eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi) && (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME || is_gimple_min_invariant (gimple_assign_rhs1 (stmt)))) { - tree val; tree rhs = gimple_assign_rhs1 (stmt); vn_reference_t vnresult; /* ??? gcc.dg/torture/pr91445.c shows that we lookup a boolean @@ -5640,14 +5643,22 @@ eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi) else lookup_lhs = NULL_TREE; } - val = NULL_TREE; + tree val = NULL_TREE; if (lookup_lhs) val = vn_reference_lookup (lookup_lhs, gimple_vuse (stmt), VN_WALK, &vnresult, false); if (TREE_CODE (rhs) == SSA_NAME) rhs = VN_INFO (rhs)->valnum; if (val - && operand_equal_p (val, rhs, 0)) + && (operand_equal_p (val, rhs, 0) + /* Due to the bitfield lookups above we can get bit + interpretations of the same RHS as values here. Those + are redundant as well. */ + || (TREE_CODE (val) == SSA_NAME + && gimple_assign_single_p (SSA_NAME_DEF_STMT (val)) + && (val = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (val))) + && TREE_CODE (val) == VIEW_CONVERT_EXPR + && TREE_OPERAND (val, 0) == rhs))) { /* We can only remove the later store if the former aliases at least all accesses the later one does or if the store