From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21977 invoked by alias); 14 Nov 2012 19:15:14 -0000 Received: (qmail 21967 invoked by uid 22791); 14 Nov 2012 19:15:13 -0000 X-SWARE-Spam-Status: No, hits=-5.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-wg0-f51.google.com (HELO mail-wg0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 14 Nov 2012 19:15:05 +0000 Received: by mail-wg0-f51.google.com with SMTP id ed3so302555wgb.8 for ; Wed, 14 Nov 2012 11:15:03 -0800 (PST) MIME-Version: 1.0 Received: by 10.180.8.100 with SMTP id q4mr27617762wia.16.1352920503859; Wed, 14 Nov 2012 11:15:03 -0800 (PST) Received: by 10.217.64.194 with HTTP; Wed, 14 Nov 2012 11:15:03 -0800 (PST) In-Reply-To: <27d19005-b82d-4ecc-a81e-14208937ce0f@EXCHHUB01.MIPS.com> References: <27d19005-b82d-4ecc-a81e-14208937ce0f@EXCHHUB01.MIPS.com> Date: Wed, 14 Nov 2012 19:15:00 -0000 Message-ID: Subject: Re: [patch] Performance patch for MIPS conditional move in expr.c From: Andrew Pinski To: Steve Ellcey Cc: gcc-patches@gcc.gnu.org, rguenther@suse.de Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg01150.txt.bz2 On Wed, Nov 14, 2012 at 11:02 AM, Steve Ellcey wrote: > > Back in August of 2011, Richard Biener made a change affecting COND_EXPRs > (r178408). As a result of that change the GCC MIPS compiler that used > to promote HImode variables to SImode and then put out SImode variables > and assignments for the conditional move (MIPS doesn't support HImode > conditional moves) started putting out HImode variables and assignments and > the resulting code is slower then it was. > > The code that used to look like this: > > (insn 23 22 24 3 (set (reg/v:SI 231 [ a2+-2 ]) (zero_extend:SI (subreg:HI (reg:SI 320) 2))) x.c:11 -1 (nil)) > (insn 27 26 28 3 (set (reg/v:SI 233 [ a2+-2 ]) (zero_extend:SI (subreg:HI (reg:SI 323) 2))) x.c:12 -1 (nil)) > IF () > (insn 30 241 31 4 (set (reg:SI 324) (reg/v:SI 231 [ a2+-2 ])) -1 (nil)) > ELSE > (insn 34 242 35 5 (set (reg:SI 324) (reg/v:SI 233 [ a2+-2 ])) -1 (nil)) > (insn 36 243 37 6 (set (reg/v:SI 234 [ a2+-2 ]) (reg:SI 324)) -1 (nil)) > > > > started outputting HI assignments instead: > > > > (insn 23 22 24 3 (set (reg/v:SI 231 [ a2+-2 ]) (zero_extend:SI (subreg:HI (reg:SI 320) 2))) x.c:11 -1 (nil)) > (insn 27 26 28 3 (set (reg/v:SI 233 [ a2+-2 ]) (zero_extend:SI (subreg:HI (reg:SI 323) 2))) x.c:12 -1 (nil)) > IF () > (insn 30 241 31 4 (set (reg:HI 324) (subreg/s/u:HI (reg/v:SI 231 [ a2+-2 ]) 2)) -1 (nil)) > ELSE > (insn 34 242 35 5 (set (reg:HI 324) (subreg/s/u:HI (reg/v:SI 233 [ a2+-2 ]) 2)) -1 (nil)) > (insn 36 243 37 6 (set (reg/v:SI 234 [ a2+-2 ]) (zero_extend:SI (reg:HI 324))) -1 (nil)) > > This resulted in an extra 'andi REG,REG,0xffff' instruction to implement the > final zero_extend instruction and that slowed the code down. This patch > restores the previous behaviour by modifying expand_cond_expr_using_cmove > so that when we need to promote the mode in order to do a conditional move > we use that promoted mode in the temp that we are creating for the conditional > move. > > Tested on mips-mti-elf with no regressions. > > OK for checkin? Do you have a testcase? As I added expand_cond_expr_using_cmove, I think this is the correct fix. Thanks, Andrew Pinski > > Steve Ellcey > sellcey@mips.com > > > 2012-11-14 Steve Ellcey > > * expr.c (expand_cond_expr_using_cmove): Use promoted mode for temp. > > > diff --git a/gcc/expr.c b/gcc/expr.c > index cbf3a40..b1b83d0 100644 > --- a/gcc/expr.c > +++ b/gcc/expr.c > @@ -7840,15 +7840,17 @@ expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED, > int unsignedp = TYPE_UNSIGNED (type); > enum machine_mode mode = TYPE_MODE (type); > > - temp = assign_temp (type, 0, 1); > - > /* If we cannot do a conditional move on the mode, try doing it > with the promoted mode. */ > if (!can_conditionally_move_p (mode)) > - mode = promote_mode (type, mode, &unsignedp); > - > - if (!can_conditionally_move_p (mode)) > - return NULL_RTX; > + { > + mode = promote_mode (type, mode, &unsignedp); > + if (!can_conditionally_move_p (mode)) > + return NULL_RTX; > + temp = assign_temp (type, 0, 0); /* Use promoted mode for temp. */ > + } > + else > + temp = assign_temp (type, 0, 1); > > start_sequence (); > expand_operands (treeop1, treeop2,