From patchwork Mon Jun 30 06:56:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 365490 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 316F01400EE for ; Mon, 30 Jun 2014 16:56:24 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=sED+S91lTiWLdWirNCHON1kDxoh6G2tjDjhnUgKG1kq+lc 4hmdxt1Li0s8GMoLoaqaWqjzVtp8Kwz/txago/Ghj8Un8k8+dcWa/cxOpKFeIMNd zDgAbhpWveeUfuVBNkwqgiF20zuLjkwTXgXe+pnEh3pChrpX5ztl41xneBf6w= 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 :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=8E5SAVyfzu0sEHlk+fTZMElq9Uo=; b=DDZL4ZI3phyUXYrKZ03D F5krwpuF7DNHmXGIDCh2nX7s/pFz63lHPKqwysia3AaLM39c10d/ZZ3/xdqBlFdW uJsOoLcP5Lqft/1a0ypeMdkSjXN7MeZpybRRi+e3MvLXxpYSq2l79JOlUZo89n1U rBKUtxQnOVT85fMCf3hejMU= Received: (qmail 6279 invoked by alias); 30 Jun 2014 06:56:17 -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 6208 invoked by uid 89); 30 Jun 2014 06:56:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 30 Jun 2014 06:56:10 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5U6u9Iu019389 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 30 Jun 2014 02:56:09 -0400 Received: from stumpy.slc.redhat.com (ovpn-113-44.phx2.redhat.com [10.3.113.44]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5U6u83Y020784 for ; Mon, 30 Jun 2014 02:56:08 -0400 Message-ID: <53B10A08.4000306@redhat.com> Date: Mon, 30 Jun 2014 00:56:08 -0600 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: gcc-patches Subject: [tree-optimization/61607] Look through SSA_NAME_VALUE chains X-IsSubscribed: yes SSA_NAME_VALUE is, in effect, a chain of values. ie, it's possible for SSA_NAME_VALUE of any given SSA_NAME to refer to another SSA_NAME. In many cases it is advantageous to look deeper into those chains, particularly when simplifying conditionals for jump threading. The problem with simply following the chains, is they can have loops. This can occur when we're threading across a loop backedge. I did some fairly simple experiments which showed that chains of 0, or 1 element are by far the most common. chains of 2 elements are rare, but do occur in practice (such as pr61607). Chains of > 2 elements consistently have loops. So this patch just looks up to two elements deep in the chain and avoids the complication of explicitly looking for loops. This allows us to pick up the obvious equivalency in pr61607 and gets the jumps outside the loop fully threaded. Bootstrapped and regression tested on x86_64-unknown-linux-gnu. Installed on the trunk. commit 3e2754da946eb64d7a1d30548c9b6119cda3a014 Author: Jeff Law Date: Sun Jun 29 23:35:50 2014 -0600 tree-optimization/61607 * tree-ssa-threadedge.c (simplify_control_stmt_condition): Look deeper into the SSA_NAME_VALUE chain. tree-optimization/61607 * gcc.dg/tree-ssa/pr61607.c: New test. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4cc167a..6dfe1d3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-06-30 Jeff Law + + tree-optimization/61607 + * tree-ssa-threadedge.c (simplify_control_stmt_condition): Look + deeper into the SSA_NAME_VALUE chain. + 2014-06-30 Zhenqiang Chen * loop-invariant.c (get_inv_cost): Handle register class. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5a9d73a..1df9d4e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-06-30 Jeff Law + + tree-optimization/61607 + * gcc.dg/tree-ssa/pr61607.c: New test. + 2014-06-30 Zhenqiang Chen * ira-loop-pressure.c: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr61607.c b/gcc/testsuite/gcc.dg/tree-ssa/pr61607.c new file mode 100644 index 0000000..ec00f51 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr61607.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-Os -fno-tree-fre -fdump-tree-dom1" } */ + +void foo(int *); +void f2(int dst[3], int R) +{ + int i, inter[2]; + _Bool inter0p = 0; + _Bool inter1p = 0; + for (i = 1; i < R; i++) + { + inter0p = 1; + inter1p = 1; + } + if (inter0p) + inter[0] = 1; + if (inter1p) + inter[1] = 1; + foo(inter); +} + + +/* There should be precisely two conditionals. One for the loop condition + and one for the test after the loop. Previously we failed to eliminate + the second conditional after the loop. */ +/* { dg-final { scan-tree-dump-times "if" 2 "dom1"} } */ + +/* { dg-final { cleanup-tree-dump "dom1" } } */ + diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c index a76a7ce..9807b42 100644 --- a/gcc/tree-ssa-threadedge.c +++ b/gcc/tree-ssa-threadedge.c @@ -542,16 +542,26 @@ simplify_control_stmt_condition (edge e, /* Get the current value of both operands. */ if (TREE_CODE (op0) == SSA_NAME) { - tree tmp = SSA_NAME_VALUE (op0); - if (tmp) - op0 = tmp; + for (int i = 0; i < 2; i++) + { + if (TREE_CODE (op0) == SSA_NAME + && SSA_NAME_VALUE (op0)) + op0 = SSA_NAME_VALUE (op0); + else + break; + } } if (TREE_CODE (op1) == SSA_NAME) { - tree tmp = SSA_NAME_VALUE (op1); - if (tmp) - op1 = tmp; + for (int i = 0; i < 2; i++) + { + if (TREE_CODE (op1) == SSA_NAME + && SSA_NAME_VALUE (op1)) + op1 = SSA_NAME_VALUE (op1); + else + break; + } } if (handle_dominating_asserts) @@ -625,10 +635,17 @@ simplify_control_stmt_condition (edge e, It is possible to get loops in the SSA_NAME_VALUE chains (consider threading the backedge of a loop where we have a loop invariant SSA_NAME used in the condition. */ - if (cached_lhs - && TREE_CODE (cached_lhs) == SSA_NAME - && SSA_NAME_VALUE (cached_lhs)) - cached_lhs = SSA_NAME_VALUE (cached_lhs); + if (cached_lhs) + { + for (int i = 0; i < 2; i++) + { + if (TREE_CODE (cached_lhs) == SSA_NAME + && SSA_NAME_VALUE (cached_lhs)) + cached_lhs = SSA_NAME_VALUE (cached_lhs); + else + break; + } + } /* If we're dominated by a suitable ASSERT_EXPR, then update CACHED_LHS appropriately. */