The attached code produces the following assembler foo: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax testl %eax, %eax jne .L7 leave ret .p2align 2,,3 .L7: xorl %edx, %edx bsfl %eax, %eax sete %dl negl %edx orl %edx, %eax incl %eax decl %eax leave ret
There are two issues 1) the incl/decl pair fails to be eliminated. I presume this is because the define_insn_and_split that i86 uses gets split too late for CSE to fold in the subsequent decrement of the source code. Perhaps it could be partially split earlier, leaving the conditional move stuff to later. I've not examined it in greate detal. 2) Possibly much harder. The ffs expansion has no knowledge that its input is nonzero, and therefore need not deal with that case. I gues this will be systemic to other targets. I wonder what can be done about that -- possibly duplicate FFS_NON_ZERO_EXPR and FFS_MAYBE_ZERO_EXPR nodes? -- Summary: extraneous inc/dec pair Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: nathan at gcc dot gnu dot org CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18233