From patchwork Tue Jun 10 09:23:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 31609 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D8F4620675 for ; Tue, 10 Jun 2014 09:24:16 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id g18sf42319021oah.9 for ; Tue, 10 Jun 2014 02:24:16 -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 :x-original-sender:x-original-authentication-results:content-type; bh=JPAZj/DTizyDe/rQh4CbPTy6H88Lgt0EZfDCcLKC8r4=; b=dZfHr9lEUb4rRv6ld/NUl9TKo2hz1rh6iFthpU/YvY8W3ZCGjYt0h0a3Va10trt6kH VzCMQmO/OXekJHoNa474U9XGQW8QbgKDL4MMtEEg/antab+t31IYCgiJQQnfGXA4i51g xVHoGmL6QszzDecqrv6pTS637JJ4d+7ODkl5S00Xfch2Uta3foWvpUgaOINSq0tr94/c 1/atAsNoiGGWwqwngpJ39aemR05QscngQnlMkPIHW9DaAwdalZMjJ7rNVq2YqCqEUuSk D8jbB1iMsCxXOPHdd0FyQzS3U7lwZOn8B8SHMgZmHce6Qt6SBsMfKYxS+YL/c4qv4pnX orUw== X-Gm-Message-State: ALoCoQmY+1AfO538Kzq1+VJmI3UlhGExX7yGyvM6jly0ZNLKhrA470USWznpzA+BYNaj3AwqGmo5 X-Received: by 10.50.61.146 with SMTP id p18mr2883681igr.3.1402392256392; Tue, 10 Jun 2014 02:24:16 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.104 with SMTP id u95ls2025520qgd.5.gmail; Tue, 10 Jun 2014 02:24:16 -0700 (PDT) X-Received: by 10.52.5.129 with SMTP id s1mr26559577vds.31.1402392256052; Tue, 10 Jun 2014 02:24:16 -0700 (PDT) Received: from mail-ve0-x231.google.com (mail-ve0-x231.google.com [2607:f8b0:400c:c01::231]) by mx.google.com with ESMTPS id sn13si12843185vdb.86.2014.06.10.02.24.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Jun 2014 02:24:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c01::231 as permitted sender) client-ip=2607:f8b0:400c:c01::231; Received: by mail-ve0-f177.google.com with SMTP id oz11so3152409veb.8 for ; Tue, 10 Jun 2014 02:24:15 -0700 (PDT) X-Received: by 10.52.121.39 with SMTP id lh7mr414743vdb.66.1402392255955; Tue, 10 Jun 2014 02:24:15 -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 vs6csp210623vcb; Tue, 10 Jun 2014 02:24:15 -0700 (PDT) X-Received: by 10.68.133.7 with SMTP id oy7mr10605709pbb.43.1402392255130; Tue, 10 Jun 2014 02:24:15 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id nu1si33638945pbb.216.2014.06.10.02.24.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Jun 2014 02:24:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-369866-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 756 invoked by alias); 10 Jun 2014 09:24:03 -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 730 invoked by uid 89); 10 Jun 2014 09:24:01 -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-f43.google.com Received: from mail-la0-f43.google.com (HELO mail-la0-f43.google.com) (209.85.215.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 10 Jun 2014 09:24:00 +0000 Received: by mail-la0-f43.google.com with SMTP id mc6so3827864lab.30 for ; Tue, 10 Jun 2014 02:23:57 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.152.121.39 with SMTP id lh7mr21108887lab.7.1402392237295; Tue, 10 Jun 2014 02:23:57 -0700 (PDT) Received: by 10.112.13.36 with HTTP; Tue, 10 Jun 2014 02:23:57 -0700 (PDT) Date: Tue, 10 Jun 2014 17:23:57 +0800 Message-ID: Subject: [PATCH, loop2_invariant, 2/2] Change heuristics for identical invariants From: Zhenqiang Chen To: "gcc-patches@gcc.gnu.org" 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:c01::231 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, When analysing logs of loop2-invariant of eembc, I found the same invariant occurred lots of times in a loop. But it was not selected since its cost was not high and register pressure was high. Logs show performance improvement by giving them higher priority to move. The patch changes the heuristics to move identical invariants: * add a new member eqno, which records the number of invariants eqto the inv. * set its cost to: inv->cost * inv->eqno; * compare with spill_cost if register pressure is high. Bootstrap and no make check regression on X86-64. Bootstrap and no make check regression on X86-64 with flag_ira_loop_pressure = true. OK for trunk? Thanks! -Zhenqiang ChangeLog: 2014-06-10 Zhenqiang Chen * loop-invariant.c (struct invariant): Add a new member: eqno; (find_identical_invariants): Update eqno; (create_new_invariant): Init eqno; (get_inv_cost): Compute comp_cost wiht eqno; (gain_for_invariant): Take spill cost into account. return; @@ -513,7 +517,12 @@ find_identical_invariants (invariant_htab_type eq, struct invariant *inv) mode = GET_MODE (expr); if (mode == VOIDmode) mode = GET_MODE (SET_DEST (set)); - inv->eqto = find_or_insert_inv (eq, expr, mode, inv)->invno; + + tmp = find_or_insert_inv (eq, expr, mode, inv); + inv->eqto = tmp->invno; + + if (tmp->invno != inv->invno && inv->always_executed) + tmp->eqno++; if (dump_file && inv->eqto != inv->invno) fprintf (dump_file, @@ -725,6 +734,10 @@ create_new_invariant (struct def *def, rtx insn, bitmap depends_on, inv->invno = invariants.length (); inv->eqto = ~0u; + + /* Itself. */ + inv->eqno = 1; + if (def) def->invno = inv->invno; invariants.safe_push (inv); @@ -1107,7 +1120,7 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed, if (!inv->cheap_address || inv->def->n_addr_uses < inv->def->n_uses) - (*comp_cost) += inv->cost; + (*comp_cost) += inv->cost * inv->eqno; #ifdef STACK_REGS { @@ -1243,7 +1256,13 @@ gain_for_invariant (struct invariant *inv, unsigned *regs_needed, + IRA_LOOP_RESERVED_REGS - ira_class_hard_regs_num[cl]; if (size_cost > 0) - return -1; + { + int spill_cost = target_spill_cost [speed] * (int) regs_needed[cl]; + if (comp_cost <= spill_cost) + return -1; + + return 2; + } else size_cost = 0; } diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index 92388f5..c43206a 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -104,6 +104,9 @@ struct invariant /* The number of the invariant with the same value. */ unsigned eqto; + /* The number of invariants which eqto this. */ + unsigned eqno; + /* If we moved the invariant out of the loop, the register that contains its value. */ rtx reg; @@ -498,6 +501,7 @@ find_identical_invariants (invariant_htab_type eq, struct invariant *inv) struct invariant *dep; rtx expr, set; enum machine_mode mode; + struct invariant *tmp; if (inv->eqto != ~0u)