https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89184
Bug ID: 89184 Summary: GCC does not simplify expressions involving shifts, bitwise operators and comparisons. Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: m...@nieper-wisskirchen.de Target Milestone: --- GCC compiles the function int foo (unsigned i) { return ((i >> 1) & 3) == 2; } to (in x86-64 assembly) foo: shrl %edi xorl %eax, %eax andl $3, %edi cmpl $2, %edi sete %al ret This is more complicated than necessary; the following assembly produced by clang needs one instruction less: foo: andl $6, %edi xorl %eax, %eax cmpl $4, %edi sete %al retq