Messages in this thread | ![/](/images/icornerl.gif) | | Date | Thu, 10 Dec 2015 12:29:51 -0300 | Subject | Re: [PATCH] usb: remove redundant conditions | From | "Geyslan G. Bem" <> |
| |
2015-12-10 12:17 GMT-03:00 David Laight <David.Laight@aculab.com>: > From: Felipe Balbi >> Sent: 10 December 2015 15:14 >> "Geyslan G. Bem" <geyslan@gmail.com> writes: >> >> > This patch removes redundant conditions. >> > >> > - (!A || (A && B)) is the same as (!A || B). >> > - (length && length > 5) can be reduced to a single evaluation. >> > >> > Caught by: cppcheck >> > >> > Signed-off-by: Geyslan G. Bem <geyslan@gmail.com> >> > --- >> >> I guess you didn't get previous comment in time; let's split this per >> driver so different maintainers can pick their parts. > > I also suspect that gcc will optimise out the redundant checks as well. Yes, David. it will.
Let's see.
void f(int f, int s) { if (!f || (f && s)) printf("branch\n"); }
Generates without optimization three comparisons:
cmpl $0, -4(%rbp) je .L2 cmpl $0, -4(%rbp) je .L4 cmpl $0, -8(%rbp) je .L4
But with -O2 it generates only two:
testl %edi, %edi je .L2 testl %esi, %esi je .L1
Despite that, I think that the patches are welcome since they silence checkpatch and make code clearer. Don't you think?
> > David >
-- Regards,
Geyslan G. Bem hackingbits.com
| ![\](/images/icornerr.gif) |