https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99155
Bug ID: 99155 Summary: redundant AND instructions generated to mask bit fields Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dennisc at harding dot ca Target Milestone: --- Created attachment 50217 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50217&action=edit C source file and Compiler Explorer screen capture While looking at some code on Compiler Explorer I noticed that GCC 10.2 was producing suboptimal code compared to MSVC 19.0. I saw that GCC was issuing redundant AND instructions to mask off bit fields in my C code. I have attached the short C source file used for the test and a screen capture of the Compiler Explorer output from GCC 10.2 and MSVC 19.0 in a ZIP file. I don't think this Compiler Explorer share URL will survive but in case it does you can try https://godbolt.org/z/hhaov9 The assignment at source line 68 generates code at line 15-22 for GCC which contains two redundant AND instructions at lines 16-17. This can be compared to the MSVC code at lines 22-27 which contains an equivalent single AND at line 23. The same issue is repeated at lines 24-25 corresponding to source line 69, and lines 33-34 corresponding to source line 70.