On Wed, Nov 14, 2012 at 11:02 AM, Steve Ellcey <sell...@mips.com> 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
> sell...@mips.com
>
>
> 2012-11-14  Steve Ellcey  <sell...@mips.com>
>
>         * 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,

Reply via email to