From patchwork Sun Jan 20 05:00:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 213910 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]) by ozlabs.org (Postfix) with SMTP id 69B4C2C0086 for ; Sun, 20 Jan 2013 16:01:20 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1359262881; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=ZRU3I2D eywgZYIsezEL0eK18X10=; b=bgP/8gq0BhxIeeluJOvWPV1ccgUirRL23P9+0nN mM3sgKVBtY89sPrfUHUCQjkQi2u9oLdlTHqGawPILEZfpNJi+f9UVzinWjjoRE/Z fgacKvFRLvMkTLHUZeMQmRfVP7xT8kIRRlf5ixovfcUintaza7+cOoU0xq2OzuhW SXy4= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=KSJRXEd9FghggZa4ikDJLd2/22MvvscumexS0MxoJ2EYcc+rYaPI7MzmxY5J19 WXH/Dq5Uw9hb2ap3Cre/n+VrrPWnuLUlNd45QxoudcsHtFIupuEgH/2lg8eByY4o xNdm8h14GduY7Oe0xcQGUH8HeI2xFr2gj3luWvdnIvmQg=; Received: (qmail 26841 invoked by alias); 20 Jan 2013 05:01:10 -0000 Received: (qmail 26827 invoked by uid 22791); 20 Jan 2013 05:01:09 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CV X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 20 Jan 2013 05:00:56 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0K50kGH031081 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 20 Jan 2013 00:00:55 -0500 Received: from stumpy.slc.redhat.com (ovpn-113-44.phx2.redhat.com [10.3.113.44]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0K50jXd026996 for ; Sun, 20 Jan 2013 00:00:46 -0500 Message-ID: <50FB79FD.3070605@redhat.com> Date: Sat, 19 Jan 2013 22:00:45 -0700 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: gcc-patches Subject: PR 52631 X-IsSubscribed: yes 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 PR 52631 is a missed-optimization regression where we fail to lookup a simplified expression when value numbering the ssa graph to see if the simplified expression already has a value number. Andrew Pinski had a patch that was 99% complete in the PR; Richard Biener suggested a relatively minor change. Specifically instead of using valid_gimple_rhs_p to explicitly check for the valid codes. I've made that trivial change, added Andrew's sample code to the testsuite and updated the expected output from one test that we optimize better during FRE. Bootstrapped and regression tested on x86_64-linux-gnu. Applied to the trunk. commit cb8cc8bfd2be2c7cd0b3906e28f0c5557b62379a Author: Jeff Law Date: Sat Jan 19 21:51:27 2013 -0700 PR tree-optimization/52631 * tree-ssa-sccvn (visit_use): Before looking up the original statement, try looking up the simplified expression. PR tree-optimization/52631 * tree-ssa/pr52631.c: New test. * tree-ssa/ssa-fre-9: Update expected output. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2c01942..528afa1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2013-01-19 Andrew Pinski + + PR tree-optimization/52631 + * tree-ssa-sccvn (visit_use): Before looking up the original + statement, try looking up the simplified expression. + 2013-01-19 Anthony Green * config/moxie/moxie.c (moxie_expand_prologue): Set diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d6a8f70..0d50296 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2013-01-19 Jeff Law + + PR tree-optimization/52631 + * tree-ssa/pr52631.c: New test. + * tree-ssa/ssa-fre-9: Update expected output. + 2013-01-19 Anthony Green * gcc.dg/tree-ssa/asm-2.c (REGISTER): Pick an appropriate register diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c b/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c new file mode 100644 index 0000000..c0d650b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr52631.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-fre1-details" } */ + +unsigned f(unsigned a) +{ + unsigned b = a >> 31; + return b&1; +} + +/* We want to verify that we replace the b & 1 with b. */ +/* { dg-final { scan-tree-dump-times "Replaced b_\[0-9\]+ & 1 with b_\[0-9\]+ in" 1 "fre1"} } */ + +/* { dg-final { cleanup-tree-dump "fre1" } } */ + diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-9.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-9.c index 57c6d4b..d3986f5 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-9.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-9.c @@ -23,6 +23,6 @@ void __frame_state_for1 (volatile char *state_in) } } -/* { dg-final { scan-tree-dump-times "Eliminated: 1" 2 "fre1" } } */ +/* { dg-final { scan-tree-dump-times "Eliminated: 2" 2 "fre1" } } */ /* { dg-final { scan-tree-dump-times "Insertions: 1" 2 "fre1" } } */ /* { dg-final { cleanup-tree-dump "fre1" } } */ diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 5794035..81a07ae 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -3422,6 +3422,28 @@ visit_use (tree use) } else { + /* First try to lookup the simplified expression. */ + if (simplified) + { + enum gimple_rhs_class rhs_class; + + + rhs_class = get_gimple_rhs_class (TREE_CODE (simplified)); + if ((rhs_class == GIMPLE_UNARY_RHS + || rhs_class == GIMPLE_BINARY_RHS + || rhs_class == GIMPLE_TERNARY_RHS) + && valid_gimple_rhs_p (simplified)) + { + tree result = vn_nary_op_lookup (simplified, NULL); + if (result) + { + changed = set_ssa_val_to (lhs, result); + goto done; + } + } + } + + /* Otherwise visit the original statement. */ switch (vn_get_stmt_kind (stmt)) { case VN_NARY: