[clang] 1276a5b - [CIR] Upstream support for builtin_vectorelements (#144877)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 25 10:40:25 PDT 2025
Author: Amr Hesham
Date: 2025-06-25T19:40:21+02:00
New Revision: 1276a5b368493cc73ef0febee35a6591b92464d5
URL: https://github.com/llvm/llvm-project/commit/1276a5b368493cc73ef0febee35a6591b92464d5
DIFF: https://github.com/llvm/llvm-project/commit/1276a5b368493cc73ef0febee35a6591b92464d5.diff
LOG: [CIR] Upstream support for builtin_vectorelements (#144877)
Add support for `__builtin_vectorelements`
Issue https://github.com/llvm/llvm-project/issues/136487
Added:
Modified:
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
clang/test/CIR/CodeGen/vector-ext.cpp
clang/test/CIR/CodeGen/vector.cpp
Removed:
################################################################################
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 577b45ad4ec0f..7f8dcd96a6bff 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -1960,13 +1960,6 @@ mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
return builder.getConstant(
loc, builder.getAttr<cir::IntAttr>(
cgf.cgm.UInt64Ty, llvm::APSInt(llvm::APInt(64, 1), true)));
- } else if (e->getKind() == UETT_VectorElements) {
- cgf.getCIRGenModule().errorNYI(e->getSourceRange(),
- "sizeof operator for VectorElements",
- e->getStmtClassName());
- return builder.getConstant(
- loc, builder.getAttr<cir::IntAttr>(
- cgf.cgm.UInt64Ty, llvm::APSInt(llvm::APInt(64, 1), true)));
}
return builder.getConstant(
diff --git a/clang/test/CIR/CodeGen/vector-ext.cpp b/clang/test/CIR/CodeGen/vector-ext.cpp
index fe4919ec0478d..2ee42187a6e94 100644
--- a/clang/test/CIR/CodeGen/vector-ext.cpp
+++ b/clang/test/CIR/CodeGen/vector-ext.cpp
@@ -1161,3 +1161,18 @@ void foo20() {
// OGCG: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
// OGCG: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
// OGCG: %[[SHUF:.*]] = shufflevector <4 x i32> %[[TMP_A]], <4 x i32> %[[TMP_B]], <4 x i32> <i32 poison, i32 1, i32 poison, i32 1>
+
+void foo21() {
+ vi4 a;
+ unsigned long size = __builtin_vectorelements(a);
+}
+
+// CIR: %[[INIT:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["size", init]
+// CIR: %[[SIZE:.*]] = cir.const #cir.int<4> : !u64i
+// CIR: cir.store align(8) %[[SIZE]], %[[INIT]] : !u64i, !cir.ptr<!u64i>
+
+// LLVM: %[[SIZE:.*]] = alloca i64, i64 1, align 8
+// LLVM: store i64 4, ptr %[[SIZE]], align 8
+
+// OGCG: %[[SIZE:.*]] = alloca i64, align 8
+// OGCG: store i64 4, ptr %[[SIZE]], align 8
diff --git a/clang/test/CIR/CodeGen/vector.cpp b/clang/test/CIR/CodeGen/vector.cpp
index d0c5b83cd5b04..18fa90bd2cb3f 100644
--- a/clang/test/CIR/CodeGen/vector.cpp
+++ b/clang/test/CIR/CodeGen/vector.cpp
@@ -1203,3 +1203,18 @@ void foo23() {
// OGCG: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
// OGCG: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
// OGCG: %[[SHUF:.*]] = shufflevector <4 x i32> %[[TMP_A]], <4 x i32> %[[TMP_B]], <4 x i32> <i32 poison, i32 1, i32 poison, i32 1>
+
+void foo24() {
+ vi4 a;
+ unsigned long size = __builtin_vectorelements(a);
+}
+
+// CIR: %[[INIT:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["size", init]
+// CIR: %[[SIZE:.*]] = cir.const #cir.int<4> : !u64i
+// CIR: cir.store align(8) %[[SIZE]], %[[INIT]] : !u64i, !cir.ptr<!u64i>
+
+// LLVM: %[[SIZE:.*]] = alloca i64, i64 1, align 8
+// LLVM: store i64 4, ptr %[[SIZE]], align 8
+
+// OGCG: %[[SIZE:.*]] = alloca i64, align 8
+// OGCG: store i64 4, ptr %[[SIZE]], align 8
More information about the cfe-commits
mailing list