Skip to content

Commit 8ad32ce

Browse files
committed
[X86] Add sub-feature zu (zero upper) for APX
This is a follow-up patch for #74199
1 parent 954b692 commit 8ad32ce

File tree

9 files changed

+18
-3
lines changed

9 files changed

+18
-3
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6311,9 +6311,9 @@ def mno_gather : Flag<["-"], "mno-gather">, Group<m_Group>,
63116311
def mno_scatter : Flag<["-"], "mno-scatter">, Group<m_Group>,
63126312
HelpText<"Disable generation of scatter instructions in auto-vectorization(x86 only)">;
63136313
def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, Group<m_x86_Features_Group>,
6314-
HelpText<"Enable features of APX">, Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf">;
6314+
HelpText<"Enable features of APX">, Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">;
63156315
def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, Group<m_x86_Features_Group>,
6316-
HelpText<"Disable features of APX">, Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf">;
6316+
HelpText<"Disable features of APX">, Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">;
63176317
// For stability, we only add a feature to -mapxf after it passes the validation of llvm-test-suite && cpu2017 on Intel SDE.
63186318
def mapxf : Flag<["-"], "mapxf">, Alias<mapx_features_EQ>, AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf"]>;
63196319
def mno_apxf : Flag<["-"], "mno-apxf">, Alias<mno_apx_features_EQ>, AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf"]>;

clang/lib/Basic/Targets/X86.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
455455
HasNF = true;
456456
} else if (Feature == "+cf") {
457457
HasCF = true;
458+
} else if (Feature == "+zu") {
459+
HasZU = true;
458460
}
459461

460462
X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
@@ -962,6 +964,8 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
962964
Builder.defineMacro("__NF__");
963965
if (HasCF)
964966
Builder.defineMacro("__CF__");
967+
if (HasZU)
968+
Builder.defineMacro("__ZU__");
965969
// Condition here is aligned with the feature set of mapxf in Options.td
966970
if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD && HasCCMP && HasNF && HasCF)
967971
Builder.defineMacro("__APX_F__");
@@ -1166,6 +1170,7 @@ bool X86TargetInfo::isValidFeatureName(StringRef Name) const {
11661170
.Case("ccmp", true)
11671171
.Case("nf", true)
11681172
.Case("cf", true)
1173+
.Case("zu", true)
11691174
.Default(false);
11701175
}
11711176

@@ -1286,6 +1291,7 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
12861291
.Case("ccmp", HasCCMP)
12871292
.Case("nf", HasNF)
12881293
.Case("cf", HasCF)
1294+
.Case("zu", HasZU)
12891295
.Default(false);
12901296
}
12911297

clang/lib/Basic/Targets/X86.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
172172
bool HasCCMP = false;
173173
bool HasNF = false;
174174
bool HasCF = false;
175+
bool HasZU = false;
175176
bool HasInlineAsmUseGPR32 = false;
176177

177178
protected:

clang/lib/Driver/ToolChains/Arch/X86.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
274274
for (StringRef Value : A->getValues()) {
275275
if (Value == "egpr" || Value == "push2pop2" || Value == "ppx" ||
276276
Value == "ndd" || Value == "ccmp" || Value == "nf" ||
277-
Value == "cf") {
277+
Value == "cf" || Value == "zu") {
278278
Features.push_back(
279279
Args.MakeArgString((IsNegative ? "-" : "+") + Value));
280280
continue;

clang/test/Driver/x86-target-features.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,15 @@
433433
// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=ccmp %s -### -o %t.o 2>&1 | FileCheck -check-prefix=CCMP %s
434434
// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=nf %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NF %s
435435
// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=cf %s -### -o %t.o 2>&1 | FileCheck -check-prefix=CF %s
436+
// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=zu %s -### -o %t.o 2>&1 | FileCheck -check-prefix=ZU %s
436437
// EGPR: "-target-feature" "+egpr"
437438
// PUSH2POP2: "-target-feature" "+push2pop2"
438439
// PPX: "-target-feature" "+ppx"
439440
// NDD: "-target-feature" "+ndd"
440441
// CCMP: "-target-feature" "+ccmp"
441442
// NF: "-target-feature" "+nf"
442443
// CF: "-target-feature" "+cf"
444+
// ZU: "-target-feature" "+zu"
443445

444446
// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr,ndd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
445447
// RUN: %clang -target x86_64-unknown-linux-gnu -mapx-features=egpr -mapx-features=ndd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s

clang/test/Preprocessor/x86_target_features.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@
754754
// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=ccmp -x c -E -dM -o - %s | FileCheck --check-prefix=CCMP %s
755755
// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=nf -x c -E -dM -o - %s | FileCheck --check-prefix=NF %s
756756
// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=cf -x c -E -dM -o - %s | FileCheck --check-prefix=CF %s
757+
// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=zu -x c -E -dM -o - %s | FileCheck --check-prefix=ZU %s
757758
// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapxf -x c -E -dM -o - %s | FileCheck --check-prefixes=EGPR,PUSH2POP2,PPX,NDD,CCMP,NF,CF,APXF %s
758759
// APXF: #define __APX_F__ 1
759760
// CCMP: #define __CCMP__ 1
@@ -763,6 +764,7 @@
763764
// NF: #define __NF__ 1
764765
// PPX: #define __PPX__ 1
765766
// PUSH2POP2: #define __PUSH2POP2__ 1
767+
// ZU: #define __ZU__ 1
766768

767769
// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-inline-asm-use-gpr32 -x c -E -dM -o - %s | FileCheck --check-prefixes=NOUSEGPR32 %s
768770
// RUN: %clang -target x86_64-unknown-unknown -march=x86-64 -mapx-features=egpr -mapx-inline-asm-use-gpr32 -x c -E -dM -o - %s | FileCheck --check-prefixes=USEGPR32 %s

llvm/include/llvm/TargetParser/X86TargetParser.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ X86_FEATURE_COMPAT(AVX512DQ, "avx512dq", 22)
161161
X86_FEATURE_COMPAT(AVX512CD, "avx512cd", 23)
162162
X86_FEATURE (NF, "nf")
163163
X86_FEATURE (CF, "cf")
164+
X86_FEATURE (ZU, "zu")
164165
X86_FEATURE_COMPAT(AVX512VBMI, "avx512vbmi", 24)
165166
X86_FEATURE_COMPAT(AVX512IFMA, "avx512ifma", 25)
166167
X86_FEATURE_COMPAT(AVX5124VNNIW, "avx5124vnniw", 26)

llvm/lib/Target/X86/X86.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ def FeatureNF : SubtargetFeature<"nf", "HasNF", "true",
346346
"Support status flags update suppression">;
347347
def FeatureCF : SubtargetFeature<"cf", "HasCF", "true",
348348
"Support conditional faulting">;
349+
def FeatureZU : SubtargetFeature<"zu", "HasZU", "true",
350+
"Support zero-upper SETcc/IMUL">;
349351
def FeatureUseGPR32InInlineAsm
350352
: SubtargetFeature<"inline-asm-use-gpr32", "UseInlineAsmGPR32", "true",
351353
"Enable use of GPR32 in inline assembly for APX">;

llvm/lib/TargetParser/X86TargetParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ constexpr FeatureBitset ImpliedFeaturesNDD = {};
631631
constexpr FeatureBitset ImpliedFeaturesCCMP = {};
632632
constexpr FeatureBitset ImpliedFeaturesNF = {};
633633
constexpr FeatureBitset ImpliedFeaturesCF = {};
634+
constexpr FeatureBitset ImpliedFeaturesZU = {};
634635

635636
constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = {
636637
#define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM},

0 commit comments

Comments
 (0)