Skip to content

Commit 3f25f23

Browse files
authored
[X86][AVX10] Fix unexpected error and warning when using intrinsic (#104781)
E.g.: https://godbolt.org/z/G8zK5svjK Based on Evgenii's work.
1 parent f321456 commit 3f25f23

File tree

11 files changed

+93
-13
lines changed

11 files changed

+93
-13
lines changed

clang/lib/Basic/Targets/X86.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ bool X86TargetInfo::initFeatureMap(
186186
llvm::append_range(UpdatedFeaturesVec, UpdatedAVX10FeaturesVec);
187187
// HasEVEX512 is a three-states flag. We need to turn it into [+-]evex512
188188
// according to other features.
189-
if (HasAVX512F) {
189+
if (!HasAVX10_512 && HasAVX512F) {
190190
UpdatedFeaturesVec.push_back(HasEVEX512 == FE_FALSE ? "-evex512"
191191
: "+evex512");
192-
if (HasAVX10 && !HasAVX10_512 && HasEVEX512 != FE_FALSE)
192+
if (HasAVX10 && HasEVEX512 != FE_FALSE)
193193
Diags.Report(diag::warn_invalid_feature_combination)
194194
<< LastAVX512 + " " + LastAVX10 + "; will be promoted to avx10.1-512";
195195
} else if (HasAVX10) {
196-
if (HasEVEX512 != FE_NOSET)
196+
if (!HasAVX512F && HasEVEX512 != FE_NOSET)
197197
Diags.Report(diag::warn_invalid_feature_combination)
198198
<< LastAVX10 + (HasEVEX512 == FE_TRUE ? " +evex512" : " -evex512");
199199
UpdatedFeaturesVec.push_back(HasAVX10_512 ? "+evex512" : "-evex512");

clang/lib/Headers/avx2intrin.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@
1515
#define __AVX2INTRIN_H
1616

1717
/* Define the default attributes for the functions in this file. */
18+
#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
1819
#define __DEFAULT_FN_ATTRS256 \
1920
__attribute__((__always_inline__, __nodebug__, \
2021
__target__("avx2,no-evex512"), __min_vector_width__(256)))
2122
#define __DEFAULT_FN_ATTRS128 \
2223
__attribute__((__always_inline__, __nodebug__, \
2324
__target__("avx2,no-evex512"), __min_vector_width__(128)))
25+
#else
26+
#define __DEFAULT_FN_ATTRS256 \
27+
__attribute__((__always_inline__, __nodebug__, __target__("avx2"), \
28+
__min_vector_width__(256)))
29+
#define __DEFAULT_FN_ATTRS128 \
30+
__attribute__((__always_inline__, __nodebug__, __target__("avx2"), \
31+
__min_vector_width__(128)))
32+
#endif
2433

2534
/* SSE4 Multiple Packed Sums of Absolute Difference. */
2635
/// Computes sixteen sum of absolute difference (SAD) operations on sets of

clang/lib/Headers/avxintrin.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,21 @@ typedef __bf16 __m256bh __attribute__((__vector_size__(32), __aligned__(32)));
5050
#endif
5151

5252
/* Define the default attributes for the functions in this file. */
53+
#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
5354
#define __DEFAULT_FN_ATTRS \
5455
__attribute__((__always_inline__, __nodebug__, __target__("avx,no-evex512"), \
5556
__min_vector_width__(256)))
5657
#define __DEFAULT_FN_ATTRS128 \
5758
__attribute__((__always_inline__, __nodebug__, __target__("avx,no-evex512"), \
5859
__min_vector_width__(128)))
60+
#else
61+
#define __DEFAULT_FN_ATTRS \
62+
__attribute__((__always_inline__, __nodebug__, __target__("avx"), \
63+
__min_vector_width__(256)))
64+
#define __DEFAULT_FN_ATTRS128 \
65+
__attribute__((__always_inline__, __nodebug__, __target__("avx"), \
66+
__min_vector_width__(128)))
67+
#endif
5968

6069
/* Arithmetic */
6170
/// Adds two 256-bit vectors of [4 x double].

clang/lib/Headers/emmintrin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ typedef __bf16 __m128bh __attribute__((__vector_size__(16), __aligned__(16)));
4949
#endif
5050

5151
/* Define the default attributes for the functions in this file. */
52+
#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
5253
#define __DEFAULT_FN_ATTRS \
5354
__attribute__((__always_inline__, __nodebug__, \
5455
__target__("sse2,no-evex512"), __min_vector_width__(128)))
56+
#else
57+
#define __DEFAULT_FN_ATTRS \
58+
__attribute__((__always_inline__, __nodebug__, __target__("sse2"), \
59+
__min_vector_width__(128)))
60+
#endif
5561

5662
#define __trunc64(x) \
5763
(__m64) __builtin_shufflevector((__v2di)(x), __extension__(__v2di){}, 0)

clang/lib/Headers/gfniintrin.h

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef __GFNIINTRIN_H
1515
#define __GFNIINTRIN_H
1616

17+
#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
1718
/* Default attributes for simple form (no masking). */
1819
#define __DEFAULT_FN_ATTRS \
1920
__attribute__((__always_inline__, __nodebug__, \
@@ -25,26 +26,47 @@
2526
__target__("avx,gfni,no-evex512"), \
2627
__min_vector_width__(256)))
2728

28-
/* Default attributes for ZMM unmasked forms. */
29-
#define __DEFAULT_FN_ATTRS_Z \
29+
/* Default attributes for VLX masked forms. */
30+
#define __DEFAULT_FN_ATTRS_VL128 \
3031
__attribute__((__always_inline__, __nodebug__, \
31-
__target__("avx512f,evex512,gfni"), \
32-
__min_vector_width__(512)))
33-
/* Default attributes for ZMM masked forms. */
34-
#define __DEFAULT_FN_ATTRS_Z_MASK \
32+
__target__("avx512bw,avx512vl,gfni,no-evex512"), \
33+
__min_vector_width__(128)))
34+
#define __DEFAULT_FN_ATTRS_VL256 \
3535
__attribute__((__always_inline__, __nodebug__, \
36-
__target__("avx512bw,evex512,gfni"), \
37-
__min_vector_width__(512)))
36+
__target__("avx512bw,avx512vl,gfni,no-evex512"), \
37+
__min_vector_width__(256)))
38+
#else
39+
/* Default attributes for simple form (no masking). */
40+
#define __DEFAULT_FN_ATTRS \
41+
__attribute__((__always_inline__, __nodebug__, __target__("gfni"), \
42+
__min_vector_width__(128)))
43+
44+
/* Default attributes for YMM unmasked form. */
45+
#define __DEFAULT_FN_ATTRS_Y \
46+
__attribute__((__always_inline__, __nodebug__, __target__("avx,gfni"), \
47+
__min_vector_width__(256)))
3848

3949
/* Default attributes for VLX masked forms. */
4050
#define __DEFAULT_FN_ATTRS_VL128 \
4151
__attribute__((__always_inline__, __nodebug__, \
42-
__target__("avx512bw,avx512vl,gfni,no-evex512"), \
52+
__target__("avx512bw,avx512vl,gfni"), \
4353
__min_vector_width__(128)))
4454
#define __DEFAULT_FN_ATTRS_VL256 \
4555
__attribute__((__always_inline__, __nodebug__, \
46-
__target__("avx512bw,avx512vl,gfni,no-evex512"), \
56+
__target__("avx512bw,avx512vl,gfni"), \
4757
__min_vector_width__(256)))
58+
#endif
59+
60+
/* Default attributes for ZMM unmasked forms. */
61+
#define __DEFAULT_FN_ATTRS_Z \
62+
__attribute__((__always_inline__, __nodebug__, \
63+
__target__("avx512f,evex512,gfni"), \
64+
__min_vector_width__(512)))
65+
/* Default attributes for ZMM masked forms. */
66+
#define __DEFAULT_FN_ATTRS_Z_MASK \
67+
__attribute__((__always_inline__, __nodebug__, \
68+
__target__("avx512bw,evex512,gfni"), \
69+
__min_vector_width__(512)))
4870

4971
#define _mm_gf2p8affineinv_epi64_epi8(A, B, I) \
5072
((__m128i)__builtin_ia32_vgf2p8affineinvqb_v16qi((__v16qi)(__m128i)(A), \

clang/lib/Headers/mmintrin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@ typedef short __v8hi __attribute__((__vector_size__(16)));
3939
typedef char __v16qi __attribute__((__vector_size__(16)));
4040

4141
/* Define the default attributes for the functions in this file. */
42+
#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
4243
#define __DEFAULT_FN_ATTRS_SSE2 \
4344
__attribute__((__always_inline__, __nodebug__, \
4445
__target__("sse2,no-evex512"), __min_vector_width__(128)))
46+
#else
47+
#define __DEFAULT_FN_ATTRS_SSE2 \
48+
__attribute__((__always_inline__, __nodebug__, __target__("sse2"), \
49+
__min_vector_width__(128)))
50+
#endif
4551

4652
#define __trunc64(x) \
4753
(__m64) __builtin_shufflevector((__v2di)(x), __extension__(__v2di){}, 0)

clang/lib/Headers/pmmintrin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717
#include <emmintrin.h>
1818

1919
/* Define the default attributes for the functions in this file. */
20+
#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
2021
#define __DEFAULT_FN_ATTRS \
2122
__attribute__((__always_inline__, __nodebug__, \
2223
__target__("sse3,no-evex512"), __min_vector_width__(128)))
24+
#else
25+
#define __DEFAULT_FN_ATTRS \
26+
__attribute__((__always_inline__, __nodebug__, __target__("sse3"), \
27+
__min_vector_width__(128)))
28+
#endif
2329

2430
/// Loads data from an unaligned memory location to elements in a 128-bit
2531
/// vector.

clang/lib/Headers/smmintrin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717
#include <tmmintrin.h>
1818

1919
/* Define the default attributes for the functions in this file. */
20+
#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
2021
#define __DEFAULT_FN_ATTRS \
2122
__attribute__((__always_inline__, __nodebug__, \
2223
__target__("sse4.1,no-evex512"), __min_vector_width__(128)))
24+
#else
25+
#define __DEFAULT_FN_ATTRS \
26+
__attribute__((__always_inline__, __nodebug__, __target__("sse4.1"), \
27+
__min_vector_width__(128)))
28+
#endif
2329

2430
/* SSE4 Rounding macros. */
2531
#define _MM_FROUND_TO_NEAREST_INT 0x00

clang/lib/Headers/tmmintrin.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717
#include <pmmintrin.h>
1818

1919
/* Define the default attributes for the functions in this file. */
20+
#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
2021
#define __DEFAULT_FN_ATTRS \
2122
__attribute__((__always_inline__, __nodebug__, \
2223
__target__("ssse3,no-evex512"), __min_vector_width__(128)))
24+
#else
25+
#define __DEFAULT_FN_ATTRS \
26+
__attribute__((__always_inline__, __nodebug__, __target__("ssse3"), \
27+
__min_vector_width__(128)))
28+
#endif
2329

2430
#define __trunc64(x) \
2531
(__m64) __builtin_shufflevector((__v2di)(x), __extension__(__v2di){}, 0)

clang/lib/Headers/xmmintrin.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,21 @@ typedef unsigned int __v4su __attribute__((__vector_size__(16)));
3232
#endif
3333

3434
/* Define the default attributes for the functions in this file. */
35+
#if defined(__EVEX512__) && !defined(__AVX10_1_512__)
3536
#define __DEFAULT_FN_ATTRS \
3637
__attribute__((__always_inline__, __nodebug__, __target__("sse,no-evex512"), \
3738
__min_vector_width__(128)))
3839
#define __DEFAULT_FN_ATTRS_SSE2 \
3940
__attribute__((__always_inline__, __nodebug__, \
4041
__target__("sse2,no-evex512"), __min_vector_width__(128)))
42+
#else
43+
#define __DEFAULT_FN_ATTRS \
44+
__attribute__((__always_inline__, __nodebug__, __target__("sse"), \
45+
__min_vector_width__(128)))
46+
#define __DEFAULT_FN_ATTRS_SSE2 \
47+
__attribute__((__always_inline__, __nodebug__, __target__("sse2"), \
48+
__min_vector_width__(128)))
49+
#endif
4150

4251
#define __trunc64(x) \
4352
(__m64) __builtin_shufflevector((__v2di)(x), __extension__(__v2di){}, 0)

clang/test/CodeGen/X86/avx512vlbw-builtins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s
22
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s
3+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx10.1-512 -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s
34

45
#include <immintrin.h>
56

0 commit comments

Comments
 (0)