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: Fold some equal to and not equal to patterns in match.pd


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


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