[Builltins][X86] Provide implementations of __lzcnt16, __lzcnt, __lzcnt64 for MS...
authorCraig Topper <craig.topper@intel.com>
Fri, 14 Dec 2018 00:21:02 +0000 (00:21 +0000)
committerCraig Topper <craig.topper@intel.com>
Fri, 14 Dec 2018 00:21:02 +0000 (00:21 +0000)
commit1f2b181689c8b938f2ec344179a86d3fbeaf0c74
treebbc68f9aa19ef4141c68c57a9725605625c2db15
parent37b891edb3ea1e2bc1ec5a076aba56741a357621
[Builltins][X86] Provide implementations of __lzcnt16, __lzcnt, __lzcnt64 for MS compatibility. Remove declarations from intrin.h and implementations from lzcntintrin.h

intrin.h had forward declarations for these and lzcntintrin.h had implementations that were only available with -mlzcnt or a -march that supported the lzcnt feature.

For MS compatibility we should always have these builtins available regardless of X86 being the target or the CPU support the lzcnt instruction. The backends should be able to gracefully fallback to something support even if its just shifts and bit ops.

Unfortunately, gcc also implements 2 of the 3 function names here on X86 when lzcnt feature is enabled.

This patch adds builtins for these for MSVC compatibility and drops the forward declarations from intrin.h. To keep the gcc compatibility the two intrinsics that collided have been turned into macros that use the X86 specific builtins with the lzcnt feature check. These macros are only defined when _MSC_VER is not defined. Without them being macros we can get a redefinition error because -ms-extensions doesn't seem to set _MSC_VER but does make the MS builtins available.

Should fix PR40014

Differential Revision: https://reviews.llvm.org/D55677

llvm-svn: 349098
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/intrin.h
clang/lib/Headers/lzcntintrin.h
clang/test/CodeGen/ms-intrinsics-other.c