On Mon, Oct 19, 2020 at 10:19:48AM -0400, Andrew MacLeod via Gcc-patches wrote:
> On 10/19/20 5:38 AM, Aldy Hernandez wrote:
> > If the shift amount in operator_lshift::op1_range was zero, an invalid range
> > of [1, 0] was being created.
> 
> Should we do the same thing with rshift::op1_range?     ie, return the LHS
> if the shift is 0 instead of trying to figure it out....

Shift by 0 is a noop, so yes, for all of left/right shifts and rotates
the result range should be the range of the first operand.

> > gcc/ChangeLog:
> > 
> >     PR tree-optimization/97467
> >     * range-op.cc (operator_lshift::op1_range): Handle shifts by 0.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> >     * gcc.dg/pr97467.c: New test.
> > ---
> >   gcc/range-op.cc                |  5 +++++
> >   gcc/testsuite/gcc.dg/pr97467.c | 16 ++++++++++++++++
> >   2 files changed, 21 insertions(+)
> >   create mode 100644 gcc/testsuite/gcc.dg/pr97467.c
> > 
> > diff --git a/gcc/range-op.cc b/gcc/range-op.cc
> > index 0efa00186e8..30d2a4d3987 100644
> > --- a/gcc/range-op.cc
> > +++ b/gcc/range-op.cc
> > @@ -1579,6 +1579,11 @@ operator_lshift::op1_range (irange &r,
> >         wide_int shift = wi::to_wide (shift_amount);
> >         if (wi::lt_p (shift, 0, SIGNED))
> >     return false;
> > +      if (shift == 0)
> > +   {
> > +     r = lhs;
> > +     return true;
> > +   }
> >         // Work completely in unsigned mode to start.
> >         tree utype = type;
> > diff --git a/gcc/testsuite/gcc.dg/pr97467.c b/gcc/testsuite/gcc.dg/pr97467.c
> > new file mode 100644
> > index 00000000000..dcbd218f733
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/pr97467.c
> > @@ -0,0 +1,16 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-Os" } */
> > +
> > +int a;
> > +long b;
> > +unsigned int c = 1;
> > +
> > +int main () {
> > +  int e;
> > +  for (; c <= 0; c++) {
> > +    int f = 0;
> > +    b = e;
> > +    a = f || b << c;
> > +  }
> > +  return 0;
> > +}

        Jakub

Reply via email to