This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fold some equal to and not equal to patterns in match.pd
- From: Kai Tietz <ktietz70 at googlemail dot com>
- To: Jeff Law <law at redhat dot com>
- Cc: Segher Boessenkool <segher at kernel dot crashing dot org>, Andrew Pinski <andrew dot pinski at caviumnetworks dot com>, Richard Biener <richard dot guenther at gmail dot com>, Jakub Jelinek <jakub at redhat dot com>, "Hurugalawadi, Naveen" <Naveen dot Hurugalawadi at caviumnetworks dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 24 Jul 2015 09:48:32 +0200
- Subject: Re: Fold some equal to and not equal to patterns in match.pd
- Authentication-results: sourceware.org; auth=none
- References: <DM2PR0701MB1018928F9138DEBCB2A0E9108E840 at DM2PR0701MB1018 dot namprd07 dot prod dot outlook dot com> <20150721093831 dot GF1780 at tucnak dot redhat dot com> <0B875690-DCED-43AB-B964-67CDDCAF6776 at gmail dot com> <CA+=Sn1nELSn3CPMk5YBWpxyRQCUVj6VQEVSD=ZksDD1iLZ_Y8A at mail dot gmail dot com> <55B111CD dot 2030300 at redhat dot com> <20150723163329 dot GA27818 at gate dot crashing dot org> <55B1D313 dot 6010703 at redhat dot com>
2015-07-24 7:54 GMT+02:00 Jeff Law <law@redhat.com>:
> On 07/23/2015 10:33 AM, Segher Boessenkool wrote:
>>
>> On Thu, Jul 23, 2015 at 10:09:49AM -0600, Jeff Law wrote:
>>>
>>> It seems to me in these kind of cases that selection of the canonical
>>> form should be driven by factors outside of which is better for a
>>> particular target. ie, which is simpler
>>
>>
>> I agree. But neither form is simpler here, and we need to have both
>> forms in other contexts, so there is no real benefit to canonicalising.
>
>
>
> a << N ==/!= 0
>
> Looks like two operations. A shift and a comparison against zero regardless
> of whether or not N is constant.
>
>
> a&(-1>>N) ==/!= 0
>
> For a varying N, this has a shift, logical and and comparison against zero.
>
> For a constant N obviously the shift collapses to a constant and we're left
> with two operations again.
>
> So for gimple, I'd prefer to see us using the a << N form.
>
> If we need both forms in other contexts, we ought to be looking to eliminate
> that need :-)
>
> If we go to the RTL level, then it's more complex -- it might depend on the
> constant produced by the -1 >> N operation, whether or not the target can
> shift by more than one bit at a time (H8/300 series is limited here for
> example), whether or not one operation sets condition codes in a useful way,
> potentially allowing the comparison to be removed, etc etc. rtx_costs, even
> with its limitations is probably the way to drive selection of form for the
> RTL optimizers.
>
>
> Jeff
I fully agree. But there are case there is not necessarily a 'better'
representation. For example for sinking converts into shift-operation
can be tricky.
for 'typea a;'
(typeb) (a << N) -> ((typeb) a) << N
'bitsizeof (typeb) <= N' result is always zero.
'bitsizeof (typeb) > N' result needs to be calculated.
But it isn't necessarily easy to say if form '(typeb) (a << N)', or
'((typeb) a) << N' form is to be prefered. It strongly depends on
expression this pattern is used in.
For RTL this pattern has another issue, as we need to take natural
mode into account here too,
We should define for such forms our 'normal' representation.
Kai