[llvm-bugs] [Bug 33869] Clang is not aware of a false dependency of LZCNT, TZCNT, POPCNT on destination register on some Intel CPUs

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Mar 20 13:21:12 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=33869

Ori Livneh <atdt at google.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |---
             Status|RESOLVED                    |REOPENED

--- Comment #24 from Ori Livneh <atdt at google.com> ---
As far as I can tell, clang still does not break the dependency in the
reproduction case I attached in comment 14. Minimally:

    #include <cstdint>
    #include <x86intrin.h>

    __attribute__((noinline))
    int msb(uint64_t n) {
        return 63 ^ __builtin_clzll(n);
    }


clang version 7.0.0 (trunk 327823), -O2 -march=haswell:

    lzcnt rax, rdi
    xor eax, 63
    ret

g++ 8.0.1 20180319, -O2 -march=haswell:

    xor eax, eax
    lzcnt rax, rdi
    xor eax, 63
    ret

https://godbolt.org/g/JC57Ri

The failure to break the dependency chain causes a measurable degradation in
performance when the function is called in a loop. I tested on one Haswell
machine and one Broadwell machine.

Worse, clang is shooting itself in the foot. If you compile the same code but
target an older microarchitecture w/no lzcnt (-march=core-i7 for example),
clang emits a bsr instruction instead, which doesn't appear to suffer from this
false dependency issue.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180320/7f8d4eb6/attachment.html>


More information about the llvm-bugs mailing list