Skip to content

[AMDGPU] Report error in clang if wave32 is requested where unsupported #97633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 9, 2024

Conversation

rampitec
Copy link
Collaborator

@rampitec rampitec commented Jul 3, 2024

No description provided.

@rampitec rampitec requested review from jayfoad and shiltian July 3, 2024 20:35
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AMDGPU clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-amdgpu

Author: Stanislav Mekhanoshin (rampitec)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/97633.diff

5 Files Affected:

  • (modified) clang/lib/Basic/Targets/AMDGPU.cpp (+6-2)
  • (modified) clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl (+2)
  • (modified) clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl (+1-2)
  • (modified) llvm/include/llvm/TargetParser/TargetParser.h (+2-1)
  • (modified) llvm/lib/TargetParser/TargetParser.cpp (+9-4)
diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index cc7be64656e5b..ea20acdb930fa 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -188,8 +188,12 @@ bool AMDGPUTargetInfo::initFeatureMap(
 
   // TODO: Should move this logic into TargetParser
   std::string ErrorMsg;
-  if (!insertWaveSizeFeature(CPU, getTriple(), Features, ErrorMsg)) {
-    Diags.Report(diag::err_invalid_feature_combination) << ErrorMsg;
+  bool IsCombinationError;
+  if (!insertWaveSizeFeature(CPU, getTriple(), Features, ErrorMsg,
+                             IsCombinationError)) {
+    Diags.Report(IsCombinationError ? diag::err_invalid_feature_combination
+                                    : diag::err_opt_not_valid_on_target)
+        << ErrorMsg;
     return false;
   }
 
diff --git a/clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl b/clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl
index 7dbf5c3c6cd59..4e2f7f86e8402 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl
@@ -1,6 +1,8 @@
 // RUN: not %clang_cc1 -triple amdgcn -target-feature +wavefrontsize32 -target-feature +wavefrontsize64 -o /dev/null %s 2>&1 | FileCheck %s
 // RUN: not %clang_cc1 -triple amdgcn -target-cpu gfx1103 -target-feature +wavefrontsize32 -target-feature +wavefrontsize64 -o /dev/null %s 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -triple amdgcn -target-cpu gfx900 -target-feature +wavefrontsize32 -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=GFX9
 
 // CHECK: error: invalid feature combination: 'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive
+// GFX9: error: option 'wavefrontsize32' cannot be specified on this target
 
 kernel void test() {}
diff --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl b/clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl
index 52f31c1ff0575..e0e3872b566d9 100644
--- a/clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl
+++ b/clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl
@@ -12,8 +12,7 @@ void test_ballot_wave32(global uint* out, int a, int b) {
   *out = __builtin_amdgcn_ballot_w32(a == b);  // expected-error {{'__builtin_amdgcn_ballot_w32' needs target feature wavefrontsize32}}
 }
 
-// FIXME: Should error for subtargets that don't support wave32
-__attribute__((target("wavefrontsize32")))
+__attribute__((target("wavefrontsize32"))) // gfx9-error@*:* {{option 'wavefrontsize32' cannot be specified on this target}}
 void test_ballot_wave32_target_attr(global uint* out, int a, int b) {
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
diff --git a/llvm/include/llvm/TargetParser/TargetParser.h b/llvm/include/llvm/TargetParser/TargetParser.h
index e03d8f6eebfca..858a1fdc01b37 100644
--- a/llvm/include/llvm/TargetParser/TargetParser.h
+++ b/llvm/include/llvm/TargetParser/TargetParser.h
@@ -178,7 +178,8 @@ void fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
 
 /// Inserts wave size feature for given GPU into features map
 bool insertWaveSizeFeature(StringRef GPU, const Triple &T,
-                           StringMap<bool> &Features, std::string &ErrorMsg);
+                           StringMap<bool> &Features, std::string &ErrorMsg,
+                           bool &IsCombinationError);
 
 } // namespace AMDGPU
 } // namespace llvm
diff --git a/llvm/lib/TargetParser/TargetParser.cpp b/llvm/lib/TargetParser/TargetParser.cpp
index 00df92e0aaded..4bcd966183c67 100644
--- a/llvm/lib/TargetParser/TargetParser.cpp
+++ b/llvm/lib/TargetParser/TargetParser.cpp
@@ -618,15 +618,20 @@ static bool isWave32Capable(StringRef GPU, const Triple &T) {
 
 bool AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T,
                                    StringMap<bool> &Features,
-                                   std::string &ErrorMsg) {
+                                   std::string &ErrorMsg,
+                                   bool &IsCombinationError) {
   bool IsWave32Capable = isWave32Capable(GPU, T);
   const bool IsNullGPU = GPU.empty();
-  // FIXME: Not diagnosing wavefrontsize32 on wave64 only targets.
-  const bool HaveWave32 =
-      (IsWave32Capable || IsNullGPU) && Features.count("wavefrontsize32");
+  const bool HaveWave32 = Features.count("wavefrontsize32");
   const bool HaveWave64 = Features.count("wavefrontsize64");
   if (HaveWave32 && HaveWave64) {
     ErrorMsg = "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive";
+    IsCombinationError = true;
+    return false;
+  }
+  if (HaveWave32 && !IsNullGPU && !IsWave32Capable) {
+    ErrorMsg = "wavefrontsize32";
+    IsCombinationError = false;
     return false;
   }
   // Don't assume any wavesize with an unknown subtarget.

Copy link

github-actions bot commented Jul 9, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@shiltian shiltian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG. Thanks.

@rampitec rampitec merged commit f363e30 into llvm:main Jul 9, 2024
5 of 6 checks passed
@rampitec rampitec deleted the clang-invalid-wavesize branch July 9, 2024 21:26
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 9, 2024

LLVM Buildbot has detected a new failure on builder ppc64le-flang-rhel-clang running on ppc64le-flang-rhel-test while building clang,llvm at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/2114

Here is the relevant piece of the build log for the reference:

Step 5 (build-unified-tree) failure: build (failure)
...
53.159 [18/8/6429] Creating library symlink lib/libLTO.so
53.668 [18/7/6430] Linking CXX executable bin/clang-import-test
53.749 [18/6/6431] Linking CXX executable bin/c-index-test
53.847 [18/5/6432] Linking CXX executable bin/clang-scan-deps
54.324 [18/4/6433] Linking CXX executable bin/clang-repl
54.489 [18/3/6434] Linking CXX executable bin/clang-19
54.503 [17/3/6435] Linking CXX shared library lib/libclang-cpp.so.19.0git
54.504 [16/3/6436] Creating executable symlink bin/clang
54.508 [16/2/6437] Creating library symlink lib/libclang-cpp.so
59.345 [16/1/6438] Building CXX object tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o
FAILED: tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o 
ccache /home/buildbots/llvm-external-buildbots/clang.16.0.1/bin/clang++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/tools/flang/lib/Frontend -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/lib/Frontend -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/tools/flang/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/include -I/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include -isystem /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/../mlir/include -isystem /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/tools/mlir/include -isystem /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/build/tools/clang/include -isystem /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/../clang/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion           -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o -MF tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o.d -o tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o -c /home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/lib/Frontend/CompilerInstance.cpp
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/flang/lib/Frontend/CompilerInstance.cpp:226:44: error: too many arguments to function call, expected 3, have 4
                                           errorMsg)) {
                                           ^~~~~~~~
/home/buildbots/llvm-external-buildbots/workers/ppc64le-flang-rhel-test/ppc64le-flang-rhel-clang-build/llvm-project/llvm/include/llvm/TargetParser/TargetParser.h:187:1: note: 'insertWaveSizeFeature' declared here
insertWaveSizeFeature(StringRef GPU, const Triple &T,
^
1 error generated.
ninja: build stopped: subcommand failed.

rampitec added a commit to rampitec/llvm-project that referenced this pull request Jul 9, 2024
rampitec added a commit that referenced this pull request Jul 9, 2024
@rampitec
Copy link
Collaborator Author

rampitec commented Jul 9, 2024 via email

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 9, 2024

LLVM Buildbot has detected a new failure on builder premerge-monolithic-linux running on premerge-linux-1 while building clang,llvm at step 6 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/2433

Here is the relevant piece of the build log for the reference:

Step 6 (build-unified-tree) failure: build (failure)
...
16.660 [2956/11/227] Linking CXX executable bin/clang-doc
16.660 [2956/10/228] Linking CXX executable bin/arcmt-test
16.665 [2956/9/229] Linking CXX executable bin/clang-include-cleaner
16.704 [2956/8/230] Linking CXX executable bin/clang-installapi
16.709 [2956/7/231] Linking CXX executable bin/clang-refactor
17.083 [2956/6/232] Linking CXX executable bin/clangd-indexer
17.102 [2956/5/233] Linking CXX executable bin/clangd-fuzzer
17.112 [2956/4/234] Linking CXX executable bin/clang-import-test
17.145 [2956/3/235] Linking CXX executable bin/clangd
28.093 [2956/2/236] Building CXX object tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o
FAILED: tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/clang++ -DBUILD_EXAMPLES -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/build/buildbot/premerge-monolithic-linux/build/tools/flang/lib/Frontend -I/build/buildbot/premerge-monolithic-linux/llvm-project/flang/lib/Frontend -I/build/buildbot/premerge-monolithic-linux/llvm-project/flang/include -I/build/buildbot/premerge-monolithic-linux/build/tools/flang/include -I/build/buildbot/premerge-monolithic-linux/build/include -I/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include -isystem /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/../mlir/include -isystem /build/buildbot/premerge-monolithic-linux/build/tools/mlir/include -isystem /build/buildbot/premerge-monolithic-linux/build/tools/clang/include -isystem /build/buildbot/premerge-monolithic-linux/llvm-project/llvm/../clang/include -gmlt -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion           -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o -MF tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o.d -o tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/CompilerInstance.cpp.o -c /build/buildbot/premerge-monolithic-linux/llvm-project/flang/lib/Frontend/CompilerInstance.cpp
/build/buildbot/premerge-monolithic-linux/llvm-project/flang/lib/Frontend/CompilerInstance.cpp:226:44: error: too many arguments to function call, expected 3, have 4
                                           errorMsg)) {
                                           ^~~~~~~~
/build/buildbot/premerge-monolithic-linux/llvm-project/llvm/include/llvm/TargetParser/TargetParser.h:187:1: note: 'insertWaveSizeFeature' declared here
insertWaveSizeFeature(StringRef GPU, const Triple &T,
^
1 error generated.
29.203 [2956/1/237] Building CXX object lib/Target/AMDGPU/AsmParser/CMakeFiles/LLVMAMDGPUAsmParser.dir/AMDGPUAsmParser.cpp.o
ninja: build stopped: subcommand failed.

@rampitec
Copy link
Collaborator Author

rampitec commented Jul 9, 2024

/build/buildbot/premerge-monolithic-linux/llvm-project/flang/lib/Frontend/CompilerInstance.cpp:226:44: error: too many arguments to function call, expected 3, have 4

Fixed.

aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants