From patchwork Thu Jul 3 05:31:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 33011 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F338020560 for ; Thu, 3 Jul 2014 05:32:27 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lj1sf63968564pab.5 for ; Wed, 02 Jul 2014 22:32:27 -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=Axbdg+USXlzacPAuUkglnJm5a8qQRk5R5zwEM+b9oFE=; b=YkCAkAUB7uk+cFE96003QV61YapHKHx6KdciqsRjOOJE+oZJQZoLDhNdItkf8pq22S Ycj4EBT0AocjOhe8RM/Ss8cQCMLXwcVm2W3abWo6u6ighX0lC0Qhxx4Tk+ptw7p1beKz InoRiILkNHgQnjdhv+GtnikbEvAyyahqOOmNDyutzapKPuWZnqTFQpZH8jaYGaA5OkqX 9b93yEcGtwT2kHCQ2byZJqBUnQ38OQD+QnhilL2QP0yECCm6/XB1PYnuMao7l6GgolzK KwKMOwV8jfrSbAcHhXlFoDayiHk6kBg0eqt6cbqf3evX1seCZLXhCUOucgfQSeb0VZnQ 2Hvg== X-Gm-Message-State: ALoCoQn449ircbaNedz04ufaEBuo0POEHHz9glo7XFxezL5K8BR6GCbBdBL4tkxSxxRwX83C3muA X-Received: by 10.66.160.34 with SMTP id xh2mr1369385pab.6.1404365546934; Wed, 02 Jul 2014 22:32:26 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.105.54 with SMTP id b51ls345547qgf.48.gmail; Wed, 02 Jul 2014 22:32:26 -0700 (PDT) X-Received: by 10.220.68.140 with SMTP id v12mr1735497vci.13.1404365546821; Wed, 02 Jul 2014 22:32:26 -0700 (PDT) Received: from mail-vc0-x22e.google.com (mail-vc0-x22e.google.com [2607:f8b0:400c:c03::22e]) by mx.google.com with ESMTPS id b8si13817615vcf.7.2014.07.02.22.32.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Jul 2014 22:32:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22e as permitted sender) client-ip=2607:f8b0:400c:c03::22e; Received: by mail-vc0-f174.google.com with SMTP id hy4so11161559vcb.33 for ; Wed, 02 Jul 2014 22:32:26 -0700 (PDT) X-Received: by 10.52.27.208 with SMTP id v16mr1463419vdg.21.1404365546470; Wed, 02 Jul 2014 22:32:26 -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.37.5 with SMTP id tc5csp346305vcb; Wed, 2 Jul 2014 22:32:26 -0700 (PDT) X-Received: by 10.69.31.107 with SMTP id kl11mr2473426pbd.70.1404365545651; Wed, 02 Jul 2014 22:32:25 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id fl3si32014007pab.165.2014.07.02.22.32.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jul 2014 22:32:25 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-371715-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 17280 invoked by alias); 3 Jul 2014 05:32:00 -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 17173 invoked by uid 89); 3 Jul 2014 05:31:50 -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-f48.google.com Received: from mail-la0-f48.google.com (HELO mail-la0-f48.google.com) (209.85.215.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 03 Jul 2014 05:31:32 +0000 Received: by mail-la0-f48.google.com with SMTP id el20so7615486lab.21 for ; Wed, 02 Jul 2014 22:31:28 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.180.225 with SMTP id dr1mr1706543lbc.51.1404365488861; Wed, 02 Jul 2014 22:31:28 -0700 (PDT) Received: by 10.112.13.36 with HTTP; Wed, 2 Jul 2014 22:31:28 -0700 (PDT) Date: Thu, 3 Jul 2014 13:31:28 +0800 Message-ID: Subject: [Committed]: [PATCH, loop2_invariant, 2/2] Change heuristics for identical invariants From: Zhenqiang Chen To: Jeff Law Cc: Steven Bosscher , "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:c03::22e 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 On 2 July 2014 03:54, Jeff Law wrote: > On 07/01/14 01:16, Zhenqiang Chen wrote: > >> >> ChangeLog: >> 2014-07-01 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; > > s/wiht/with/ > > Do you have a testcase for this? If at all possible I'd like to see some > kind of test to verify that this tracking results in better invariant > selection. Since the patch bases on the result of rtx_cost, it is hard to design a common test case. A testcase for ARM is added. > With some kind of test and the ChangeLog typo fixed, this is OK. Thanks. Updated and committed @r212256. ChangeLog: 2014-07-03 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 with eqno; testsuite/ChangeLog: 2014-07-03 Zhenqiang Chen * gcc.target/arm/identical-invariants.c: New test. + diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index d47d461..bd67eb9 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) 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, @@ -1136,7 +1149,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 { diff --git a/gcc/testsuite/gcc.target/arm/identical-invariants.c b/gcc/testsuite/gcc.target/arm/identical-invariants.c new file mode 100644 index 0000000..7762ce6 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/identical-invariants.c @@ -0,0 +1,29 @@ +/* { dg-do compile { target { arm_thumb2_ok } } } */ +/* { dg-options "-O2 -fdump-rtl-loop2_invariant " } */ + +int t1, t2, t3, t4, t5, t6, t7, t8, t9, t10; +extern void foo2 (int *, int *, int *, int *, int *, int *); +extern int foo3 (int, int, int, int, int, int); +int foo (int a, int b, int c, int d) +{ + int i = a; + + for (; i > 0; i += b) + { + if (a > 0x1234567) + foo2 (&t1, &t2, &t3, &t4, &t5, &t6); + foo2 (&t1, &t2, &t3, &t4, &t5, &t6); + if (b > 0x1234567) + foo2 (&t7, &t2, &t8, &t4, &t5, &t6); + foo2 (&t1, &t2, &t3, &t4, &t5, &t6); + if (c > 0x1234567) + foo2 (&t1, &t9, &t10, &t4, &t5, &t6); + t2 = t5 - d; + } + + return foo3 (t1, t2, t3, t4, t5, t6); +} + +/* { dg-final { scan-rtl-dump "Decided to move invariant 0" "loop2_invariant" } } */ +/* { dg-final { cleanup-rtl-dump "loop2_invariant" } } */