RE: [PATCH] media: atomisp: silence "dubious: !x | !y" warning

From: David Laight
Date: Tue Apr 20 2021 - 06:36:39 EST


From: Dan Carpenter
> Sent: 20 April 2021 11:28
>
> On Sat, Apr 17, 2021 at 09:31:32PM +0000, David Laight wrote:
> > From: Mauro Carvalho Chehab
> > > Sent: 17 April 2021 19:56
> > >
> > > Em Sat, 17 Apr 2021 21:06:27 +0530
> > > Ashish Kalra <eashishkalra@xxxxxxxxx> escreveu:
> > >
> > > > Upon running sparse, "warning: dubious: !x | !y" is brought to notice
> > > > for this file. Logical and bitwise OR are basically the same in this
> > > > context so it doesn't cause a runtime bug. But let's change it to
> > > > logical OR to make it cleaner and silence the Sparse warning.
> >
> > The old code is very likely to by slightly more efficient.
> >
> > It may not matter here, but it might in a really hot path.
> >
> > Since !x | !y and !x || !y always have the same value
> > why is sparse complaining at all.
> >
>
> Smatch doesn't warn about | vs || if both sides are true/false. But
> I've occasionally asked people if they were trying to do a fast path
> optimization but it's always just a typo.

The problem is with people blindly patching code to 'fix'
these warnings.
It might just be a fast path optimisation - which they break.

Trying to beat the compiler into submission can be hard though.
Getting it to 'or' together the outputs from a series of x86
'setne' instructions isn't for the faint hearted.
Not helped by the instruction only setting %al.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)