https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105735
Bug ID: 105735 Summary: GCC failed to reduce &= loop_inv in loop. Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: crazylht at gmail dot com Target Milestone: --- This is another case from 47769, similar like 103462, but a little different. unsigned long cfunc_one(unsigned long tmp, unsigned long bit2) { for (unsigned long bit = 0; bit < 64; bit++) { tmp &= bit2; } return tmp; } it should be equal to unsigned long cfunc_one(unsigned long tmp, unsigned long bit2) { tmp &= bit2; return tmp; } but gcc generates a loop. cfunc_one(unsigned long, unsigned long): mov eax, 64 .L2: and rdi, rsi dec rax jne .L2 mov rax, rdi ret Similar for |= and ^=.