This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PR39715 (Thumb pessimization)


Hi Paolo,

Paolo Bonzini <bonzini@gnu.org> writes:
> Index: gcc/simplify-rtx.c
> ===================================================================
> --- gcc/simplify-rtx.c	(branch cond-optab2)
> +++ gcc/simplify-rtx.c	(working copy)
> @@ -3990,6 +3990,49 @@ simplify_relational_operation_1 (enum rt
>  				    simplify_gen_binary (XOR, cmp_mode,
>  							 XEXP (op0, 1), op1));
>  
> +  /* Look for useless extensions of a subreg, if the extension
> +     is from the same mode as the subreg.  */
> +  if (op0code == SIGN_EXTEND
> +      && GET_CODE (XEXP (op0, 0)) == SUBREG
> +      && subreg_lowpart_p (XEXP (op0, 0))
> +      && GET_MODE (op0) == GET_MODE (SUBREG_REG (XEXP (op0, 0)))
> +      && num_sign_bit_copies (SUBREG_REG (XEXP (op0, 0)), GET_MODE (op0))
> +         > (unsigned) (GET_MODE_BITSIZE (GET_MODE (op0))
> +		       - GET_MODE_BITSIZE (GET_MODE (XEXP (op0, 0)))))
> +    return simplify_gen_relational (code, mode, cmp_mode,
> +				    SUBREG_REG (XEXP (op0, 0)), op1);
> +    
> +  if (GET_CODE (op1) == SIGN_EXTEND
> +      && GET_CODE (XEXP (op1, 0)) == SUBREG
> +      && subreg_lowpart_p (XEXP (op0, 0))
> +      && GET_MODE (op1) == GET_MODE (SUBREG_REG (XEXP (op1, 0)))
> +      && num_sign_bit_copies (SUBREG_REG (XEXP (op1, 0)), GET_MODE (op1))
> +         > (unsigned) (GET_MODE_BITSIZE (GET_MODE (op1))
> +		       - GET_MODE_BITSIZE (GET_MODE (XEXP (op1, 0)))))
> +    return simplify_gen_relational (code, mode, cmp_mode,
> +				    op0, SUBREG_REG (XEXP (op1, 0)));

These seem to be true even without the enclosing comparison:

(sign_extend:W (subreg:N (reg:W X) <low>))
->
(reg:W X) if (reg:W X) is already sign-extended from N to W.

Doesn't my changes to simplify_shift_const_1 in combine fix this?  Or I
guess the problem is that since you create these in simplify-rtx we
never actually see this in the combiner proper.

Then maybe we should do this in simplify_unary_operation_1
<SIGN_EXTEND>?  It's bad that we'd have this in two places but in order
to share code we would have to expand and rebuild compounds in
simplify-rtx too which does not seem like a good idea.

Adam


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]