From patchwork Tue Jun 17 02:11:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 32007 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A049820E7A for ; Tue, 17 Jun 2014 02:12:10 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id n16sf37322513oag.6 for ; Mon, 16 Jun 2014 19:12:09 -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:mime-version:date:message-id:subject:from:to:cc :x-original-sender:x-original-authentication-results:content-type; bh=+eXBT0doE2maFjiRxFl7CyVAfOhJixXR1iRQw345NWw=; b=IsyDneBdcUmoQ/YY1tvqxpAnkqUQJ0zna3KGNfmFR+fx4veAMGCXkynspWBm0zLgxy DrVHu59TdOiasKNi9f58ymgfFv/IgP/HtUa/OvbNxxFzlW1Po6fEh/L5ybvwBCDJV2kz 8AxV6hc1hj9VU/TEU8vWEWMPbQzLKJL3zZ/fWPsS51UhAcvr241SYJzR/4RWSoEIXIOP g9W7tK7vfgCL4br1+6XC7EkaDYC9b25UVIjv06JieuZQkisjbkNbekRz0Mci8i8MUyDT WyWLAeZ2+I2pwJTg+CWYoP52a/wa5LN9YvB/VPqVi6LQZhPPUxew67acDiuKPe2MJrAK SCIg== X-Gm-Message-State: ALoCoQmzrYuMuVDlG89fG+Ly97k/J7pcJ5h2/nIPO+7a+nwhZ+x2dHnYZGlcYo0Zyzbp1I7KNVnq X-Received: by 10.182.73.200 with SMTP id n8mr2888382obv.33.1402971129724; Mon, 16 Jun 2014 19:12:09 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.85 with SMTP id u79ls2559462qgu.61.gmail; Mon, 16 Jun 2014 19:12:09 -0700 (PDT) X-Received: by 10.53.0.135 with SMTP id ay7mr16292280vdd.11.1402971129632; Mon, 16 Jun 2014 19:12:09 -0700 (PDT) Received: from mail-vc0-x22a.google.com (mail-vc0-x22a.google.com [2607:f8b0:400c:c03::22a]) by mx.google.com with ESMTPS id aa6si4811606vec.66.2014.06.16.19.12.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Jun 2014 19:12:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22a as permitted sender) client-ip=2607:f8b0:400c:c03::22a; Received: by mail-vc0-f170.google.com with SMTP id hy10so5775047vcb.15 for ; Mon, 16 Jun 2014 19:12:09 -0700 (PDT) X-Received: by 10.52.232.133 with SMTP id to5mr16103916vdc.16.1402971129489; Mon, 16 Jun 2014 19:12:09 -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.221.54.6 with SMTP id vs6csp176524vcb; Mon, 16 Jun 2014 19:12:09 -0700 (PDT) X-Received: by 10.68.196.202 with SMTP id io10mr28099596pbc.149.1402971128771; Mon, 16 Jun 2014 19:12:08 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id rq3si7196167pbb.81.2014.06.16.19.12.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Jun 2014 19:12:08 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-370401-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 22596 invoked by alias); 17 Jun 2014 02:11:56 -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 21202 invoked by uid 89); 17 Jun 2014 02:11:52 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-la0-f42.google.com Received: from mail-la0-f42.google.com (HELO mail-la0-f42.google.com) (209.85.215.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 17 Jun 2014 02:11:50 +0000 Received: by mail-la0-f42.google.com with SMTP id el20so3545512lab.1 for ; Mon, 16 Jun 2014 19:11:47 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.160.105 with SMTP id xj9mr15349527lbb.2.1402971107047; Mon, 16 Jun 2014 19:11:47 -0700 (PDT) Received: by 10.112.13.36 with HTTP; Mon, 16 Jun 2014 19:11:46 -0700 (PDT) Date: Tue, 17 Jun 2014 10:11:46 +0800 Message-ID: Subject: [PATCH, cprop] Check rtx_cost when propagating constant From: Zhenqiang Chen To: "gcc-patches@gcc.gnu.org" Cc: Andrew Pinski X-IsSubscribed: yes X-Original-Sender: zhenqiang.chen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22a 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 Hi, For some large constant, ports like ARM, need one more instructions to operate it. e.g #define MASK 0xfe00ff void maskdata (int * data, int len) { int i = len; for (; i > 0; i -= 2) { data[i] &= MASK; data[i + 1] &= MASK; } } Need two instructions for each AND operation: and r3, r3, #16711935 bic r3, r3, #65536 If we keep the MASK in a register, loop2_invariant pass can hoist it out the loop. And it can be shared by different references. So the patch skips constant propagation if it makes INSN's cost higher. Bootstrap and no make check regression on X86-64 and ARM Chrome book. OK for trunk? Thanks! -Zhenqiang ChangeLog: 2014-06-17 Zhenqiang Chen * cprop.c (try_replace_reg): Check cost for constants. diff --git a/gcc/cprop.c b/gcc/cprop.c index aef3ee8..c9cf02a 100644 --- a/gcc/cprop.c +++ b/gcc/cprop.c @@ -733,6 +733,14 @@ try_replace_reg (rtx from, rtx to, rtx insn) rtx src = 0; int success = 0; rtx set = single_set (insn); + int old_cost = 0; + bool copy_p = false; + bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn)); + + if (set && SET_SRC (set) && REG_P (SET_SRC (set))) + copy_p = true; + else + old_cost = set_rtx_cost (set, speed); /* Usually we substitute easy stuff, so we won't copy everything. We however need to take care to not duplicate non-trivial CONST @@ -740,6 +748,20 @@ try_replace_reg (rtx from, rtx to, rtx insn) 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 (set && !copy_p && CONSTANT_P (to)) + { + int new_cost = set_rtx_cost (set, speed); + if (new_cost > old_cost) + { + cancel_changes (0); + return false; + } + } + if (num_changes_pending () && apply_change_group ()) success = 1;