[all-commits] [llvm/llvm-project] 0431d6: Clang: convert `__m64` intrinsics to unconditional...

James Y Knight via All-commits all-commits at lists.llvm.org
Wed Jul 24 14:00:33 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0431d6dab40b05d9f4a312a9c170c81a889bfb49
      https://github.com/llvm/llvm-project/commit/0431d6dab40b05d9f4a312a9c170c81a889bfb49
  Author: James Y Knight <jyknight at google.com>
  Date:   2024-07-24 (Wed, 24 Jul 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/BuiltinsX86.def
    M clang/lib/CodeGen/CGBuiltin.cpp
    M clang/lib/Headers/emmintrin.h
    M clang/lib/Headers/mmintrin.h
    M clang/lib/Headers/tmmintrin.h
    M clang/lib/Headers/xmmintrin.h
    M clang/lib/Sema/SemaX86.cpp
    M clang/test/CodeGen/X86/mmx-builtins.c
    M clang/test/CodeGen/X86/mmx-inline-asm.c
    M clang/test/CodeGen/X86/mmx-shift-with-immediate.c
    M clang/test/CodeGen/attr-target-x86-mmx.c
    M clang/test/CodeGen/builtins-x86.c
    M clang/test/CodeGen/palignr.c
    R clang/test/CodeGen/pr26099.c
    M clang/test/Headers/xmmintrin.c
    M clang/test/Sema/x86-builtin-palignr.c
    M clang/www/builtins.py
    M llvm/include/llvm/IR/IntrinsicsX86.td

  Log Message:
  -----------
  Clang: convert `__m64` intrinsics to unconditionally use SSE2 instead of MMX. (#96540)

The MMX instruction set is legacy, and the SSE2 variants are in every
way superior, when they are available -- and they have been available
since the Pentium 4 was released, 20 years ago.

Therefore, we are switching the "MMX" intrinsics to depend on SSE2,
unconditionally. This change entirely drops the ability to generate
vectorized code using compiler intrinsics for chips with MMX but without
SSE2: the Intel Pentium MMX, Pentium, II, and Pentium III (released
1997-1999), as well as AMD K6 and K7 series chips of around the same
timeframe. Targeting these older CPUs remains supported -- simply
without the ability to use MMX compiler intrinsics.

Migrating away from the use of MMX registers also fixes a rather
non-obvious requirement. The long-standing programming model for these
MMX intrinsics requires that the programmer be aware of the x87/MMX
mode-switching semantics, and manually call `_mm_empty()` between using
any MMX instruction and any x87 FPU instruction. If you neglect to, then
every future x87 operation will return a NaN result. This requirement is
not at all obvious to users of these these intrinsic functions, and
causes very difficult to detect bugs.

Worse, even if the user did write code that correctly calls
`_mm_empty()` in the right places, LLVM may sometimes reorder x87 and
mmx operations around each-other, unaware of this mode switching issue.

Eliminating the use of MMX registers eliminates this problem.

This change also deletes the now-unnecessary MMX `__builtin_ia32_*`
functions from Clang. Only 3 MMX-related builtins remain in use --
`__builtin_ia32_emms`, used by `_mm_empty`, and
`__builtin_ia32_vec_{ext,set}_v4si`, used by `_mm_insert_pi16` and
`_mm_extract_pi16`. Note particularly that the latter two lower to
generic, non-MMX, IR. Support for the LLVM intrinsics underlying these
removed builtins still remains, for the moment.

The file `clang/www/builtins.py` has been updated with mappings from the
newly-removed `__builtin_ia32` functions to the still-supported
equivalents in `mmintrin.h`.

(Originally uploaded at https://reviews.llvm.org/D86855 and
https://reviews.llvm.org/D94252)

Fixes issue #41665
Works towards #98272



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list