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: 47162 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F1C0B2121F for ; Wed, 15 Apr 2015 07:54:08 +0000 (UTC) Received: by lbcne10 with SMTP id ne10sf7552880lbc.1 for ; Wed, 15 Apr 2015 00:54:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:message-id:date:from:user-agent:mime-version:to :subject:content-type:x-original-sender :x-original-authentication-results; bh=pN8ZjvszIofWGOKNTFdzHmSO9QkgX2iiqbpee5olOp4=; b=HQBRw+kKdBAJK/OkP8nubAVulAenJjTEadehn51MwW6+Ju8P+5BtqVBjC4UoRyp16f DEWCkIcnVgeb+9+3diV6CAXIloqHDf0aNd+IUSHTuhVkDBf4GioxmyPoOqJ2h3rg9D6K JvHuy67ibQA6qW3vpnNM/4/HhXdTnSYYKBVjZeutEGk9du0e1VyMmQ4MSjtvcQBQrdjX mxi88JHqfbfPe5Kezsnz0UXeryM8NJwEYHSUX5+1SMQNHHCEJdZFLbA9l9KPgoo8tnZF F4Na7v46h3gyLBhuz5V7cZ10nZkj1L0JzPJxxTtCBhI2wfay26Di8UCPLyDqXG+Jmgs9 RVPA== X-Gm-Message-State: ALoCoQlc8MAWm8NHc+RfNVP2faJX2J9hfWN69VCTx8ymHCKlnjmFdkDJd9kOW0oZwGQP/dnDR0SA X-Received: by 10.152.163.99 with SMTP id yh3mr4676293lab.8.1429084447906; Wed, 15 Apr 2015 00:54:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.74 with SMTP id j10ls159470lag.7.gmail; Wed, 15 Apr 2015 00:54:07 -0700 (PDT) X-Received: by 10.152.205.106 with SMTP id lf10mr22370028lac.89.1429084447758; Wed, 15 Apr 2015 00:54:07 -0700 (PDT) Received: from mail-la0-x234.google.com (mail-la0-x234.google.com. [2a00:1450:4010:c03::234]) by mx.google.com with ESMTPS id is5si3168947lac.110.2015.04.15.00.54.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Apr 2015 00:54:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::234 as permitted sender) client-ip=2a00:1450:4010:c03::234; Received: by labbd9 with SMTP id bd9so26469460lab.2 for ; Wed, 15 Apr 2015 00:54:07 -0700 (PDT) X-Received: by 10.112.163.168 with SMTP id yj8mr22007298lbb.36.1429084447271; Wed, 15 Apr 2015 00:54:07 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp2344655lbt; Wed, 15 Apr 2015 00:54:06 -0700 (PDT) X-Received: by 10.68.87.229 with SMTP id bb5mr44076325pbb.131.1429084445222; Wed, 15 Apr 2015 00:54:05 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id zn2si5754999pbc.102.2015.04.15.00.54.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Apr 2015 00:54:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-395185-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 13954 invoked by alias); 15 Apr 2015 07:53:51 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 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-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 X-Original-Sender: kugan.vivekanandarajah@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::234 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 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;