On 08/30/2017 06:52 AM, Richard Biener wrote: > On Wed, Aug 30, 2017 at 11:53 AM, Michael Clark <michaeljcl...@mac.com> wrote: >> >>> On 30 Aug 2017, at 9:43 PM, Michael Clark <michaeljcl...@mac.com> wrote: >>> >>>>> diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c >>>>> index ce632ae..25dd70f 100644 >>>>> --- a/gcc/simplify-rtx.c >>>>> +++ b/gcc/simplify-rtx.c >>>>> @@ -1503,6 +1503,10 @@ simplify_unary_operation_1 (enum rtx_code code, >>>>> machine_mode mode, rtx op) >>>>> /* (sign_extend:M (lshiftrt:N <X> (const_int I))) is better as >>>>> (zero_extend:M (lshiftrt:N <X> (const_int I))) if I is not 0. */ >>>>> if (GET_CODE (op) == LSHIFTRT >>>>> +#if defined(POINTERS_EXTEND_UNSIGNED) >>>>> + /* we skip this optimisation if pointers naturally extend signed */ >>>>> + && POINTERS_EXTEND_UNSIGNED >>>>> +#endif >>>>> && CONST_INT_P (XEXP (op, 1)) >>>>> && XEXP (op, 1) != const0_rtx) >>>>> return simplify_gen_unary (ZERO_EXTEND, mode, op, GET_MODE (op)); >>>> >>>> Is it just me or does this miss a || mode != Pmode || GET_MODE (op) != >>>> ptr_mode >>>> check? Note the comment says exactly the opposite as the transform... >>>> >>>> I’m not even sure why this simplification is correct in the first place?! >>> >>> I hope you are not confusing my use of POINTERS_EXTEND_UNSIGNED as a proxy >>> for the property that defines whether sub width operations sign-extend to >>> the full width of the register vs zero extend. Are you taking about our >>> added comment? > > I'm talking about using POINTERS_EXTEND_UNSIGNED for sth that looks > unrelated (and that has no easy way to be queried as you noted). Right. I was going to make the same observation. I can't see how POINTER_EXTEND_UNSIGNED plays a significant role here.
MIPS has similar properties and my recollection is they did some interesting tricks in the target files to fold the extension back into the arithmetic insns (beyond the usual LOAD_EXTEND_OP, WORD_REGISTER_OPERATIONS, TRULY_NOOP_TRUNCATION, and PROMOTE_MODE stuff). My recollection was they defined their key insns with match_operators that allowed the sign extension to occur in the arithmetic insns. BUt I don't see any evidence of that anymore. But I can distinctly remember discussing it with Ian and Meissner eons ago and its impact on reload in particular. Jeff