These two functions should produce the same asm: int f(int a, int b) { return (a&0xF)+(b&0xF0); } int f1(int a, int b) { return (a&0xF)|(b&0xF0); } For PPC, we get: _f: rlwinm r4,r4,0,24,27 rlwinm r3,r3,0,28,31 add r3,r3,r4 blr _f1: rlwinm r4,r4,0,24,27 rlwimi r3,r4,0,0,27 blr
Which shows the | is more efficient than the + one. -- Summary: fold does not change (a&C1)+(b&C2) to (a&C1)|(b&C2) iff (C1 & C2) == 0 Product: gcc Version: 4.1.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P2 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: pinskia at gcc dot gnu dot org CC: gcc-bugs at gcc dot gnu dot org GCC target triplet: powerpc-*-* OtherBugsDependingO 19987 nThis: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23664