https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90838
Bug ID: 90838 Summary: Detect table-based ctz implementation Product: gcc Version: 9.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: ktkachov at gcc dot gnu.org Target Milestone: --- 531.deepsjeng_r has a hot function doing something like: static const unsigned long long magic = 0x03f08c5392f756cdULL; static const int table[64] = { 0, 1, 12, 2, 13, 22, 17, 3, 14, 33, 23, 36, 18, 58, 28, 4, 62, 15, 34, 26, 24, 48, 50, 37, 19, 55, 59, 52, 29, 44, 39, 5, 63, 11, 21, 16, 32, 35, 57, 27, 61, 25, 47, 49, 54, 51, 43, 38, 10, 20, 31, 56, 60, 46, 53, 42, 9, 30, 45, 41, 8, 40, 7, 6, }; int myctz (unsigned long long b) { unsigned long long lsb = b & -b; return table[(lsb * magic) >> 58]; } This is equivalent to __builtin_ctzl (b). Would it be possible to match this in GCC?