On Tue, Sep 18, 2018 at 10:52:17AM -0500, Will Schmidt wrote:
> On Wed, 2018-09-12 at 08:23 -0500, Segher Boessenkool wrote: 
> > Hi!
> 
> > > + unsigned int n_elts = VECTOR_CST_NELTS (arg0);
> > > + if (TREE_CODE (arg1) != INTEGER_CST
> > > +     || TREE_INT_CST_LOW (arg1) > (n_elts -1))
> > > +   return false;
> > 
> > I think you should check lower bound 0 as well.  Maybe use IN_RANGE?
> 
> I'm comparing the IN_RANGE usage here with elsewhere in rs6000.c.
> Do I need the sext_hwi() adjustment for arg1 within the IN_RANGE check?

No, it will work fine (it cast to unsigned HWI internally).

> As reference, this is for the vec_splat intrinsic, where arg1 is defined
> as 'const int', and we want to return false if arg1 is outside the range
> of 0..#elements . 
>       vector bool char vec_splat (vector bool char, const int);
> 
> So.. this?
>       unsigned int n_elts = VECTOR_CST_NELTS (arg0);
>       if (TREE_CODE (arg1) != INTEGER_CST
>           || !IN_RANGE (TREE_INT_CST_LOW (arg1), 0, (n_elts - 1))
>         return false;

That looks fine, but you can lose the parens around "n_elts - 1".

...

It turns out TREE_INT_CST_LOW returns an unsigned HWI, so this is all
moot, sorry for the misdirection; just the > is fine, as you had.

But write:

        if (TREE_CODE (arg1) != INTEGER_CST
            || TREE_INT_CST_LOW (arg1) >= n_elts)

or use tree_to_uhwi perhaps...  Ask someone who knows trees :-)


Segher

Reply via email to