unsigned long le1_bit(unsigned long x) {
    return x == 0 || (x & (x - 1)) == 0;
}

yields with 4.0.0 20050201:

le1_bit: clr     v0
         lda     t0,-1(a0)
         beq     a0,L1
         and     a0,t0,t0
         bne     t0,L2
L1:      lda     v0,1
L2:      ret


that is, two unnecessary jumps as compared to the completely straight-forward
translation:

le1_bit: cmpeq   a0,0,t0
         lda     t1,-1(a0)
         and     a0,t1,t1
         cmpeq   t1,0,t1
         or      t0,t1,v0
         ret

-- 
           Summary: Unnecessary jumps for comparisons
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: falk at debian dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: alphaev68-unknown-linux-gnu
  GCC host triplet: alphaev68-unknown-linux-gnu
GCC target triplet: alphaev68-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19778

Reply via email to