From patchwork Wed Jun 27 03:02:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 167490 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]) by ozlabs.org (Postfix) with SMTP id 1908AB6FCA for ; Wed, 27 Jun 2012 13:03:29 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1341371010; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=mNqmt/f J3FGZcbRmzDkrBWU+vFM=; b=NZqSZ2lLDUUM91vAB5bp0XogynRqdgZHDINoHUm aqYX+AoRI8f7xbsawiplA7kL2Egwo4iQs4a3OIkX/5Ju+CQfg7NJHzFCvLNuAqvT IkSgBvVSW/mq0ym8+UsSayQtIJ6R2eV7kgnIjUvgL4jLmYpM9xfkdiPiaRFuKyzK TY6w= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=pdLyRG/G3KTLEi1OkaJ7LV2l4qkbH7rJdA1JQO4dOeCHGt1mGg0J/DoZZ3zFje GjUcl6KCJgcUrKbbB8Hdt45bF5EKXnHIDd2hLpsX8StaSh41peTV4+Tx29/TasK3 IOT4YgD6sgXYyN8m3hEkJHNY2CIgd9+qeXOfHYMmkGC2w=; Received: (qmail 20668 invoked by alias); 27 Jun 2012 03:03:25 -0000 Received: (qmail 20658 invoked by uid 22791); 27 Jun 2012 03:03:24 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, TW_DQ, TW_PX, TW_VD, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 27 Jun 2012 03:03:05 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q5R32xF4001675 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Jun 2012 23:02:59 -0400 Received: from pebble.twiddle.home (vpn-11-210.rdu.redhat.com [10.11.11.210]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q5R32vau018695; Tue, 26 Jun 2012 23:02:57 -0400 Message-ID: <4FEA77E0.4020501@redhat.com> Date: Tue, 26 Jun 2012 20:02:56 -0700 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: GCC Patches CC: Vladimir Makarov , bernds@codesourcery.com, uweigand@de.ibm.com Subject: [RFC] Tweak reload to const propagate into matching constraint output X-IsSubscribed: yes 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 The problem I'd like to solve is stuff like pxor %xmm4, %xmm4 ... movdqa %xmm4, %xmm2 pcmpgtd %xmm0, %xmm2 In that there's no point performing the copy from xmm4 rather than just emitting a new pxor insn. The Real Problem, as I see it, is that at the point (g)cse runs we have no visibility into the 2-operand matching constraint on that pcmpgtd so we make the wrong choice in sharing the zero. If we're using AVX, instead of SSE, we don't use matching constraints and given the 3-operand insn, hoisting the zero is the right and proper thing to do because we won't need to emit that movdqa. Of course, this fires for normal integer code as well. Some cases it's a clear win: -: 41 be 1f 00 00 00 mov $0x1f,%r14d ... -: 4c 89 f1 mov %r14,%rcx +: b9 1f 00 00 00 mov $0x1f,%ecx sometimes not (increased code size): -: 41 bd 01 00 00 00 mov $0x1,%r13d -: 4d 89 ec mov %r13,%r12 +: 41 bc 01 00 00 00 mov $0x1,%r12d +: 41 bd 01 00 00 00 mov $0x1,%r13d although the total difference is minimal, and ambiguous: new text old text cc1 13971302 13971342 cc1plus 15882736 15882728 Also, note that in the first case above, r14 is otherwise unused, and we wind up with an unnecessary save/restore of the register in the function. Thoughts? r~ diff --git a/gcc/reload.c b/gcc/reload.c index e42cc5c..fb928be 100644 --- a/gcc/reload.c +++ b/gcc/reload.c @@ -2534,6 +2534,38 @@ safe_from_earlyclobber (rtx op, rtx clobber) early_data = decompose (clobber); return immune_p (op, clobber, early_data); } + +/* For matching operand constraints, we may need to make a reg-reg copy. + In some cases the source reg is equivalent to a constant, and it's + more efficient to set the dest reg from the constant rather than the + source reg. Return the source to use for the reload. */ + +static rtx +matching_constraint_src (rtx src) +{ + unsigned regno; + rtx c; + + if (!REG_P (src)) + return src; + + regno = REGNO (src); + if (HARD_REGISTER_NUM_P (regno)) + { + regno = ORIGINAL_REGNO (src); + if (HARD_REGISTER_NUM_P (regno)) + return src; + } + c = reg_equiv_constant (regno); + if (c == NULL) + return src; + + /* Only use the constant when it's just as cheap as a reg move. */ + if (set_src_cost (c, optimize_function_for_speed_p (cfun)) == 0) + return c; + else + return src; +} /* Main entry point of this file: search the body of INSN for values that need reloading and record them with push_reload. @@ -4049,28 +4081,28 @@ find_reloads (rtx insn, int replace, int ind_levels, int live_known, else if (modified[i] == RELOAD_READ && modified[goal_alternative_matched[i]] == RELOAD_WRITE) { + int a = goal_alternative_matched[i]; operand_reloadnum[i] - = push_reload (recog_data.operand[i], - recog_data.operand[goal_alternative_matched[i]], + = push_reload (matching_constraint_src (recog_data.operand[i]), + recog_data.operand[a], recog_data.operand_loc[i], - recog_data.operand_loc[goal_alternative_matched[i]], + recog_data.operand_loc[a], (enum reg_class) goal_alternative[i], - operand_mode[i], - operand_mode[goal_alternative_matched[i]], + operand_mode[i], operand_mode[a], 0, 0, i, RELOAD_OTHER); - operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum; + operand_reloadnum[a] = output_reloadnum; } else if (modified[i] == RELOAD_WRITE && modified[goal_alternative_matched[i]] == RELOAD_READ) { - operand_reloadnum[goal_alternative_matched[i]] - = push_reload (recog_data.operand[goal_alternative_matched[i]], + int a = goal_alternative_matched[i]; + operand_reloadnum[a] + = push_reload (matching_constraint_src (recog_data.operand[a]), recog_data.operand[i], - recog_data.operand_loc[goal_alternative_matched[i]], + recog_data.operand_loc[a], recog_data.operand_loc[i], (enum reg_class) goal_alternative[i], - operand_mode[goal_alternative_matched[i]], - operand_mode[i], + operand_mode[a], operand_mode[i], 0, 0, i, RELOAD_OTHER); operand_reloadnum[i] = output_reloadnum; }