[clang] [CIR] Raise IntType max bitwidth to match LLVM IR (PR #191499)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 10 12:25:08 PDT 2026
https://github.com/adams381 created https://github.com/llvm/llvm-project/pull/191499
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)
>From 069929f7b601258dc2a0de4afd171818571b4ada Mon Sep 17 00:00:00 2001
From: Adam Smith <adams at nvidia.com>
Date: Fri, 10 Apr 2026 12:23:34 -0700
Subject: [PATCH] [CIR] Raise IntType max bitwidth to match LLVM IR
Increase IntType::maxBitwidth() from 128 to 1<<23 (8388608) so CIR
can represent the full range of _BitInt widths that Clang and LLVM IR
support. Remove the now-dead errorNYI guard for large _BitInt in
CIRGenTypes.
Follow-up to #188113 addressing feedback from @erichkeane.
Made-with: Cursor
---
clang/include/clang/CIR/Dialect/IR/CIRTypes.td | 5 +++--
clang/lib/CIR/CodeGen/CIRGenTypes.cpp | 11 +++--------
clang/test/CIR/CodeGen/bitint.c | 5 +++++
clang/test/CIR/IR/bitint.cir | 5 +++--
4 files changed, 14 insertions(+), 12 deletions(-)
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
}
More information about the cfe-commits
mailing list