<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - MSVC and Clang use different values for _MM_HINT constants; Windows SDK hardcodes MSVC values"
   href="https://bugs.llvm.org/show_bug.cgi?id=37400">37400</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>MSVC and Clang use different values for _MM_HINT constants; Windows SDK hardcodes MSVC values
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Headers
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>fabiang@radgametools.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>