From patchwork Wed Apr 15 07:53:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 461376 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 5DBEB14016A for ; Wed, 15 Apr 2015 17:53:58 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=QEpvAdze; dkim-adsp=none (unprotected policy); 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 :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=aPRgTSP1Dfk+qHF2y99VqKiLUWbIbu8tMWUNu1VvISAive g4LX6FAv1HKcCh9wQU4RQL6KXFnnKcBre/Te3EDFoSmE1y/70JXrgsuWvHbnockR F4lDgcvw56ZspqWhhcSv3gAAy/VLMow5eh/84DkQz8Hscmb5gpQUyq1P8yqx8= 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=2k8VhetMwXzpMIvWGsuENHY7nr8=; b=QEpvAdzen3qBMQAPMrlL /oyxVQtZFUz8U6WbILjliTC6Y8ilQFUIMagOME1eBQIQAA1SkqIBXw253aZf0vN6 EqOun/GoPmNtCXj7tM7A7caeTbPxYs+d56PYpdGeaMG4zrlaELVn2ESZBcqm+r59 p2eCEiozFnjesE9cGzidTgg= Received: (qmail 13954 invoked by alias); 15 Apr 2015 07:53:51 -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 13942 invoked by uid 89); 15 Apr 2015 07:53:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f170.google.com Received: from mail-pd0-f170.google.com (HELO mail-pd0-f170.google.com) (209.85.192.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 15 Apr 2015 07:53:49 +0000 Received: by pdea3 with SMTP id a3so43015804pde.3 for ; Wed, 15 Apr 2015 00:53:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:content-type; bh=/xNywB4xBM+88mqIGBwhKDDIkir/ypxuJZKdg9bygGY=; b=AbzSmpn7HkJ3mBeMZoOesx4p2EZWzbsxFWdrE/K6ql5sk4SNGHTf65/R5e3iD/HrUQ FL7A4FbNrGSbRZ5wueq2B4dq6OI2hNBkEurbxbUZGbBAKCvygiTnRFfuacVZKdv+s97t 1V8w4hx01iEf/0XkhUggsSEk9U5aX73YsBBBrpUI2pwr+8i/V0KhZ8PBBHkPQGtJwdbY ls6MEQ1iChmfQDu+WYPfq06EKn5cP2HrFw201kVoqb4yVzEMttMmYBR/QB/sp7SomB2s ZlMk3Gf4lBWjUI44DXHJUr6er7N30EsH74QMwUMpbOFOlaiIc0rx1sVI82DeXnGs4+5o AWPw== X-Gm-Message-State: ALoCoQlstS1+if+fY/mKYA8deo2gDFSBBzJFFKTBrIyw+LM/4A8jPrHPFi9tLLO4hO4wb5pZ+nG1 X-Received: by 10.68.253.162 with SMTP id ab2mr43914978pbd.62.1429084427429; Wed, 15 Apr 2015 00:53:47 -0700 (PDT) Received: from [10.1.1.5] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by mx.google.com with ESMTPSA id ox4sm3241718pdb.36.2015.04.15.00.53.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Apr 2015 00:53:46 -0700 (PDT) Message-ID: <552E1907.4090708@linaro.org> Date: Wed, 15 Apr 2015 17:53:43 +1000 From: Kugan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" Subject: [PR65768] Check rtx_cost when propagating constant X-IsSubscribed: yes As mentioned in PR65768, ARM gcc generates suboptimal code for constant Uses in loop. Part of the reason is cprop is undoing what loop invariant code motion did. Zhenqiang posted a patch at to fix this based on rtx costs: https://gcc.gnu.org/ml/gcc-patches/2014-06/msg01321.html I cleaned it up and bootstrapped, regression tested on x86_64-linux-gnu; no new regressions. Is this OK for trunk? Thanks, Kugan gcc/ChangeLog: 2015-04-15 Kugan Vivekanandarajah Zhenqiang Chen PR target/65768 * cprop.c (try_replace_reg): Check cost of constants before propagating. diff --git a/gcc/cprop.c b/gcc/cprop.c index c9fb2fc..42a2a72 100644 --- a/gcc/cprop.c +++ b/gcc/cprop.c @@ -758,12 +758,38 @@ try_replace_reg (rtx from, rtx to, rtx_insn *insn) int success = 0; rtx set = single_set (insn); + bool already_const_p = false; + bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn)); + int old_cost = set ? set_rtx_cost (set, speed) : 0; + + if ((note != 0 + && REG_NOTE_KIND (note) == REG_EQUAL + && (GET_CODE (XEXP (note, 0)) == CONST + || CONSTANT_P (XEXP (note, 0)))) + || (set && CONSTANT_P (SET_SRC (set)))) + already_const_p = true; + /* Usually we substitute easy stuff, so we won't copy everything. We however need to take care to not duplicate non-trivial CONST expressions. */ to = copy_rtx (to); validate_replace_src_group (from, to, insn); + + + /* For CONSTANT_P (to), loop2_invariant pass might hoist it out the loop. + And it can be shared by different references. So skip propagation if + it makes INSN's rtx cost higher. */ + + if (!already_const_p + && CONSTANT_P (to) + && (set_rtx_cost (set, speed) > old_cost)) + { + cancel_changes (0); + return false; + } + + if (num_changes_pending () && apply_change_group ()) success = 1;