https://github.com/xakep8 updated 
https://github.com/llvm/llvm-project/pull/218852

>From 6dfe59e0ab23f80344a6d45125e16dd7295c7085 Mon Sep 17 00:00:00 2001
From: Kunal Dubey <[email protected]>
Date: Wed, 26 Aug 2026 12:48:59 +0530
Subject: [PATCH 1/3] [CIR] Added case for builtins in CIRGen

Added case for stdc_rotate_left, stdc_rotate_right and
stdc_memreverse8 so that they don't fall through to isLibFunction path.
Now they emit NYI.
---
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp       | 19 ++++++++++
 .../builtin-stdc-bit-c2y-nyi.c                | 35 +++++++++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y-nyi.c

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index e2fe3adefd4af..e85475814fed4 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -1726,12 +1726,31 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
   case Builtin::BI__builtin_rotateleft32:
   case Builtin::BI__builtin_rotateleft64:
     return emitRotate(e, /*isRotateLeft=*/true);
+  case Builtin::BI__builtin_stdc_rotate_left:
+  case Builtin::BIstdc_rotate_left_uc:
+  case Builtin::BIstdc_rotate_left_us:
+  case Builtin::BIstdc_rotate_left_ui:
+  case Builtin::BIstdc_rotate_left_ul:
+  case Builtin::BIstdc_rotate_left_ull:
+    return errorBuiltinNYI(*this, e, builtinID);
 
   case Builtin::BI__builtin_rotateright8:
   case Builtin::BI__builtin_rotateright16:
   case Builtin::BI__builtin_rotateright32:
   case Builtin::BI__builtin_rotateright64:
     return emitRotate(e, /*isRotateLeft=*/false);
+  case Builtin::BI__builtin_stdc_rotate_right:
+  case Builtin::BIstdc_rotate_right_uc:
+  case Builtin::BIstdc_rotate_right_us:
+  case Builtin::BIstdc_rotate_right_ui:
+  case Builtin::BIstdc_rotate_right_ul:
+  case Builtin::BIstdc_rotate_right_ull:
+  case Builtin::BIstdc_memreverse8:
+  case Builtin::BIstdc_memreverse8u8:
+  case Builtin::BIstdc_memreverse8u16:
+  case Builtin::BIstdc_memreverse8u32:
+  case Builtin::BIstdc_memreverse8u64:
+    return errorBuiltinNYI(*this, e, builtinID);
 
   case Builtin::BI__builtin_coro_id:
     return RValue::get(emitCoroIDBuiltinCall(e).getResult());
diff --git a/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y-nyi.c 
b/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y-nyi.c
new file mode 100644
index 0000000000000..f6dd75f8cbe21
--- /dev/null
+++ b/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y-nyi.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-cir -verify -DSTDC_ROTATE_LEFT %s -o -
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-cir -verify -DSTDC_ROTATE_RIGHT %s -o -
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-cir -verify -DSTDC_MEMREVERSE8 %s -o -
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -emit-llvm %s -o 
- | FileCheck %s --check-prefix=OGCG
+
+unsigned stdc_rotate_left_ui(unsigned, unsigned);
+unsigned stdc_rotate_right_ui(unsigned, unsigned);
+unsigned stdc_memreverse8u32(unsigned);
+
+#if !defined(STDC_ROTATE_RIGHT) && !defined(STDC_MEMREVERSE8)
+unsigned test_stdc_rotate_left_ui(unsigned x) {
+  return stdc_rotate_left_ui(x, 1); // expected-error {{ClangIR code gen Not 
Yet Implemented: unimplemented X86 builtin call: stdc_rotate_left_ui}}
+}
+
+// OGCG-LABEL: define{{.*}} i32 @test_stdc_rotate_left_ui(
+// OGCG: call i32 @llvm.fshl.i32(
+#endif
+
+#if !defined(STDC_ROTATE_LEFT) && !defined(STDC_MEMREVERSE8)
+unsigned test_stdc_rotate_right_ui(unsigned x) {
+  return stdc_rotate_right_ui(x, 1); // expected-error {{ClangIR code gen Not 
Yet Implemented: unimplemented X86 builtin call: stdc_rotate_right_ui}}
+}
+
+// OGCG-LABEL: define{{.*}} i32 @test_stdc_rotate_right_ui(
+// OGCG: call i32 @llvm.fshr.i32(
+#endif
+
+#if !defined(STDC_ROTATE_LEFT) && !defined(STDC_ROTATE_RIGHT)
+unsigned test_stdc_memreverse8u32(unsigned x) {
+  return stdc_memreverse8u32(x); // expected-error {{ClangIR code gen Not Yet 
Implemented: unimplemented X86 builtin call: stdc_memreverse8u32}}
+}
+
+// OGCG-LABEL: define{{.*}} i32 @test_stdc_memreverse8u32(
+// OGCG: call i32 @llvm.bswap.i32(
+#endif

>From c39525268c6078a3021e650bb67e78237fd0994e Mon Sep 17 00:00:00 2001
From: Kunal Dubey <[email protected]>
Date: Wed, 26 Aug 2026 15:09:12 +0530
Subject: [PATCH 2/3] [CIR] Lower C2Y stdc rotate and memreverse builtins

Lowered the C2y stdc_rotate_left/right builtins through cir.rotate, also
lowered stdc_memreverse8u* builtins using cir.byte_swap.

Kept the generic pointer stdc_memreverse8 form as NYI for now.
---
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp       | 17 +++--
 .../builtin-stdc-bit-c2y-nyi.c                | 35 ---------
 .../CodeGenBuiltins/builtin-stdc-bit-c2y.c    | 73 +++++++++++++++++++
 3 files changed, 83 insertions(+), 42 deletions(-)
 delete mode 100644 clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y-nyi.c
 create mode 100644 clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y.c

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index e85475814fed4..00e1fa2ad5140 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -542,10 +542,8 @@ RValue CIRGenFunction::emitRotate(const CallExpr *e, bool 
isRotateLeft) {
   mlir::Value input = emitScalarExpr(e->getArg(0));
   mlir::Value amount = emitScalarExpr(e->getArg(1));
 
-  // TODO(cir): MSVC flavor bit rotate builtins use different types for input
-  // and amount, but cir.rotate requires them to have the same type. Cast 
amount
-  // to the type of input when necessary.
-  assert(!cir::MissingFeatures::msvcBuiltins());
+  if (amount.getType() != input.getType())
+    amount = builder.createIntCast(amount, input.getType());
 
   auto r = cir::RotateOp::create(builder, getLoc(e->getSourceRange()), input,
                                  amount, isRotateLeft);
@@ -1732,7 +1730,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
   case Builtin::BIstdc_rotate_left_ui:
   case Builtin::BIstdc_rotate_left_ul:
   case Builtin::BIstdc_rotate_left_ull:
-    return errorBuiltinNYI(*this, e, builtinID);
+    return emitRotate(e, /*isRotateLeft=*/true);
 
   case Builtin::BI__builtin_rotateright8:
   case Builtin::BI__builtin_rotateright16:
@@ -1745,11 +1743,16 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
   case Builtin::BIstdc_rotate_right_ui:
   case Builtin::BIstdc_rotate_right_ul:
   case Builtin::BIstdc_rotate_right_ull:
-  case Builtin::BIstdc_memreverse8:
+    return emitRotate(e, /*isRotateLeft=*/false);
   case Builtin::BIstdc_memreverse8u8:
+    return RValue::get(emitScalarExpr(e->getArg(0)));
   case Builtin::BIstdc_memreverse8u16:
   case Builtin::BIstdc_memreverse8u32:
-  case Builtin::BIstdc_memreverse8u64:
+  case Builtin::BIstdc_memreverse8u64: {
+    mlir::Value arg = emitScalarExpr(e->getArg(0));
+    return RValue::get(cir::ByteSwapOp::create(builder, loc, arg));
+  }
+  case Builtin::BIstdc_memreverse8:
     return errorBuiltinNYI(*this, e, builtinID);
 
   case Builtin::BI__builtin_coro_id:
diff --git a/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y-nyi.c 
b/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y-nyi.c
deleted file mode 100644
index f6dd75f8cbe21..0000000000000
--- a/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y-nyi.c
+++ /dev/null
@@ -1,35 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-cir -verify -DSTDC_ROTATE_LEFT %s -o -
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-cir -verify -DSTDC_ROTATE_RIGHT %s -o -
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-cir -verify -DSTDC_MEMREVERSE8 %s -o -
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -emit-llvm %s -o 
- | FileCheck %s --check-prefix=OGCG
-
-unsigned stdc_rotate_left_ui(unsigned, unsigned);
-unsigned stdc_rotate_right_ui(unsigned, unsigned);
-unsigned stdc_memreverse8u32(unsigned);
-
-#if !defined(STDC_ROTATE_RIGHT) && !defined(STDC_MEMREVERSE8)
-unsigned test_stdc_rotate_left_ui(unsigned x) {
-  return stdc_rotate_left_ui(x, 1); // expected-error {{ClangIR code gen Not 
Yet Implemented: unimplemented X86 builtin call: stdc_rotate_left_ui}}
-}
-
-// OGCG-LABEL: define{{.*}} i32 @test_stdc_rotate_left_ui(
-// OGCG: call i32 @llvm.fshl.i32(
-#endif
-
-#if !defined(STDC_ROTATE_LEFT) && !defined(STDC_MEMREVERSE8)
-unsigned test_stdc_rotate_right_ui(unsigned x) {
-  return stdc_rotate_right_ui(x, 1); // expected-error {{ClangIR code gen Not 
Yet Implemented: unimplemented X86 builtin call: stdc_rotate_right_ui}}
-}
-
-// OGCG-LABEL: define{{.*}} i32 @test_stdc_rotate_right_ui(
-// OGCG: call i32 @llvm.fshr.i32(
-#endif
-
-#if !defined(STDC_ROTATE_LEFT) && !defined(STDC_ROTATE_RIGHT)
-unsigned test_stdc_memreverse8u32(unsigned x) {
-  return stdc_memreverse8u32(x); // expected-error {{ClangIR code gen Not Yet 
Implemented: unimplemented X86 builtin call: stdc_memreverse8u32}}
-}
-
-// OGCG-LABEL: define{{.*}} i32 @test_stdc_memreverse8u32(
-// OGCG: call i32 @llvm.bswap.i32(
-#endif
diff --git a/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y.c 
b/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y.c
new file mode 100644
index 0000000000000..ec42db73d6e26
--- /dev/null
+++ b/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y.c
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-cir %s -o - | FileCheck %s --check-prefix=CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-llvm %s -o - | FileCheck %s --check-prefix=LLVM
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -emit-llvm %s -o 
- | FileCheck %s --check-prefix=OGCG
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-cir -verify -DNYI_MEMREVERSE8 %s -o -
+
+typedef __SIZE_TYPE__ size_t;
+
+unsigned char stdc_rotate_left_uc(unsigned char, unsigned);
+unsigned long long stdc_rotate_right_ull(unsigned long long, unsigned);
+unsigned char stdc_memreverse8u8(unsigned char);
+unsigned stdc_memreverse8u32(unsigned);
+void stdc_memreverse8(size_t, unsigned char *);
+
+#ifndef NYI_MEMREVERSE8
+unsigned char test_stdc_rotate_left_uc(unsigned char x, unsigned amount) {
+  return stdc_rotate_left_uc(x, amount);
+}
+
+// CIR-LABEL: test_stdc_rotate_left_uc
+// CIR: cir.cast integral {{.*}} : !u32i -> !u8i
+// CIR: cir.rotate left {{.*}} : !u8i
+
+// LLVM-LABEL: test_stdc_rotate_left_uc
+// LLVM: call i8 @llvm.fshl.i8(
+
+// OGCG-LABEL: test_stdc_rotate_left_uc
+// OGCG: call i8 @llvm.fshl.i8(
+
+unsigned long long test_stdc_rotate_right_ull(unsigned long long x,
+                                              unsigned amount) {
+  return stdc_rotate_right_ull(x, amount);
+}
+
+// CIR-LABEL: test_stdc_rotate_right_ull
+// CIR: cir.cast integral {{.*}} : !u32i -> !u64i
+// CIR: cir.rotate right {{.*}} : !u64i
+
+// LLVM-LABEL: test_stdc_rotate_right_ull
+// LLVM: call i64 @llvm.fshr.i64(
+
+// OGCG-LABEL: test_stdc_rotate_right_ull
+// OGCG: call i64 @llvm.fshr.i64(
+
+unsigned char test_stdc_memreverse8u8(unsigned char x) {
+  return stdc_memreverse8u8(x);
+}
+
+// CIR-LABEL: test_stdc_memreverse8u8
+// CIR-NOT: cir.byte_swap
+
+// LLVM-LABEL: test_stdc_memreverse8u8
+// LLVM-NOT: @llvm.bswap
+
+// OGCG-LABEL: test_stdc_memreverse8u8
+// OGCG-NOT: @llvm.bswap
+
+unsigned test_stdc_memreverse8u32(unsigned x) {
+  return stdc_memreverse8u32(x);
+}
+
+// CIR-LABEL: test_stdc_memreverse8u32
+// CIR: cir.byte_swap {{.*}} : !u32i
+
+// LLVM-LABEL: test_stdc_memreverse8u32
+// LLVM: call i32 @llvm.bswap.i32(
+
+// OGCG-LABEL: test_stdc_memreverse8u32
+// OGCG: call i32 @llvm.bswap.i32(
+#else
+void test_stdc_memreverse8(unsigned char *p) {
+  stdc_memreverse8(4, p); // expected-error {{ClangIR code gen Not Yet 
Implemented: unimplemented X86 builtin call: stdc_memreverse8}}
+}
+#endif

>From 70e255f8a50f223e032bcc5e7716db19375970a2 Mon Sep 17 00:00:00 2001
From: Kunal Dubey <[email protected]>
Date: Wed, 16 Sep 2026 22:31:24 +0530
Subject: [PATCH 3/3] [CIR] Aligned C2Y stdc rotate and memreverse tests with
 CodeGen

---
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp       |  4 +--
 .../CodeGenBuiltins/builtin-stdc-bit-c2y.c    | 28 ++++---------------
 2 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 00e1fa2ad5140..ea4c46de25726 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -1723,7 +1723,6 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
   case Builtin::BI__builtin_rotateleft16:
   case Builtin::BI__builtin_rotateleft32:
   case Builtin::BI__builtin_rotateleft64:
-    return emitRotate(e, /*isRotateLeft=*/true);
   case Builtin::BI__builtin_stdc_rotate_left:
   case Builtin::BIstdc_rotate_left_uc:
   case Builtin::BIstdc_rotate_left_us:
@@ -1736,7 +1735,6 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
   case Builtin::BI__builtin_rotateright16:
   case Builtin::BI__builtin_rotateright32:
   case Builtin::BI__builtin_rotateright64:
-    return emitRotate(e, /*isRotateLeft=*/false);
   case Builtin::BI__builtin_stdc_rotate_right:
   case Builtin::BIstdc_rotate_right_uc:
   case Builtin::BIstdc_rotate_right_us:
@@ -1744,6 +1742,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
   case Builtin::BIstdc_rotate_right_ul:
   case Builtin::BIstdc_rotate_right_ull:
     return emitRotate(e, /*isRotateLeft=*/false);
+
+  // stdc_memreverse8u8 is a no-op (single byte, nothing to swap).
   case Builtin::BIstdc_memreverse8u8:
     return RValue::get(emitScalarExpr(e->getArg(0)));
   case Builtin::BIstdc_memreverse8u16:
diff --git a/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y.c 
b/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y.c
index ec42db73d6e26..87da785445304 100644
--- a/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y.c
+++ b/clang/test/CIR/CodeGenBuiltins/builtin-stdc-bit-c2y.c
@@ -1,17 +1,12 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-cir %s -o - | FileCheck %s --check-prefix=CIR
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-llvm %s -o - | FileCheck %s --check-prefix=LLVM
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -emit-llvm %s -o 
- | FileCheck %s --check-prefix=OGCG
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -fclangir 
-emit-cir -verify -DNYI_MEMREVERSE8 %s -o -
-
-typedef __SIZE_TYPE__ size_t;
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c2y -emit-llvm %s -o 
- | FileCheck %s --check-prefix=LLVM
 
 unsigned char stdc_rotate_left_uc(unsigned char, unsigned);
 unsigned long long stdc_rotate_right_ull(unsigned long long, unsigned);
 unsigned char stdc_memreverse8u8(unsigned char);
 unsigned stdc_memreverse8u32(unsigned);
-void stdc_memreverse8(size_t, unsigned char *);
 
-#ifndef NYI_MEMREVERSE8
 unsigned char test_stdc_rotate_left_uc(unsigned char x, unsigned amount) {
   return stdc_rotate_left_uc(x, amount);
 }
@@ -23,9 +18,6 @@ unsigned char test_stdc_rotate_left_uc(unsigned char x, 
unsigned amount) {
 // LLVM-LABEL: test_stdc_rotate_left_uc
 // LLVM: call i8 @llvm.fshl.i8(
 
-// OGCG-LABEL: test_stdc_rotate_left_uc
-// OGCG: call i8 @llvm.fshl.i8(
-
 unsigned long long test_stdc_rotate_right_ull(unsigned long long x,
                                               unsigned amount) {
   return stdc_rotate_right_ull(x, amount);
@@ -38,21 +30,19 @@ unsigned long long test_stdc_rotate_right_ull(unsigned long 
long x,
 // LLVM-LABEL: test_stdc_rotate_right_ull
 // LLVM: call i64 @llvm.fshr.i64(
 
-// OGCG-LABEL: test_stdc_rotate_right_ull
-// OGCG: call i64 @llvm.fshr.i64(
-
 unsigned char test_stdc_memreverse8u8(unsigned char x) {
   return stdc_memreverse8u8(x);
 }
 
 // CIR-LABEL: test_stdc_memreverse8u8
 // CIR-NOT: cir.byte_swap
+// CIR-NOT: cir.call
+// CIR: cir.return
 
 // LLVM-LABEL: test_stdc_memreverse8u8
 // LLVM-NOT: @llvm.bswap
-
-// OGCG-LABEL: test_stdc_memreverse8u8
-// OGCG-NOT: @llvm.bswap
+// LLVM-NOT: call
+// LLVM: ret i8
 
 unsigned test_stdc_memreverse8u32(unsigned x) {
   return stdc_memreverse8u32(x);
@@ -63,11 +53,3 @@ unsigned test_stdc_memreverse8u32(unsigned x) {
 
 // LLVM-LABEL: test_stdc_memreverse8u32
 // LLVM: call i32 @llvm.bswap.i32(
-
-// OGCG-LABEL: test_stdc_memreverse8u32
-// OGCG: call i32 @llvm.bswap.i32(
-#else
-void test_stdc_memreverse8(unsigned char *p) {
-  stdc_memreverse8(4, p); // expected-error {{ClangIR code gen Not Yet 
Implemented: unimplemented X86 builtin call: stdc_memreverse8}}
-}
-#endif

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

Reply via email to