llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: adams381

<details>
<summary>Changes</summary>

Follow-up to #<!-- -->188113 per @<!-- -->erichkeane's feedback about the 
128-bit cap.

CIR's IntType was hard-limited to 128 bits, which meant any _BitInt wider than 
that hit an errorNYI.  LLVM IR goes up to 2^23 (about 8 million bits), and 
there are real tests/users at those sizes.  This raises CIR's limit to match 
and drops the guard that was working around it.

Tests: added a _BitInt(256) global to bitint.c and a 1024-bit round-trip to 
bitint.cir.

Made with [Cursor](https://cursor.com)

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


4 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIRTypes.td (+3-2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenTypes.cpp (+3-8) 
- (modified) clang/test/CIR/CodeGen/bitint.c (+5) 
- (modified) clang/test/CIR/IR/bitint.cir (+3-2) 


``````````diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index b177eab08ccad..c0ed674a7e993 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -90,8 +90,9 @@ def CIR_IntType : CIR_Type<"Int", "int", [
 
     /// Returns a minimum bitwidth of cir::IntType
     static unsigned minBitwidth() { return 1; }
-    /// Returns a maximum bitwidth of cir::IntType
-    static unsigned maxBitwidth() { return 128; }
+    /// Returns a maximum bitwidth of cir::IntType.
+    /// Matches llvm::IntegerType::MAX_INT_BITS (1 << 23).
+    static unsigned maxBitwidth() { return (1 << 23); }
   }];
   let genVerifyDecl = 1;
 }
diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp 
b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
index 9b493263b76c2..3ee8f15c5467b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
@@ -563,14 +563,9 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
 
   case Type::BitInt: {
     const auto *bitIntTy = cast<BitIntType>(type);
-    if (bitIntTy->getNumBits() > cir::IntType::maxBitwidth()) {
-      cgm.errorNYI(SourceLocation(), "large _BitInt type", type);
-      resultType = cgm.sInt32Ty;
-    } else {
-      resultType = cir::IntType::get(&getMLIRContext(), bitIntTy->getNumBits(),
-                                     bitIntTy->isSigned(),
-                                     /*isBitInt=*/true);
-    }
+    resultType = cir::IntType::get(&getMLIRContext(), bitIntTy->getNumBits(),
+                                   bitIntTy->isSigned(),
+                                   /*isBitInt=*/true);
     break;
   }
 
diff --git a/clang/test/CIR/CodeGen/bitint.c b/clang/test/CIR/CodeGen/bitint.c
index 014b315c907ba..6d91986c165ba 100644
--- a/clang/test/CIR/CodeGen/bitint.c
+++ b/clang/test/CIR/CodeGen/bitint.c
@@ -13,19 +13,24 @@
 // CIR-DAG: !s128i_bitint = !cir.int<s, 128, bitint>
 // CIR-DAG: !u64i_bitint = !cir.int<u, 64, bitint>
 // CIR-DAG: !s128i = !cir.int<s, 128>
+// CIR-DAG: !s256i_bitint = !cir.int<s, 256, bitint>
 
 // _BitInt(128) has alignment 8 while __int128 has alignment 16.
 signed _BitInt(128) bitint128_var;
 __int128 int128_var;
+signed _BitInt(256) bitint256_var;
 
 // CIR: cir.global external @bitint128_var = #cir.int<0> : !s128i_bitint 
{alignment = 8 : i64}
 // CIR: cir.global external @int128_var = #cir.int<0> : !s128i {alignment = 16 
: i64}
+// CIR: cir.global external @bitint256_var = #cir.int<0> : !s256i_bitint
 
 // LLVM: @bitint128_var = global i128 0, align 8
 // LLVM: @int128_var = global i128 0, align 16
+// LLVM: @bitint256_var = global i256 0
 
 // OGCG: @bitint128_var = global i128 0, align 8
 // OGCG: @int128_var = global i128 0, align 16
+// OGCG: @bitint256_var = global i256 0
 
 void take_bitint_32(_BitInt(32) x) {}
 // CIR: cir.func {{.*}} @take_bitint_32(%arg0: !s32i_bitint
diff --git a/clang/test/CIR/IR/bitint.cir b/clang/test/CIR/IR/bitint.cir
index 5dddddc833777..c61f1b581b62e 100644
--- a/clang/test/CIR/IR/bitint.cir
+++ b/clang/test/CIR/IR/bitint.cir
@@ -5,10 +5,11 @@
 !s32i_bitint = !cir.int<s, 32, bitint>
 !u64i_bitint = !cir.int<u, 64, bitint>
 !s128i_bitint = !cir.int<s, 128, bitint>
+!s1024i_bitint = !cir.int<s, 1024, bitint>
 
 module {
-  // CHECK: cir.func @round_trip_bitint(%arg0: !s32i_bitint, %arg1: 
!u64i_bitint, %arg2: !s128i_bitint)
-  cir.func @round_trip_bitint(%arg0: !s32i_bitint, %arg1: !u64i_bitint, %arg2: 
!s128i_bitint) {
+  // CHECK: cir.func @round_trip_bitint(%arg0: !s32i_bitint, %arg1: 
!u64i_bitint, %arg2: !s128i_bitint, %arg3: !s1024i_bitint)
+  cir.func @round_trip_bitint(%arg0: !s32i_bitint, %arg1: !u64i_bitint, %arg2: 
!s128i_bitint, %arg3: !s1024i_bitint) {
     cir.return
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/191499
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to