Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Clang] Allow vector and matrix type attributes for sub-byte _BitInt #140253

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from

Conversation

MrSidims
Copy link
Contributor

@MrSidims MrSidims commented May 16, 2025

It is useful for several cases, particularly for 4-bit integers.

Signed-off-by: Sidorov, Dmitry <dmitry.sidorov@intel.com>
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 16, 2025
@llvmbot
Copy link
Member

llvmbot commented May 16, 2025

@llvm/pr-subscribers-clang

Author: Dmitry Sidorov (MrSidims)

Changes

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

4 Files Affected:

  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-2)
  • (modified) clang/lib/Sema/SemaType.cpp (+2-2)
  • (modified) clang/test/SemaCXX/ext-int.cpp (+2-10)
  • (modified) clang/test/SemaCXX/matrix-type.cpp (+1-2)
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f0bd5a1174020..9f20c07882901 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3257,8 +3257,7 @@ def err_attribute_too_few_arguments : Error<
   "%0 attribute takes at least %1 argument%s1">;
 def err_attribute_invalid_vector_type : Error<"invalid vector element type %0">;
 def err_attribute_invalid_bitint_vector_type : Error<
-  "'_BitInt' %select{vector|matrix}0 element width must be %select{a power of 2|"
-  "at least as wide as 'CHAR_BIT'}1">;
+  "'_BitInt' %select{vector|matrix}0 element width must be a power of 2">;
 def err_attribute_invalid_matrix_type : Error<"invalid matrix element type %0">;
 def err_attribute_bad_neon_vector_size : Error<
   "Neon vector size must be 64 or 128 bits">;
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 9ed2326f151a3..28d441234262b 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2321,9 +2321,9 @@ static bool CheckBitIntElementType(Sema &S, SourceLocation AttrLoc,
                                    bool ForMatrixType = false) {
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
   unsigned NumBits = BIT->getNumBits();
-  if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8)
+  if (!llvm::isPowerOf2_32(NumBits))
     return S.Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
-           << ForMatrixType << (NumBits < 8);
+           << ForMatrixType;
   return false;
 }
 
diff --git a/clang/test/SemaCXX/ext-int.cpp b/clang/test/SemaCXX/ext-int.cpp
index d974221e774a7..5c566dafed931 100644
--- a/clang/test/SemaCXX/ext-int.cpp
+++ b/clang/test/SemaCXX/ext-int.cpp
@@ -84,17 +84,9 @@ struct is_same<T,T> {
 };
 
 // Reject vector types:
-// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
-typedef _BitInt(2) __attribute__((vector_size(16))) VecTy;
-// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
-typedef _BitInt(2) __attribute__((ext_vector_type(32))) OtherVecTy;
-// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
-typedef _BitInt(4) __attribute__((vector_size(16))) VecTy2;
-// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
-typedef _BitInt(4) __attribute__((ext_vector_type(32))) OtherVecTy2;
-// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+// expected-error@+1{{'_BitInt' vector element width must be a power of 2}}
 typedef _BitInt(5) __attribute__((vector_size(16))) VecTy3;
-// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+// expected-error@+1{{'_BitInt' vector element width must be a power of 2}}
 typedef _BitInt(5) __attribute__((ext_vector_type(32))) OtherVecTy3;
 // expected-error@+1{{'_BitInt' vector element width must be a power of 2}}
 typedef _BitInt(37) __attribute__((vector_size(16))) VecTy4;
diff --git a/clang/test/SemaCXX/matrix-type.cpp b/clang/test/SemaCXX/matrix-type.cpp
index bb7a8421ca9e3..186d3b6b35208 100644
--- a/clang/test/SemaCXX/matrix-type.cpp
+++ b/clang/test/SemaCXX/matrix-type.cpp
@@ -31,8 +31,7 @@ void matrix_unsupported_element_type() {
 }
 
 void matrix_unsupported_bit_int() {
-  using m1 = _BitInt(2) __attribute__((matrix_type(4, 4))); // expected-error{{'_BitInt' matrix element width must be at least as wide as 'CHAR_BIT'}}
-  using m2 = _BitInt(7) __attribute__((matrix_type(4, 4))); // expected-error{{'_BitInt' matrix element width must be at least as wide as 'CHAR_BIT'}}
+  using m2 = _BitInt(7) __attribute__((matrix_type(4, 4))); // expected-error{{'_BitInt' matrix element width must be a power of 2}}
   using m3 = _BitInt(9) __attribute__((matrix_type(4, 4))); // expected-error{{'_BitInt' matrix element width must be a power of 2}}
   using m4 = _BitInt(12) __attribute__((matrix_type(4, 4))); // expected-error{{'_BitInt' matrix element width must be a power of 2}}
   using m5 = _BitInt(8) __attribute__((matrix_type(4, 4)));

@MrSidims
Copy link
Contributor Author

MrSidims commented May 16, 2025

@erichkeane @AaronBallman please take a look. Limitation that currently clang has seem to be unreasonable. Currently I'm just removing it, but I'm open to introducing a flag, that suppresses the error or make this error be a warning (actually, warning is a bad idea).

Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

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

I don't have a problem with this, but I'd need to see a LOT more tests here. We have this restriction because it wasn't clear whether the semantics work correctly for codegen/llvm backends.

So I'd need to see some codegen tests that show that we're doing the right thing for these, plus some sort of testing that shows that we do the right thing with llvm codegen.

@MrSidims
Copy link
Contributor Author

So I'd need to see some codegen tests that show that we're doing the right thing for these, plus some sort of testing that shows that we do the right thing with llvm codegen.

Sure, I'll work on this.

@erichkeane
Copy link
Collaborator

So I'd need to see some codegen tests that show that we're doing the right thing for these, plus some sort of testing that shows that we do the right thing with llvm codegen.

Sure, I'll work on this.

Thanks! This was really just a "tests would be a PITA to write, so lets restrict it and let someone who cares loosen it" situation, no real good reason otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.