From patchwork Tue Jun 10 09:22:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 357805 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 9F83F140087 for ; Tue, 10 Jun 2014 19:23:13 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=NcrME7X9QjcriQHRlvQZBhg+AcquOzxGWsByXJ8cYvhaUm dAio4YglfAb6hS74SB5fKH/D4zJIbQNQ2qkUd7JCyb1mOnbbu35H1GqFWaAMsELY ffoB1K02JHI08y04ZdJzgu9ODZJicLbM2We0BggE3g9NwUuTssf/N+06v6Lk0= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=VhIgBy2evNJeMmd34afe2RzAtew=; b=RrVEDtw1sEvILXE4ankF 6qpUbA8X5VCnc/7X0487m2s6CfodLToniPzk15UzNeAjrfvdBJ4u6ha+OdYwQWVT LcQ5hh+LAnlUY0oLYk4CVC16P8uYZJTov+w/ZEevHbr030OXSANe6WDzPIBnoVFl vlAPHUmpLb/JLxsZzkJlxKg= Received: (qmail 31672 invoked by alias); 10 Jun 2014 09:23:06 -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 31660 invoked by uid 89); 10 Jun 2014 09:23:04 -0000 Authentication-Results: sourceware.org; auth=none 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-f49.google.com Received: from mail-la0-f49.google.com (HELO mail-la0-f49.google.com) (209.85.215.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 10 Jun 2014 09:23:03 +0000 Received: by mail-la0-f49.google.com with SMTP id pv20so3697641lab.22 for ; Tue, 10 Jun 2014 02:22:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=BBQXT00WrXvQPwGmUbMYHRUysNy+JlCXeUsB5WtU0/U=; b=eEwdpfY/AjM4YcXTXPmNKi/mUY9qsgVA9Ei+Jgwz5VG8UQe3xzLEX1ASlXAbNzTnRi 6nWrh4KUEJ/ID02YwVs3VyEIF6ChKilzU4mWA9iY4UeYpUce2O1hs3IX/tNWxQPqPI4t KrhVvcmEK3JUcaPBVfopFBrzN5w7ymp+jFSUtNZww/nm1NTrpmfyqAPcTqaSFWmSly0U SkPxhPhLUdWOUsQwuVGWDATOtnWsUHYTkWmCJOgGNd9fhpDrc10RyCSkQHRDHB/Rhl0E wlv7LMpkMoeLDVcLn1wbXJWC/Xi17itscXUCs7e2FEyL5us/xzgQbuDpLzPEgM6uqBa2 HQbw== X-Gm-Message-State: ALoCoQlvqUOeZAIKzDwRAIF6UXzYMY/4e4Pn/eTWAxMzRR6KL+El8ss6GoBTPeXuZhDv5DCb0R1W MIME-Version: 1.0 X-Received: by 10.153.5.37 with SMTP id cj5mr1319331lad.48.1402392179288; Tue, 10 Jun 2014 02:22:59 -0700 (PDT) Received: by 10.112.13.36 with HTTP; Tue, 10 Jun 2014 02:22:59 -0700 (PDT) Date: Tue, 10 Jun 2014 17:22:59 +0800 Message-ID: Subject: [PATCH, loop2_invariant, 1/2] Check only one register class From: Zhenqiang Chen To: "gcc-patches@gcc.gnu.org" X-IsSubscribed: yes Hi, For loop2-invariant pass, when flag_ira_loop_pressure is enabled, function gain_for_invariant checks the pressures of all register classes. This does not make sense since one invariant might impact only one register class. The patch enhances functions get_inv_cost and gain_for_invariant to check only the register pressure of the invariant if possible. 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 (get_inv_cost): Handle register class. (gain_for_invariant): Check the register pressure of the inv, other than all. if (! flag_ira_loop_pressure) @@ -1095,6 +1101,8 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) pressure_class = get_pressure_class_and_nregs (inv->insn, &nregs); regs_needed[pressure_class] += nregs; + *cl = pressure_class; + ret = 1; } if (!inv->cheap_address @@ -1135,10 +1143,12 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) EXECUTE_IF_SET_IN_BITMAP (inv->depends_on, 0, depno, bi) { bool check_p; + enum reg_class dep_cl = NO_REGS; + int dep_ret; dep = invariants[depno]; - get_inv_cost (dep, &acomp_cost, aregs_needed); + dep_ret = get_inv_cost (dep, &acomp_cost, aregs_needed, &dep_cl); if (! flag_ira_loop_pressure) check_p = aregs_needed[0] != 0; @@ -1148,6 +1158,11 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) if (aregs_needed[ira_pressure_classes[i]] != 0) break; check_p = i < ira_pressure_classes_num; + + if (dep_ret > 1) + ret += dep_ret; + else if ((dep_ret == 1) && (*cl != dep_cl)) + ret++; } if (check_p /* We need to check always_executed, since if the original value of @@ -1181,6 +1196,7 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) } (*comp_cost) += acomp_cost; } + return ret; } /* Calculates gain for eliminating invariant INV. REGS_USED is the number @@ -1195,10 +1211,12 @@ gain_for_invariant (struct invariant *inv, unsigned *regs_needed, bool speed, bool call_p) { int comp_cost, size_cost; + enum reg_class cl; + int ret; actual_stamp++; - get_inv_cost (inv, &comp_cost, regs_needed); + ret = get_inv_cost (inv, &comp_cost, regs_needed, &cl); if (! flag_ira_loop_pressure) { @@ -1207,6 +1225,24 @@ gain_for_invariant (struct invariant *inv, unsigned *regs_needed, - estimate_reg_pressure_cost (new_regs[0], regs_used, speed, call_p)); } + else if (ret == 0) + return -1; + else if (ret == 1) + { + /* Hoist it anyway since it does not impact register pressure. */ + if (cl == NO_REGS) + return 1; + + size_cost = (int) new_regs[cl] + + (int) regs_needed[cl] + + LOOP_DATA (curr_loop)->max_reg_pressure[cl] + + IRA_LOOP_RESERVED_REGS + - ira_class_hard_regs_num[cl]; + if (size_cost > 0) + return -1; + else + size_cost = 0; + } else { int i; diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index 100a2c1..e822bb6 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -1058,16 +1058,22 @@ get_pressure_class_and_nregs (rtx insn, int *nregs) } /* Calculates cost and number of registers needed for moving invariant INV - out of the loop and stores them to *COST and *REGS_NEEDED. */ + out of the loop and stores them to *COST and *REGS_NEEDED. *CL will be + the REG_CLASS of INV. Return + 0: if INV is invalid. + 1: if INV and its depends_on have same reg_class + > 1: if INV and its depends_on have different reg_classes. */ -static void -get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) +static int +get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed, + enum reg_class *cl) { int i, acomp_cost; unsigned aregs_needed[N_REG_CLASSES]; unsigned depno; struct invariant *dep; bitmap_iterator bi; + int ret = 2; /* Find the representative of the class of the equivalent invariants. */ inv = invariants[inv->eqto]; @@ -1083,7 +1089,7 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) if (inv->move || inv->stamp == actual_stamp) - return; + return 0; inv->stamp = actual_stamp;