[clang][x86] Fix the return type of the cvtpd2dq builtin#189254
Conversation
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-x86 Author: Jean-Michel Gorius (jmgorius) ChangesThe CVTPD2DQ instruction converts packed 64-bit floating-point values to packed 32-bit signed integer values. This patch fixes the return type of the corresponding builtin, which previously returned a vector of two 64-bit signed integers. The new behavior is in line with the return type of the CVTTPD2DQ builtin. Full diff: https://github.com/llvm/llvm-project/pull/189254.diff 3 Files Affected:
diff --git a/clang/include/clang/Basic/BuiltinsX86.td b/clang/include/clang/Basic/BuiltinsX86.td
index f47532a63de04..0cab8c77d465d 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -180,7 +180,7 @@ let Features = "avx512f", Attributes = [NoThrow, Const, Constexpr, RequiredVecto
let Features = "sse2", Attributes = [NoThrow, Const, RequiredVectorWidth<128>] in {
def psadbw128 : X86Builtin<"_Vector<2, long long int>(_Vector<16, char>, _Vector<16, char>)">;
- def cvtpd2dq : X86Builtin<"_Vector<2, long long int>(_Vector<2, double>)">;
+ def cvtpd2dq : X86Builtin<"_Vector<4, int>(_Vector<2, double>)">;
def cvttpd2dq : X86Builtin<"_Vector<4, int>(_Vector<2, double>)">;
def cvtsd2si : X86Builtin<"int(_Vector<2, double>)">;
def cvttsd2si : X86Builtin<"int(_Vector<2, double>)">;
diff --git a/clang/lib/Headers/emmintrin.h b/clang/lib/Headers/emmintrin.h
index bbf366133c68a..43c93263f015a 100644
--- a/clang/lib/Headers/emmintrin.h
+++ b/clang/lib/Headers/emmintrin.h
@@ -1343,7 +1343,7 @@ _mm_cvtepi32_pd(__m128i __a) {
/// \returns A 128-bit vector of [4 x i32] whose lower 64 bits contain the
/// converted values. The upper 64 bits are set to zero.
static __inline__ __m128i __DEFAULT_FN_ATTRS _mm_cvtpd_epi32(__m128d __a) {
- return __builtin_ia32_cvtpd2dq((__v2df)__a);
+ return (__m128i)__builtin_ia32_cvtpd2dq((__v2df)__a);
}
/// Converts the low-order element of a 128-bit vector of [2 x double]
diff --git a/clang/test/CodeGen/builtins-x86.c b/clang/test/CodeGen/builtins-x86.c
index a1e63d59e88e1..0f66d8c4e3120 100644
--- a/clang/test/CodeGen/builtins-x86.c
+++ b/clang/test/CodeGen/builtins-x86.c
@@ -290,7 +290,7 @@ void f0(void) {
(void) __builtin_ia32_movnti64(tmp_LLip, tmp_LLi);
#endif
tmp_V2LLi = __builtin_ia32_psadbw128(tmp_V16c, tmp_V16c);
- tmp_V2LLi = __builtin_ia32_cvtpd2dq(tmp_V2d);
+ tmp_V4i = __builtin_ia32_cvtpd2dq(tmp_V2d);
tmp_V4f = __builtin_ia32_cvtpd2ps(tmp_V2d);
tmp_V4i = __builtin_ia32_cvttpd2dq(tmp_V2d);
tmp_i = __builtin_ia32_cvtsd2si(tmp_V2d);
|
RKSimon
left a comment
There was a problem hiding this comment.
LGTM - will correct match int_x86_sse2_cvtpd2dq as well
|
Thanks @RKSimon ! Would it make sense to open more PRs if I come across inconsistent types in the x86 builtins? I found a few that, e.g., should semantically operate on unsigned values but take vectors of signed values instead ( |
|
Sure - keep each patch focused on a particular instruction type though and expect some issues with constexpr evaluation which often uses the signedness from the types in the APSInt values |
The CVTPD2DQ instruction converts packed 64-bit floating-point values to packed 32-bit signed integer values. This patch fixes the return type of the corresponding builtin, which previously returned a vector of two 64-bit signed integers. The new behavior is in line with the return type of the CVTTPD2DQ builtin.