https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94026
Bug ID: 94026 Summary: combine missed opportunity to simplify comparisons with zero Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: felix.yang at huawei dot com Target Milestone: --- Created attachment 47966 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47966&action=edit 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.