From patchwork Thu Jun 5 12:22:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Bruel X-Patchwork-Id: 356338 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 998F0140080 for ; Thu, 5 Jun 2014 22:22:35 +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=WZgUd6SqT2dguMRDIGdbvX6uRs9sjMfufb9LGHfEmTIEpT +0GQ2Iwu2rMsFQD4ANZQtfOX38SvKd4pzJqwSzoRY5Amkrf2sK95JT59OXAisALK omMdGWSm9OG06wuW7RZbxNG4+hni68A5+pB1S4X6Mh5KiiI+RDxx5xa6OE7JM= 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=HD6RujbGhnTb52Vcnph74q8SRwU=; b=R1yvjo0VvpwYuC7DARQU lFWhFvO1s/gSUPhzEG6nvHQS4T1EcpEBRzxqeTycTfxYdwEuLdGviAyar6EkTHUp xIUiFdOM5p9iy9FRI/tvWoPO/1hK+WRlS1KUsmH1mupji9fWXcl4dbyHfyODEgua pJsVKZo+oYIuUnYqZnd/Ii4= Received: (qmail 1203 invoked by alias); 5 Jun 2014 12:22:26 -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 1088 invoked by uid 89); 5 Jun 2014 12:22:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-HELO: mx07-00178001.pphosted.com Received: from mx07-00178001.pphosted.com (HELO mx07-00178001.pphosted.com) (62.209.51.94) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 05 Jun 2014 12:22:23 +0000 Received: from pps.filterd (m0046670.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.14.5/8.14.5) with SMTP id s55CKs5B008217; Thu, 5 Jun 2014 14:22:19 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 1mack0bjjh-1 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Thu, 05 Jun 2014 14:22:19 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7C49859; Thu, 5 Jun 2014 12:22:08 +0000 (GMT) Received: from Webmail-eu.st.com (safex1hubcas5.st.com [10.75.90.71]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2DD87599F4; Thu, 5 Jun 2014 12:22:08 +0000 (GMT) Received: from [164.129.122.166] (164.129.122.166) by webmail-eu.st.com (10.75.90.13) with Microsoft SMTP Server (TLS) id 8.3.298.1; Thu, 5 Jun 2014 14:22:07 +0200 Message-ID: <539060EF.1060902@st.com> Date: Thu, 5 Jun 2014 14:22:07 +0200 From: Christian Bruel User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" , Richard Guenther Subject: [PATCH, tree-ssa] Optimize loop invariant phi defs constants X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.12.52, 1.0.14, 0.0.0000 definitions=2014-06-05_04:2014-06-05, 2014-06-05, 1970-01-01 signatures=0 X-IsSubscribed: yes Hello, while checking why a loop snippet like for (i = 0; i <= 5000; i++) if (b) a = 2; else a = x; was not optimized in -O2 (unless loop unrolling or loop switching), I found out that the case was already partially handled by Richard in PR43934. So this patch just adds a cost to the phi defs constants to allow the whole test to be hoisted out of the loop. Richard, does this seem reasonable and OK for 4.10 ? bootstrapped/regtested for x86 many thanks Christian 2014-06-03 Christian Bruel PR tree-optimization/43934 * tree-ssa-loop-im.c (determine_max_movement): Add PHI def constant cost. 2014-06-03 Christian Bruel PR tree-optimization/43934 * gcc.dg/tree-ssa/ssa-lim-8.c: New testcase. Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-8.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-8.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-8.c (working copy) @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-lim1-details" } */ + +void bar (int); +void foo (int n, int m) +{ + unsigned i; + for (i = 0; i < n; ++i) + { + int x; + if (m < 0) + x = 1; + else + x = m; + bar (x); + } +} + +/* { dg-final { scan-tree-dump-times "Moving PHI node" 1 "lim1" } } */ +/* { dg-final { cleanup-tree-dump "lim1" } } */ Index: gcc/tree-ssa-loop-im.c =================================================================== --- gcc/tree-ssa-loop-im.c (revision 211255) +++ gcc/tree-ssa-loop-im.c (working copy) @@ -719,8 +719,21 @@ determine_max_movement (gimple stmt, bool must_pre FOR_EACH_PHI_ARG (use_p, stmt, iter, SSA_OP_USE) { val = USE_FROM_PTR (use_p); + if (TREE_CODE (val) != SSA_NAME) - continue; + { + unsigned cst_cost = 1; + + gcc_assert (TREE_CODE (val) == INTEGER_CST + || TREE_CODE (val) == REAL_CST + || TREE_CODE (val) == VECTOR_CST + || TREE_CODE (val) == COMPLEX_CST + || TREE_CODE (val) == ADDR_EXPR); + + min_cost = MIN (min_cost, cst_cost); + total_cost += cst_cost; + continue; + } if (!add_dependency (val, lim_data, loop, false)) return false; def_data = get_lim_data (SSA_NAME_DEF_STMT (val));