From patchwork Thu Mar 16 03:18:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 739528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3vkDFv16YFz9ryk for ; Thu, 16 Mar 2017 14:18:42 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="h6GWQ/2/"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=AF5omL0uCNeuWcwgl //IB0UrwY1bACI3OoaOsZz2spuido9+C1CfeKBNIw70uNCq6X4hqkaMiuxXJjd9W rk4Ldi0i09m8qY8lrCeOzuYDk9YLETPfhPSKOPIxcsSviuHbJoAFe9ZiRsMFgq9E 3Q60DiyoTrN7z6AETznpFe0Be4= 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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=bdc4+sn73GTwwDkJf13OX+p h6Lo=; b=h6GWQ/2/YH/75Q7lbXhmNn08CD2ADlA4vd9Uzg3QaL8XMwxsa3ko3KO OHcUZNluQVEOs+oSw8lPOVjVKSa9CE96OvHmdBDPeB94d3Pdh6e7gePlPHJEBBNJ oazma4MKnxZ8iSJh+LOELIp7/1ISDlhm/2MxfD2QJEBDiUo90310= Received: (qmail 28348 invoked by alias); 16 Mar 2017 03:18:33 -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 28298 invoked by uid 89); 16 Mar 2017 03:18:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=H*M:4796 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Mar 2017 03:18:27 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6AA7F64D99 for ; Thu, 16 Mar 2017 03:18:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6AA7F64D99 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=law@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6AA7F64D99 Received: from localhost.localdomain (ovpn-116-108.phx2.redhat.com [10.3.116.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D5AC60E3F for ; Thu, 16 Mar 2017 03:18:28 +0000 (UTC) Subject: Re: [PATCH 2/5][P1][tree-optimization/71437] Record more equivalences in some cases To: gcc-patches References: From: Jeff Law Message-ID: Date: Wed, 15 Mar 2017 21:18:27 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes On 03/15/2017 09:17 PM, Jeff Law wrote: > > Patch #3 will remove handle_dominating_asserts from the core of the jump > threading code and push it into VRP's callbacks where it should always > have been. > > As a side effect it causes some code which was previously only used for > threading from VRP to be used unconditionally. It's actually a good > thing as that code will find more jump threads. But in one case the > resulting code is tougher for tree-ssa-uninit.c to handle and we get a > false positive uninit warning. > > As it turns out for that case we're better off improving DOM slightly > which allows DOM to simplify the test even further. This patch > implements the DOM improvement so that we don't see a regression when > patch #3 is installed. > > The particular case we're looking to improve looks like > > t = a | b; > if (t == 0) > ... > > In the TRUE arm we know that a must be zero and b must be zero. > Discovering those equivalences allows DOM to do a better job for the > uninit testcase from the testsuite. > > There's clearly more that could be done with this code, but I didn't > want to take it any further than was needed to address the regression > that would be caused by patch #3. > > Bootstrapped and regression tested on x86_64-linux-gnu. Installing on > the trunk. I'll be testing this in combination with patch #1 tomorrow > on ppc64le to get additional coverage. > > Jeff Whoops. This time with the patch. Jeff PR tree-optimization/71437 * tree-ssa-dom.c (derive_equivalences_from_bit_ior): New function. (record_temporary_equivalences): Use it. diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index ad71269..0ebe892 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -691,6 +691,33 @@ back_propagate_equivalences (tree lhs, edge e, BITMAP_FREE (domby); } +/* Record NAME has the value zero and if NAME was set from a BIT_IOR_EXPR + recurse into both operands recording their values as zero too. */ + +static void +derive_equivalencs_from_bit_ior (tree name, const_and_copies *const_and_copies) +{ + if (TREE_CODE (name) == SSA_NAME) + { + tree value = fold_convert (TREE_TYPE (name), integer_zero_node); + + /* This records the equivalence for the toplevel object. */ + record_equality (name, value, const_and_copies); + + /* And we can recurse into each operand to potentially find more + equivalences. */ + gimple *def_stmt = SSA_NAME_DEF_STMT (name); + if (is_gimple_assign (def_stmt) + && gimple_assign_rhs_code (def_stmt) == BIT_IOR_EXPR) + { + derive_equivalencs_from_bit_ior (gimple_assign_rhs1 (def_stmt), + const_and_copies); + derive_equivalencs_from_bit_ior (gimple_assign_rhs2 (def_stmt), + const_and_copies); + } + } +} + /* Record into CONST_AND_COPIES and AVAIL_EXPRS_STACK any equivalences implied by traversing edge E (which are cached in E->aux). @@ -711,7 +738,28 @@ record_temporary_equivalences (edge e, /* If we have 0 = COND or 1 = COND equivalences, record them into our expression hash tables. */ for (i = 0; edge_info->cond_equivalences.iterate (i, &eq); ++i) - avail_exprs_stack->record_cond (eq); + { + avail_exprs_stack->record_cond (eq); + + /* If the condition is testing that X == 0 is true or X != 0 is false + and X is set from a BIT_IOR_EXPR, then we can record equivalences + for the operands of the BIT_IOR_EXPR (and recurse on those). */ + tree op0 = eq->cond.ops.binary.opnd0; + tree op1 = eq->cond.ops.binary.opnd1; + if (TREE_CODE (op0) == SSA_NAME && integer_zerop (op1)) + { + enum tree_code code = eq->cond.ops.binary.op; + if ((code == EQ_EXPR && eq->value == boolean_true_node) + || (code == NE_EXPR && eq->value == boolean_false_node)) + derive_equivalencs_from_bit_ior (op0, const_and_copies); + + /* TODO: We could handle BIT_AND_EXPR in a similar fashion + recording that the operands have a nonzero value. */ + + /* TODO: We can handle more cases here, particularly when OP0 is + known to have a boolean range. */ + } + } tree lhs = edge_info->lhs; if (!lhs || TREE_CODE (lhs) != SSA_NAME)