[Bug rtl-optimization/94026] combine missed opportunity to simplify comparisons with zero
wdijkstr at arm dot com
gcc-bugzilla@gcc.gnu.org
Fri Mar 20 14:23:13 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94026
Wilco <wdijkstr at arm dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |wdijkstr at arm dot com
--- Comment #5 from Wilco <wdijkstr at arm dot com> ---
(In reply to Fei Yang from comment #4)
> (In reply to Fei Yang from comment #0)
> > Created attachment 47966 [details]
> > proposed patch to fix this issue
> >
> > Simple test case:
> > int
> > foo (int c, int d)
> > {
> > int a = (c >> d) & 7;
> >
> > if (a >= 2) {
> > return 1;
> > }
> >
> > return 0;
> > }
> >
> > Compile option: gcc -S -O2 test.c
> >
> >
> > On aarch64, GCC trunk emits 4 instrunctions:
> > asr w0, w0, 8
> > tst w0, 6
> > cset w0, ne
> > ret
> >
> > which can be further simplified into:
> > tst x0, 1536
> > cset w0, ne
> > ret
> >
> > We see the same issue on other targets such as i386 and x86-64.
> >
> > Attached please find proposed patch for this issue.
>
> The previously posted test case is not correct.
> Test case should be:
> int fifth (int c)
> {
> int a = (c >> 8) & 7;
>
> if (a >= 2) {
> return 1;
> } else {
> return 0;
> }
> }
Simpler cases are:
int f1(int x) { return ((x >> 8) & 6) != 0; }
int f2(int x) { return ((x << 2) & 24) != 0; }
int f3(unsigned x) { return ((x << 2) & 15) != 0; }
int f4(unsigned x) { return ((x >> 2) & 14) != 0; }
More information about the Gcc-bugs
mailing list