https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94026
--- Comment #4 from Fei Yang <felix.yang at huawei dot com> --- (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; } }