-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[CIR] Upstream support for builtin_vectorelements #144877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CIR] Upstream support for builtin_vectorelements #144877
Conversation
@llvm/pr-subscribers-clangir @llvm/pr-subscribers-clang Author: Amr Hesham (AmrDeveloper) ChangesAdd support for Issue #136487 Full diff: https://github.com/llvm/llvm-project/pull/144877.diff 3 Files Affected:
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 8d0db5cd0a1e5..dc47808bef48b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -1914,13 +1914,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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Add support for `__builtin_vectorelements` Issue llvm#136487
Add support for `__builtin_vectorelements` Issue llvm#136487
Add support for
__builtin_vectorelements
Issue #136487