Skip to content

Conversation

andykaylor
Copy link
Contributor

CIR uses aliases for standard integer types and void. This change adds upstream support for those aliases and updates existing tests.

@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Mar 18, 2025
@andykaylor
Copy link
Contributor Author

cc: @mmha

@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2025

@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Andy Kaylor (andykaylor)

Changes

CIR uses aliases for standard integer types and void. This change adds upstream support for those aliases and updates existing tests.


Patch is 50.47 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/131912.diff

17 Files Affected:

  • (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+14)
  • (modified) clang/test/CIR/CodeGen/array.cpp (+9-9)
  • (modified) clang/test/CIR/CodeGen/basic.c (+15-15)
  • (modified) clang/test/CIR/CodeGen/basic.cpp (+20-20)
  • (modified) clang/test/CIR/CodeGen/cast.cpp (+18-18)
  • (modified) clang/test/CIR/CodeGen/local-vars.cpp (+14-14)
  • (modified) clang/test/CIR/CodeGen/unary-expr-or-type-trait.cpp (+14-14)
  • (modified) clang/test/CIR/CodeGen/unary.cpp (+27-27)
  • (modified) clang/test/CIR/IR/array.cir (+24-22)
  • (modified) clang/test/CIR/IR/cast.cir (+4-4)
  • (modified) clang/test/CIR/IR/func.cir (+35-30)
  • (modified) clang/test/CIR/IR/global-var-linkage.cir (+12-10)
  • (modified) clang/test/CIR/IR/global.cir (+54-42)
  • (modified) clang/test/CIR/Transforms/scope.cir (+24-22)
  • (modified) clang/test/CIR/func-simple.cpp (+15-15)
  • (modified) clang/test/CIR/global-var-simple.cpp (+22-22)
  • (modified) clang/test/CMakeLists.txt (+2-1)
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 56247e2466350..45f9cee83d9da 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -31,6 +31,20 @@ struct CIROpAsmDialectInterface : public OpAsmDialectInterface {
   using OpAsmDialectInterface::OpAsmDialectInterface;
 
   AliasResult getAlias(Type type, raw_ostream &os) const final {
+    if (auto intType = dyn_cast<cir::IntType>(type)) {
+      // We only provide alias for standard integer types (i.e. integer types
+      // whose width is a power of 2 and at least 8).
+      unsigned width = intType.getWidth();
+      if (width < 8 || !llvm::isPowerOf2_32(width))
+        return AliasResult::NoAlias;
+      os << intType.getAlias();
+      return AliasResult::OverridableAlias;
+    }
+    if (auto voidType = dyn_cast<cir::VoidType>(type)) {
+      os << voidType.getAlias();
+      return AliasResult::OverridableAlias;
+    }
+
     return AliasResult::NoAlias;
   }
 
diff --git a/clang/test/CIR/CodeGen/array.cpp b/clang/test/CIR/CodeGen/array.cpp
index 02ecdc11e1d94..f80f64115878d 100644
--- a/clang/test/CIR/CodeGen/array.cpp
+++ b/clang/test/CIR/CodeGen/array.cpp
@@ -1,26 +1,26 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o - 2>&1 | FileCheck %s
 
 int a[10];
-// CHECK: cir.global external @a : !cir.array<!cir.int<s, 32> x 10>
+// CHECK: cir.global external @a : !cir.array<!s32i x 10>
 
 int aa[10][5];
-// CHECK: cir.global external @aa : !cir.array<!cir.array<!cir.int<s, 32> x 5> x 10>
+// CHECK: cir.global external @aa : !cir.array<!cir.array<!s32i x 5> x 10>
 
 extern int b[10];
-// CHECK: cir.global external @b : !cir.array<!cir.int<s, 32> x 10>
+// CHECK: cir.global external @b : !cir.array<!s32i x 10>
 
 extern int bb[10][5];
-// CHECK: cir.global external @bb : !cir.array<!cir.array<!cir.int<s, 32> x 5> x 10>
+// CHECK: cir.global external @bb : !cir.array<!cir.array<!s32i x 5> x 10>
 
 void f() {
   int l[10];
-  // CHECK: %[[ARR:.*]] = cir.alloca !cir.array<!cir.int<s, 32> x 10>, !cir.ptr<!cir.array<!cir.int<s, 32> x 10>>, ["l"]
+  // CHECK: %[[ARR:.*]] = cir.alloca !cir.array<!s32i x 10>, !cir.ptr<!cir.array<!s32i x 10>>, ["l"]
 }
 
 void f2(int p[10]) {}
-// CHECK: cir.func @f2(%arg0: !cir.ptr<!cir.int<s, 32>>
-// CHECK: cir.alloca !cir.ptr<!cir.int<s, 32>>, !cir.ptr<!cir.ptr<!cir.int<s, 32>>>, ["p", init]
+// CHECK: cir.func @f2(%arg0: !cir.ptr<!s32i>
+// CHECK: cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["p", init]
 
 void f3(int pp[10][5]) {}
-// CHECK: cir.func @f3(%arg0: !cir.ptr<!cir.array<!cir.int<s, 32> x 5>>
-// CHECK: cir.alloca !cir.ptr<!cir.array<!cir.int<s, 32> x 5>>, !cir.ptr<!cir.ptr<!cir.array<!cir.int<s, 32> x 5>>>
+// CHECK: cir.func @f3(%arg0: !cir.ptr<!cir.array<!s32i x 5>>
+// CHECK: cir.alloca !cir.ptr<!cir.array<!s32i x 5>>, !cir.ptr<!cir.ptr<!cir.array<!s32i x 5>>>
diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c
index 754f11f1361ba..b07addf78ff28 100644
--- a/clang/test/CIR/CodeGen/basic.c
+++ b/clang/test/CIR/CodeGen/basic.c
@@ -13,12 +13,12 @@ int f1(int i) {
 }
 
 //      CIR: module
-// CIR-NEXT: cir.func @f1(%arg0: !cir.int<s, 32> loc({{.*}})) -> !cir.int<s, 32>
-// CIR-NEXT:   %[[I_PTR:.*]] = cir.alloca !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>, ["i", init] {alignment = 4 : i64}
-// CIR-NEXT:   cir.store %arg0, %[[I_PTR]] : !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>
-// CIR-NEXT:   %[[I_IGNORED:.*]] = cir.load %[[I_PTR]] : !cir.ptr<!cir.int<s, 32>>, !cir.int<s, 32>
-// CIR-NEXT:   %[[I:.*]] = cir.load %[[I_PTR]] : !cir.ptr<!cir.int<s, 32>>, !cir.int<s, 32>
-// CIR-NEXT:   cir.return %[[I]] : !cir.int<s, 32>
+// CIR-NEXT: cir.func @f1(%arg0: !s32i loc({{.*}})) -> !s32i
+// CIR-NEXT:   %[[I_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64}
+// CIR-NEXT:   cir.store %arg0, %[[I_PTR]] : !s32i, !cir.ptr<!s32i>
+// CIR-NEXT:   %[[I_IGNORED:.*]] = cir.load %[[I_PTR]] : !cir.ptr<!s32i>, !s32i
+// CIR-NEXT:   %[[I:.*]] = cir.load %[[I_PTR]] : !cir.ptr<!s32i>, !s32i
+// CIR-NEXT:   cir.return %[[I]] : !s32i
 
 //      LLVM: define i32 @f1(i32 %[[I:.*]])
 // LLVM-NEXT:   %[[I_PTR:.*]] = alloca i32, i64 1, align 4
@@ -37,9 +37,9 @@ int f1(int i) {
 
 int f2(void) { return 3; }
 
-//      CIR: cir.func @f2() -> !cir.int<s, 32>
-// CIR-NEXT:   %[[THREE:.*]] = cir.const #cir.int<3> : !cir.int<s, 32>
-// CIR-NEXT:   cir.return %[[THREE]] : !cir.int<s, 32>
+//      CIR: cir.func @f2() -> !s32i
+// CIR-NEXT:   %[[THREE:.*]] = cir.const #cir.int<3> : !s32i
+// CIR-NEXT:   cir.return %[[THREE]] : !s32i
 
 //      LLVM: define i32 @f2()
 // LLVM-NEXT:   ret i32 3
@@ -53,12 +53,12 @@ int f3(void) {
   return i;
 }
 
-//      CIR: cir.func @f3() -> !cir.int<s, 32>
-// CIR-NEXT:   %[[I_PTR:.*]] = cir.alloca !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>, ["i", init] {alignment = 4 : i64}
-// CIR-NEXT:   %[[THREE:.*]] = cir.const #cir.int<3> : !cir.int<s, 32>
-// CIR-NEXT:   cir.store %[[THREE]], %[[I_PTR]] : !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>
-// CIR-NEXT:   %[[I:.*]] = cir.load %[[I_PTR]] : !cir.ptr<!cir.int<s, 32>>, !cir.int<s, 32>
-// CIR-NEXT:   cir.return %[[I]] : !cir.int<s, 32>
+//      CIR: cir.func @f3() -> !s32i
+// CIR-NEXT:   %[[I_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64}
+// CIR-NEXT:   %[[THREE:.*]] = cir.const #cir.int<3> : !s32i
+// CIR-NEXT:   cir.store %[[THREE]], %[[I_PTR]] : !s32i, !cir.ptr<!s32i>
+// CIR-NEXT:   %[[I:.*]] = cir.load %[[I_PTR]] : !cir.ptr<!s32i>, !s32i
+// CIR-NEXT:   cir.return %[[I]] : !s32i
 
 //      LLVM: define i32 @f3()
 // LLVM-NEXT:   %[[I_PTR:.*]] = alloca i32, i64 1, align 4
diff --git a/clang/test/CIR/CodeGen/basic.cpp b/clang/test/CIR/CodeGen/basic.cpp
index ef922cc2b46fc..1406646785a7e 100644
--- a/clang/test/CIR/CodeGen/basic.cpp
+++ b/clang/test/CIR/CodeGen/basic.cpp
@@ -6,39 +6,39 @@ int f1() {
 }
 
 // CHECK: module
-// CHECK: cir.func @f1() -> !cir.int<s, 32>
-// CHECK:    %[[I_PTR:.*]] = cir.alloca !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>, ["i"] {alignment = 4 : i64}
-// CHECK:    %[[I:.*]] = cir.load %[[I_PTR]] : !cir.ptr<!cir.int<s, 32>>, !cir.int<s, 32>
-// CHECK:    cir.return %[[I]] : !cir.int<s, 32>
+// CHECK: cir.func @f1() -> !s32i
+// CHECK:    %[[I_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i"] {alignment = 4 : i64}
+// CHECK:    %[[I:.*]] = cir.load %[[I_PTR]] : !cir.ptr<!s32i>, !s32i
+// CHECK:    cir.return %[[I]] : !s32i
 
 int f2() {
   const int i = 2;
   return i;
 }
 
-// CHECK: cir.func @f2() -> !cir.int<s, 32>
-// CHECK:    %[[I_PTR:.*]] = cir.alloca !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>, ["i", init, const] {alignment = 4 : i64}
-// CHECK:    %[[TWO:.*]] = cir.const #cir.int<2> : !cir.int<s, 32>
-// CHECK:    cir.store %[[TWO]], %[[I_PTR]] : !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>
-// CHECK:    %[[I:.*]] = cir.load %[[I_PTR]] : !cir.ptr<!cir.int<s, 32>>, !cir.int<s, 32>
-// CHECK:    cir.return %[[I]] : !cir.int<s, 32>
+// CHECK: cir.func @f2() -> !s32i
+// CHECK:    %[[I_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init, const] {alignment = 4 : i64}
+// CHECK:    %[[TWO:.*]] = cir.const #cir.int<2> : !s32i
+// CHECK:    cir.store %[[TWO]], %[[I_PTR]] : !s32i, !cir.ptr<!s32i>
+// CHECK:    %[[I:.*]] = cir.load %[[I_PTR]] : !cir.ptr<!s32i>, !s32i
+// CHECK:    cir.return %[[I]] : !s32i
 
 int f3(int i) {
   return i;
 }
 
-// CHECK: cir.func @f3(%[[ARG:.*]]: !cir.int<s, 32> loc({{.*}})) -> !cir.int<s, 32>
-// CHECK:   %[[ARG_ALLOCA:.*]] = cir.alloca !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>, ["i", init] {alignment = 4 : i64}
-// CHECK:   cir.store %[[ARG]], %[[ARG_ALLOCA]] : !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>
-// CHECK:   %[[ARG_VAL:.*]] = cir.load %[[ARG_ALLOCA]] : !cir.ptr<!cir.int<s, 32>>, !cir.int<s, 32>
-// CHECK:   cir.return %[[ARG_VAL]] : !cir.int<s, 32>
+// CHECK: cir.func @f3(%[[ARG:.*]]: !s32i loc({{.*}})) -> !s32i
+// CHECK:   %[[ARG_ALLOCA:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64}
+// CHECK:   cir.store %[[ARG]], %[[ARG_ALLOCA]] : !s32i, !cir.ptr<!s32i>
+// CHECK:   %[[ARG_VAL:.*]] = cir.load %[[ARG_ALLOCA]] : !cir.ptr<!s32i>, !s32i
+// CHECK:   cir.return %[[ARG_VAL]] : !s32i
 
 int f4(const int i) {
   return i;
 }
 
-// CHECK: cir.func @f4(%[[ARG:.*]]: !cir.int<s, 32> loc({{.*}})) -> !cir.int<s, 32>
-// CHECK:   %[[ARG_ALLOCA:.*]] = cir.alloca !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>, ["i", init, const] {alignment = 4 : i64}
-// CHECK:   cir.store %[[ARG]], %[[ARG_ALLOCA]] : !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>
-// CHECK:   %[[ARG_VAL:.*]] = cir.load %[[ARG_ALLOCA]] : !cir.ptr<!cir.int<s, 32>>, !cir.int<s, 32>
-// CHECK:   cir.return %[[ARG_VAL]] : !cir.int<s, 32>
+// CHECK: cir.func @f4(%[[ARG:.*]]: !s32i loc({{.*}})) -> !s32i
+// CHECK:   %[[ARG_ALLOCA:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init, const] {alignment = 4 : i64}
+// CHECK:   cir.store %[[ARG]], %[[ARG_ALLOCA]] : !s32i, !cir.ptr<!s32i>
+// CHECK:   %[[ARG_VAL:.*]] = cir.load %[[ARG_ALLOCA]] : !cir.ptr<!s32i>, !s32i
+// CHECK:   cir.return %[[ARG_VAL]] : !s32i
diff --git a/clang/test/CIR/CodeGen/cast.cpp b/clang/test/CIR/CodeGen/cast.cpp
index b25a0cdb4b055..198028d077993 100644
--- a/clang/test/CIR/CodeGen/cast.cpp
+++ b/clang/test/CIR/CodeGen/cast.cpp
@@ -8,11 +8,11 @@ unsigned char cxxstaticcast_0(unsigned int x) {
 }
 
 // CIR: cir.func @cxxstaticcast_0
-// CIR:    %[[XPTR:[0-9]+]] = cir.alloca !cir.int<u, 32>, !cir.ptr<!cir.int<u, 32>>, ["x", init] {alignment = 4 : i64}
-// CIR:    cir.store %arg0, %[[XPTR]] : !cir.int<u, 32>, !cir.ptr<!cir.int<u, 32>>
-// CIR:    %[[XVAL:[0-9]+]] = cir.load %[[XPTR]] : !cir.ptr<!cir.int<u, 32>>, !cir.int<u, 32>
-// CIR:    %[[CASTED:[0-9]+]] = cir.cast(integral, %[[XVAL]] : !cir.int<u, 32>), !cir.int<u, 8>
-// CIR:    cir.return %[[CASTED]] : !cir.int<u, 8>
+// CIR:    %[[XPTR:[0-9]+]] = cir.alloca !u32i, !cir.ptr<!u32i>, ["x", init] {alignment = 4 : i64}
+// CIR:    cir.store %arg0, %[[XPTR]] : !u32i, !cir.ptr<!u32i>
+// CIR:    %[[XVAL:[0-9]+]] = cir.load %[[XPTR]] : !cir.ptr<!u32i>, !u32i
+// CIR:    %[[CASTED:[0-9]+]] = cir.cast(integral, %[[XVAL]] : !u32i), !u8i
+// CIR:    cir.return %[[CASTED]] : !u8i
 // CIR:  }
 
 // LLVM: define i8 @cxxstaticcast_0(i32 %{{[0-9]+}})
@@ -26,41 +26,41 @@ int cStyleCasts_0(unsigned x1, int x2, float x3, short x4, double x5) {
 // LLVM: define i32 @cStyleCasts_0
 
   char a = (char)x1; // truncate
-  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !cir.int<u, 32>), !cir.int<s, 8>
+  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !u32i), !s8i
   // LLVM: %{{[0-9]+}} = trunc i32 %{{[0-9]+}} to i8
 
   short b = (short)x2; // truncate with sign
-  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !cir.int<s, 32>), !cir.int<s, 16>
+  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !s32i), !s16i
   // LLVM: %{{[0-9]+}} = trunc i32 %{{[0-9]+}} to i16
 
   long long c = (long long)x1; // zero extend
-  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !cir.int<u, 32>), !cir.int<s, 64>
+  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !u32i), !s64i
   // LLVM: %{{[0-9]+}} = zext i32 %{{[0-9]+}} to i64
 
   long long d = (long long)x2; // sign extend
-  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !cir.int<s, 32>), !cir.int<s, 64>
+  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !s32i), !s64i
   // LLVM: %{{[0-9]+}} = sext i32 %{{[0-9]+}} to i64
 
   unsigned ui = (unsigned)x2; // sign drop
-  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !cir.int<s, 32>), !cir.int<u, 32>
+  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !s32i), !u32i
 
   int si = (int)x1; // sign add
-  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !cir.int<u, 32>), !cir.int<s, 32>
+  // CIR: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !u32i), !s32i
 
   bool ib;
   int bi = (int)ib; // bool to int
-  // CIR: %{{[0-9]+}} = cir.cast(bool_to_int, %{{[0-9]+}} : !cir.bool), !cir.int<s, 32>
+  // CIR: %{{[0-9]+}} = cir.cast(bool_to_int, %{{[0-9]+}} : !cir.bool), !s32i
   // LLVM: %{{[0-9]+}} = zext i1 %{{[0-9]+}} to i32
 
   #ifdef CIR_ONLY
   bool b2 = x2; // int to bool
-  // CIR: %{{[0-9]+}} = cir.cast(int_to_bool, %{{[0-9]+}} : !cir.int<s, 32>), !cir.bool
+  // CIR: %{{[0-9]+}} = cir.cast(int_to_bool, %{{[0-9]+}} : !s32i), !cir.bool
   #endif
 
   #ifdef CIR_ONLY
   void *p;
    bool b3 = p; // ptr to bool
-  // CIR: %{{[0-9]+}} = cir.cast(ptr_to_bool, %{{[0-9]+}} : !cir.ptr<!cir.void>), !cir.bool
+  // CIR: %{{[0-9]+}} = cir.cast(ptr_to_bool, %{{[0-9]+}} : !cir.ptr<!void>), !cir.bool
   #endif
 
   float f;
@@ -78,11 +78,11 @@ bool cptr(void *d) {
   return x;
 }
 
-// CIR: cir.func @cptr(%arg0: !cir.ptr<!cir.void>
-// CIR:   %[[DPTR:[0-9]+]] = cir.alloca !cir.ptr<!cir.void>, !cir.ptr<!cir.ptr<!cir.void>>, ["d", init] {alignment = 8 : i64}
+// CIR: cir.func @cptr(%arg0: !cir.ptr<!void>
+// CIR:   %[[DPTR:[0-9]+]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["d", init] {alignment = 8 : i64}
 
-// CIR:   %[[DVAL:[0-9]+]] = cir.load %[[DPTR]] : !cir.ptr<!cir.ptr<!cir.void>>, !cir.ptr<!cir.void>
-// CIR:   %{{[0-9]+}} = cir.cast(ptr_to_bool, %[[DVAL]] : !cir.ptr<!cir.void>), !cir.bool
+// CIR:   %[[DVAL:[0-9]+]] = cir.load %[[DPTR]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
+// CIR:   %{{[0-9]+}} = cir.cast(ptr_to_bool, %[[DVAL]] : !cir.ptr<!void>), !cir.bool
 #endif
 
 void should_not_cast() {
diff --git a/clang/test/CIR/CodeGen/local-vars.cpp b/clang/test/CIR/CodeGen/local-vars.cpp
index 14be8f4da902b..6e9f8c39b107f 100644
--- a/clang/test/CIR/CodeGen/local-vars.cpp
+++ b/clang/test/CIR/CodeGen/local-vars.cpp
@@ -22,27 +22,27 @@ void test() {
 
 // CHECK: module
 // CHECK: cir.func @test()
-// CHECK:    %[[I_PTR:.*]] = cir.alloca !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>, ["i", init] {alignment = 4 : i64}
-// CHECK:    %[[L_PTR:.*]] = cir.alloca !cir.int<s, 64>, !cir.ptr<!cir.int<s, 64>>, ["l", init] {alignment = 8 : i64}
+// CHECK:    %[[I_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] {alignment = 4 : i64}
+// CHECK:    %[[L_PTR:.*]] = cir.alloca !s64i, !cir.ptr<!s64i>, ["l", init] {alignment = 8 : i64}
 // CHECK:    %[[F_PTR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["f", init] {alignment = 4 : i64}
 // CHECK:    %[[D_PTR:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["d", init] {alignment = 8 : i64}
 // CHECK:    %[[B1_PTR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b1", init] {alignment = 1 : i64}
 // CHECK:    %[[B2_PTR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b2", init] {alignment = 1 : i64}
-// CHECK:    %[[CI_PTR:.*]] = cir.alloca !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>, ["ci", init, const] {alignment = 4 : i64}
-// CHECK:    %[[CL_PTR:.*]] = cir.alloca !cir.int<s, 64>, !cir.ptr<!cir.int<s, 64>>, ["cl", init, const] {alignment = 8 : i64}
+// CHECK:    %[[CI_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["ci", init, const] {alignment = 4 : i64}
+// CHECK:    %[[CL_PTR:.*]] = cir.alloca !s64i, !cir.ptr<!s64i>, ["cl", init, const] {alignment = 8 : i64}
 // CHECK:    %[[CF_PTR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["cf", init, const] {alignment = 4 : i64}
 // CHECK:    %[[CD_PTR:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["cd", init, const] {alignment = 8 : i64}
 // CHECK:    %[[CB1_PTR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["cb1", init, const] {alignment = 1 : i64}
 // CHECK:    %[[CB2_PTR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["cb2", init, const] {alignment = 1 : i64}
-// CHECK:    %[[UII_PTR:.*]] = cir.alloca !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>, ["uii"] {alignment = 4 : i64}
-// CHECK:    %[[UIL_PTR:.*]] = cir.alloca !cir.int<s, 64>, !cir.ptr<!cir.int<s, 64>>, ["uil"] {alignment = 8 : i64}
+// CHECK:    %[[UII_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["uii"] {alignment = 4 : i64}
+// CHECK:    %[[UIL_PTR:.*]] = cir.alloca !s64i, !cir.ptr<!s64i>, ["uil"] {alignment = 8 : i64}
 // CHECK:    %[[UIF_PTR:.*]] = cir.alloca !cir.float, !cir.ptr<!cir.float>, ["uif"] {alignment = 4 : i64}
 // CHECK:    %[[UID_PTR:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["uid"] {alignment = 8 : i64}
 // CHECK:    %[[UIB_PTR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["uib"] {alignment = 1 : i64}
-// CHECK:    %[[ONE:.*]] = cir.const #cir.int<1> : !cir.int<s, 32>
-// CHECK:    cir.store %[[ONE]], %[[I_PTR]] : !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>
-// CHECK:    %[[TWO:.*]] = cir.const #cir.int<2> : !cir.int<s, 64>
-// CHECK:    cir.store %[[TWO]], %[[L_PTR]] : !cir.int<s, 64>, !cir.ptr<!cir.int<s, 64>>
+// CHECK:    %[[ONE:.*]] = cir.const #cir.int<1> : !s32i
+// CHECK:    cir.store %[[ONE]], %[[I_PTR]] : !s32i, !cir.ptr<!s32i>
+// CHECK:    %[[TWO:.*]] = cir.const #cir.int<2> : !s64i
+// CHECK:    cir.store %[[TWO]], %[[L_PTR]] : !s64i, !cir.ptr<!s64i>
 // CHECK:    %[[THREE:.*]] = cir.const #cir.fp<3.0{{.*}}> : !cir.float
 // CHECK:    cir.store %[[THREE]], %[[F_PTR]] : !cir.float, !cir.ptr<!cir.float>
 // CHECK:    %[[FOUR:.*]] = cir.const #cir.fp<4.0{{.*}}> : !cir.double
@@ -51,10 +51,10 @@ void test() {
 // CHECK:    cir.store %[[TRUE]], %[[B1_PTR]] : !cir.bool, !cir.ptr<!cir.bool>
 // CHECK:    %[[FALSE:.*]] = cir.const #false
 // CHECK:    cir.store %[[FALSE]], %[[B2_PTR]] : !cir.bool, !cir.ptr<!cir.bool>
-// CHECK:    %[[ONEC:.*]] = cir.const #cir.int<1> : !cir.int<s, 32>
-// CHECK:    cir.store %[[ONEC]], %[[CI_PTR]] : !cir.int<s, 32>, !cir.ptr<!cir.int<s, 32>>
-// CHECK:    %[[TWOC:.*]] = cir.const #cir.int<2> : !cir.int<s, 64>
-// CHECK:    cir.store %[[TWOC]], %[[CL_PTR]] : !cir.int<s, 64>, !cir.ptr<!cir.int<s, 64>>
+// CHECK:    %[[ONEC:.*]] = cir.const #cir.int<1> : !s32i
+// CHECK:    cir.store %[[ONEC]], %[[CI_PTR]] : !s32i, !cir.ptr<!s32i>
+// CHECK:    %[[TWOC:.*]] = cir.const #cir.int<2> : !s64i
+// CHECK:    cir.store %[[TWOC]], %[[CL_PTR]] : !s64i, !cir.ptr<!s64i>
 // CHECK:    %[[THREEC:.*]] = cir.const #cir.fp<3.0{{.*}}> : !cir.float
 // CHECK:    cir.store %[[THREEC]], %[[CF_PTR]] : !cir.float, !cir.ptr<!cir.float>
 // CHECK:    %[[FOURC:.*]] = cir.const #cir.fp<4.0{{.*}}> : !cir.double
diff --git a/clang/test/CIR/CodeGen/unary-expr-or-type-trait.cpp b/clang/test/CIR/CodeGen/unary-expr-or-type-trait.cpp
index fe5e5b434a3f1..071c52a0918e3 100644
--- a/clang/test/CIR/CodeGen/unary-expr-or-type-trait.cpp
+++ b/clang/test/CIR/CodeGen/unary-expr-or-type-trait.cpp
@@ -2,46 +2,46 @@
 
 void foo() {
   unsigned long b = sizeof(bool);
-  // CHECK: cir.const #cir.int<1> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<1> : !u64i
 
   unsigned long i = sizeof(int);
-  // CHECK: cir.const #cir.int<4> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<4> : !u64i
 
   unsigned long l =  sizeof(long);
-  // CHECK: cir.const #cir.int<8> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<8> : !u64i
 
   unsigned long f =  sizeof(float);
-  // CHECK: cir.const #cir.int<4> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<4> : !u64i
 
   unsigned long d =  sizeof(double);
-  // CHECK: cir.const #cir.int<8> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<8> : !u64i
 
   unsigned long iArr = sizeof(int[5]);
-  // CHECK: cir.const #cir.int<20> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<20> : !u64i
 
   unsigned long dArr =  sizeof(double[5]);
-  // CHECK: cir.const #cir.int<40> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<40> : !u64i
 }
 
 void foo2() {
   unsigned long b = alignof(bool);
-  // CHECK: cir.const #cir.int<1> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<1> : !u64i
 
   unsigned long i = alignof(int);
-  // CHECK: cir.const #cir.int<4> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<4> : !u64i
 
   unsigned long l =  alignof(long);
-  // CHECK: cir.const #cir.int<8> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<8> : !u64i
 
   unsigned long f =  alignof(float);
-  // CHECK: cir.const #cir.int<4> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<4> : !u64i
 
   unsigned long d =  alignof(double);
-  // CHECK: cir.const #cir.int<8> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<8> : !u64i
 
   unsigned long iArr = alignof(int[5]);
-  // CHECK: cir.const #cir.int<4> : !cir.int<u, 64>
+  // CHECK: cir.const #cir.int<4> : !u64i
 
   unsigned long dArr =  alignof(double[5]);
-  // CHECK: cir.const #cir.int<8> : !cir.int<u, 64>
+  // CHEC...
[truncated]

@@ -31,6 +31,20 @@ struct CIROpAsmDialectInterface : public OpAsmDialectInterface {
using OpAsmDialectInterface::OpAsmDialectInterface;

AliasResult getAlias(Type type, raw_ostream &os) const final {
if (auto intType = dyn_cast<cir::IntType>(type)) {
// We only provide alias for standard integer types (i.e. integer types
// whose width is a power of 2 and at least 8).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The incubator is only checking width % 8 == 0, but that creates aliases for things like !cir.int<s, 48>, which I don't think is what was intended.

Copy link
Member

Choose a reason for hiding this comment

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

Makes total sense.

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.

No concerns on this one, but let the others review, particularly for the chagne in the incubator.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -31,6 +31,20 @@ struct CIROpAsmDialectInterface : public OpAsmDialectInterface {
using OpAsmDialectInterface::OpAsmDialectInterface;

AliasResult getAlias(Type type, raw_ostream &os) const final {
if (auto intType = dyn_cast<cir::IntType>(type)) {
// We only provide alias for standard integer types (i.e. integer types
// whose width is a power of 2 and at least 8).
Copy link
Member

Choose a reason for hiding this comment

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

Makes total sense.

@@ -1,5 +1,5 @@
# Test runner infrastructure for Clang. This configures the Clang test trees
# for use by Lit, and delegates to LLVM's lit test handlers.
# for use by Lit, and delegates to LLVM's lit test handlers.int
Copy link
Contributor

Choose a reason for hiding this comment

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

copy/paste error?

@@ -89,6 +89,7 @@ list(APPEND CLANG_TEST_DEPS
if(CLANG_ENABLE_CIR)
list(APPEND CLANG_TEST_DEPS
cir-opt
cir-translate
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! I missed that. I can see that the incubator has mlir-translate as a dependency, too. Should we add this now as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That won't be needed until we upstream one of the tests that uses it. Those are all in the Lowering/ThroughMLIR directory, which we won't be adding for a while.

CIR uses aliases for standard integer types and void. This change adds
upstream support for those aliases and updates existing tests.

This also updates a few tests that were out of step with the canonicalize
pass running.
@andykaylor andykaylor merged commit 93afd8f into llvm:main Mar 19, 2025
7 of 10 checks passed
@andykaylor andykaylor deleted the cir-type-aliases branch April 10, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants