gcc is using a divide and multiply where it could be using shift/ands:

unsigned long f1(unsigned long x, unsigned long n)
{
        return x % (1UL << n);
}

produces:

f1:
        li 9,1
        slw 9,9,4
        divwu 0,3,9
        mullw 0,0,9
        subf 3,0,3
        blr


-- 
           Summary: power of 2 mod missing optimisation
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: anton at samba dot org
GCC target triplet: powerpc64-linux


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

Reply via email to