[Clang] Add elementwise saturated add/sub builtins
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 8 Feb 2022 11:21:46 +0000 (11:21 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 8 Feb 2022 11:22:01 +0000 (11:22 +0000)
commitc00db971597557e952901eac4be131157d1d5eb9
tree451f4ab434c80bc5106616f30e8e27c78b25d2ba
parent95b8a3e52050d68ca5e8f6f8d1b810f6c23b4cea
[Clang] Add elementwise saturated add/sub builtins

This patch implements `__builtin_elementwise_add_sat` and `__builtin_elementwise_sub_sat` builtins.

These map to the add/sub saturated math intrinsics described here:
https://llvm.org/docs/LangRef.html#saturation-arithmetic-intrinsics

With this in place we should then be able to replace the x86 SSE adds/subs intrinsics with these generic variants - it looks like other targets should be able to use these as well (arm/aarch64/webassembly all have similar examples in cgbuiltin).

Differential Revision: https://reviews.llvm.org/D117898
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/Builtins.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-elementwise-math.c
clang/test/Sema/builtins-elementwise-math.c
clang/test/SemaCXX/builtins-elementwise-math.cpp