https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101200
Bug ID: 101200 Summary: Unneeded AND after shift Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: steinar+gcc at gunderson dot no Target Milestone: --- The code after reduction is: struct { int b[6]; } c; unsigned char d; void e() { unsigned char a = d >> 4, f = d & 15; c.b[a] = c.b[f]; } with g++-11 -O2, this produces movzbl d(%rip), %eax movq %rax, %rdx shrq $4, %rax andl $15, %edx andl $15, %eax movl c(,%rdx,4), %edx movl %edx, c(,%rax,4) ret The second AND with 15 is unneeded and should have been optimized away by VRP as I understand it. I can't reproduce it with ARM, though, so maybe there's something x86-specific? Compiler is gcc version 11.1.0 (Debian 11.1.0-3) The same code is generated back to at least 4.9. Also present in gcc version 12.0.0 20210527 (experimental) [master revision 262e75d22c3:7bb6b9b2f47:9d3a953ec4d2695e9a6bfa5f22655e2aea47a973] (Debian 20210527-1)