[Bug target/95532] New: Failure to optimize __builtin_ctz & 0x1F to __builtin_ctz on x86 with BMI

gabravier at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Jun 4 12:41:06 GMT 2020


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

            Bug ID: 95532
           Summary: Failure to optimize __builtin_ctz & 0x1F to
                    __builtin_ctz on x86 with BMI
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

int f(int x)
{
  return __builtin_ctz(x) & 0x1F;
}

With -mbmi, this can be optimized to `__builtin_ctz(x)` (directly using `tzcnt`
without an `and` afterwards). This transformation is done by LLVM, but not by
GCC.


More information about the Gcc-bugs mailing list