The boolean expression ((p1->next && !p2->next) || p2->next) can be simplified as (p1->next || p2->next), but gcc failed to detect this.
The attached source code is an example, compile it with options -Os -march=armv5te -mthumb, I got push {lr} ldr r3, [r0] cmp r3, #0 beq .L2 ldr r3, [r1] // redundant load and comparison mov r0, #0 cmp r3, #0 // beq .L3 // can branch to L3 directly .L2: ldr r0, [r1] neg r3, r0 adc r0, r0, r3 .L3: @ sp needed for prologue pop {pc} -- Summary: missed optimization for boolean expression Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: carrot at google dot com GCC build triplet: i686-linux GCC host triplet: i686-linux GCC target triplet: arm-eabi http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41442