https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94793

            Bug ID: 94793
           Summary: Failure to optimize clz idiom
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

unsigned r1(unsigned v)
{
    unsigned r = 0;

    while (v >>= 1)
        r++;

    return r;
}

This can optimized to `32 - __builtin_clz(v >> 1);`. LLVM does this
transformation, but GCC does not.

Comparison here : https://godbolt.org/z/u73iap

Reply via email to