LiuChen3 created this revision.
Herald added a project: All.
LiuChen3 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For now we check if the amx intrinsics used on 64-bits target. This
check is not accurate.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131134

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/Driver/x86-target-features.c
  clang/test/Preprocessor/x86_amx_target_features.c

Index: clang/test/Preprocessor/x86_amx_target_features.c
===================================================================
--- clang/test/Preprocessor/x86_amx_target_features.c
+++ clang/test/Preprocessor/x86_amx_target_features.c
@@ -1,35 +1,35 @@
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=AMX-TILE %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mamx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=AMX-TILE %s
 
 // AMX-TILE: #define __AMXTILE__ 1
 
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-bf16 -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-BF16 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mamx-bf16 -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-BF16 %s
 
 // AMX-BF16: #define __AMXBF16__ 1
 // AMX-BF16: #define __AMXTILE__ 1
 
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-int8 -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-INT8 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mamx-int8 -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-INT8 %s
 
 // AMX-INT8: #define __AMXINT8__ 1
 // AMX-INT8: #define __AMXTILE__ 1
 
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-amx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-TILE %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mno-amx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-TILE %s
 
 // NOAMX-TILE-NOT: #define __AMXTILE__ 1
 
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-amx-bf16 -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-BF16 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mno-amx-bf16 -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-BF16 %s
 
 // NOAMX-BF16-NOT: #define __AMXBF16__ 1
 
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -amx-bf16 -mno-amx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-BF16 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -amx-bf16 -mno-amx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-BF16 %s
 
 // NOAMX-BF16-NOT: #define __AMXTILE__ 1
 // NOAMX-BF16-NOT: #define __AMXBF16__ 1
 
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-amx-int8 -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-INT8 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mno-amx-int8 -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-INT8 %s
 
 // NOAMX-INT8-NOT: #define __AMXINT8__ 1
 
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -amx-int8 -mno-amx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-INT8 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -amx-int8 -mno-amx-tile -x c -E -dM -o - %s | FileCheck  -check-prefix=NOAMX-INT8 %s
 
 // NOAMX-INT8-NOT: #define __AMXTILE__ 1
 // NOAMX-INT8-NOT: #define __AMXINT8__ 1
Index: clang/test/Driver/x86-target-features.c
===================================================================
--- clang/test/Driver/x86-target-features.c
+++ clang/test/Driver/x86-target-features.c
@@ -270,20 +270,26 @@
 // WIDE_KL: "-target-feature" "+widekl"
 // NO-WIDE_KL: "-target-feature" "-widekl"
 
-// RUN: %clang --target=i386 -march=i386 -mamx-tile %s -### 2>&1 | FileCheck --check-prefix=AMX-TILE %s
-// RUN: %clang --target=i386 -march=i386 -mno-amx-tile %s -### 2>&1 | FileCheck --check-prefix=NO-AMX-TILE %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mamx-tile %s -### 2>&1 | FileCheck --check-prefix=AMX-TILE %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mno-amx-tile %s -### 2>&1 | FileCheck --check-prefix=NO-AMX-TILE %s
+// RUN: not %clang --target=i386 -march=i386 -mamx-tile %s 2>&1 | FileCheck %s -check-prefix=AMX-TILE-ERROR
 // AMX-TILE: "-target-feature" "+amx-tile"
 // NO-AMX-TILE: "-target-feature" "-amx-tile"
+// AMX-TILE-ERROR: error: option '-mamx-tile' cannot be specified on this target
 
-// RUN: %clang --target=i386 -march=i386 -mamx-bf16 %s -### 2>&1 | FileCheck --check-prefix=AMX-BF16 %s
-// RUN: %clang --target=i386 -march=i386 -mno-amx-bf16 %s -### 2>&1 | FileCheck -check-prefix=NO-AMX-BF16 %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mamx-bf16 %s -### 2>&1 | FileCheck --check-prefix=AMX-BF16 %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mno-amx-bf16 %s -### 2>&1 | FileCheck -check-prefix=NO-AMX-BF16 %s
+// RUN: not %clang --target=i386 -march=i386 -mamx-bf16 %s 2>&1 | FileCheck -check-prefix=AMX-BF16-ERROR %s
 // AMX-BF16: "-target-feature" "+amx-bf16"
 // NO-AMX-BF16: "-target-feature" "-amx-bf16"
+// AMX-BF16-ERROR: error: option '-mamx-bf16' cannot be specified on this target
 
-// RUN: %clang --target=i386 -march=i386 -mamx-int8 %s -### 2>&1 | FileCheck --check-prefix=AMX-INT8 %s
-// RUN: %clang --target=i386 -march=i386 -mno-amx-int8 %s -### 2>&1 | FileCheck --check-prefix=NO-AMX-INT8 %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mamx-int8 %s -### 2>&1 | FileCheck --check-prefix=AMX-INT8 %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mno-amx-int8 %s -### 2>&1 | FileCheck --check-prefix=NO-AMX-INT8 %s
+// RUN: not %clang --target=i386 -march=i386 -mamx-int8 %s 2>&1 | FileCheck -check-prefix=AMX-INT8-ERROR %s
 // AMX-INT8: "-target-feature" "+amx-int8"
 // NO-AMX-INT8: "-target-feature" "-amx-int8"
+// AMX-INT8-ERROR: error: option '-mamx-int8' cannot be specified on this target
 
 // RUN: %clang --target=i386 -march=i386 -mhreset %s -### 2>&1 | FileCheck -check-prefix=HRESET %s
 // RUN: %clang --target=i386 -march=i386 -mno-hreset %s -### 2>&1 | FileCheck -check-prefix=NO-HRESET %s
Index: clang/lib/Basic/Targets/X86.cpp
===================================================================
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targets/X86.cpp
@@ -185,6 +185,7 @@
 /// configured set of features.
 bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
                                          DiagnosticsEngine &Diags) {
+  bool Is64bitTarget = getTriple().getArch() != llvm::Triple::x86;
   for (const auto &Feature : Features) {
     if (Feature[0] != '+')
       continue;
@@ -324,10 +325,16 @@
     } else if (Feature == "+hreset") {
       HasHRESET = true;
     } else if (Feature == "+amx-bf16") {
+      if (!Is64bitTarget)
+        Diags.Report(diag::err_opt_not_valid_on_target) << "-mamx-bf16";
       HasAMXBF16 = true;
     } else if (Feature == "+amx-int8") {
+      if (!Is64bitTarget)
+        Diags.Report(diag::err_opt_not_valid_on_target) << "-mamx-int8";
       HasAMXINT8 = true;
     } else if (Feature == "+amx-tile") {
+      if (!Is64bitTarget)
+        Diags.Report(diag::err_opt_not_valid_on_target) << "-mamx-tile";
       HasAMXTILE = true;
     } else if (Feature == "+avxvnni") {
       HasAVXVNNI = true;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to