[llvm-bugs] [Bug 37400] New: MSVC and Clang use different values for _MM_HINT constants; Windows SDK hardcodes MSVC values

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 9 15:44:14 PDT 2018


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

            Bug ID: 37400
           Summary: MSVC and Clang use different values for _MM_HINT
                    constants; Windows SDK hardcodes MSVC values
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Headers
          Assignee: unassignedclangbugs at nondot.org
          Reporter: fabiang at radgametools.com
                CC: llvm-bugs at lists.llvm.org

With clang-cl 6.0:

// ---- begin
#include <emmintrin.h>
#include <Windows.h> // <--- only with this present!

void f(const void *p)
{
    _mm_prefetch((const char *)p, _MM_HINT_T0);
}
// ---- end

"clang-cl -c -O2 -FA prefetch.cpp" yields (only relevant parts):

# ---- begin
"?f@@YAXPEBX at Z":                        # @"\01?f@@YAXPEBX at Z"
# %bb.0:
        prefetcht2      (%rcx)
        retq
# ---- end

...huh? Some grepping later, it turns out that "um\winnt.h" in the Windows SDK
10.0.16299.0 (and presumably other versions as well, but I didn't check)
contains this:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0>rg MM_HINT_T0
um\winnt.h
3266:#define _MM_HINT_T0     1
3296:#define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0
7349:#define _MM_HINT_T0     1
7366:#define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0

and indeed, the MSVC version of xmmintrin.h has _MM_HINT_T0 #defined to 1.

Long story short, for any translation unit that includes Windows.h, 
_MM_HINT_* end up re-#defined to MSVC-specific values, which produce the wrong
instructions with clang-cl.

If the goal is to make clang-cl be able to compile apps using unmodified
Windows headers, then Clang needs to use the same values for _MM_HINT_* as MSVC
does. (Presumably with some remapping done in the frontend.) Sigh.

-- 
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/20180509/862215b5/attachment.html>


More information about the llvm-bugs mailing list