Skip to content

MSVC and Clang use different values for _MM_HINT constants; Windows SDK hardcodes MSVC values #36748

@llvmbot

Description

@llvmbot
Bugzilla Link 37400
Version 6.0
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @topperc,@RKSimon,@rnk

Extended Description

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@Z":                        # @"\01?f@@YAXPEBX@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:headersHeaders provided by Clang, e.g. for intrinsicsplatform:windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions