This is the mail archive of the
mailing list for the GCC project.
Re: Redundant sign-extension instructions on RISC-V
- From: Jeff Law <law at redhat dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>, Michael Clark <michaeljclark at mac dot com>
- Cc: GCC Development <gcc at gcc dot gnu dot org>, Andrew Waterman <andrew at sifive dot com>, Palmer Dabbelt <palmer at sifive dot com>
- Date: Wed, 30 Aug 2017 08:22:27 -0600
- Subject: Re: Redundant sign-extension instructions on RISC-V
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=law at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5B4077E42F
- References: <25835613-5493-42EB-B4C8-E44BAC9F401E@mac.com> <CAFiYyc0_jc3N=+_VRi2c4bGBr7EDfnRAidYLfwD0oX3hx-2KbQ@mail.gmail.com> <E11F5B57-0756-48BB-B0A3-EC409EC7C2D2@mac.com> <CB6CAF1C-DE21-455B-A58D-1C10628AAFA1@mac.com> <CAFiYyc10j6ugDHYztF0QZLSRgOV0PAHS4-L_5RDpDY=G1iZBPg@mail.gmail.com>
On 08/30/2017 06:52 AM, Richard Biener wrote:
> On Wed, Aug 30, 2017 at 11:53 AM, Michael Clark <firstname.lastname@example.org> wrote:
>>> On 30 Aug 2017, at 9:43 PM, Michael Clark <email@example.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
>>>>> && 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