Skip to content

Commit 1276a5b

Browse files
authored
[CIR] Upstream support for builtin_vectorelements (#144877)
Add support for `__builtin_vectorelements` Issue #136487
1 parent e4da49f commit 1276a5b

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,13 +1960,6 @@ mlir::Value ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
19601960
return builder.getConstant(
19611961
loc, builder.getAttr<cir::IntAttr>(
19621962
cgf.cgm.UInt64Ty, llvm::APSInt(llvm::APInt(64, 1), true)));
1963-
} else if (e->getKind() == UETT_VectorElements) {
1964-
cgf.getCIRGenModule().errorNYI(e->getSourceRange(),
1965-
"sizeof operator for VectorElements",
1966-
e->getStmtClassName());
1967-
return builder.getConstant(
1968-
loc, builder.getAttr<cir::IntAttr>(
1969-
cgf.cgm.UInt64Ty, llvm::APSInt(llvm::APInt(64, 1), true)));
19701963
}
19711964

19721965
return builder.getConstant(

clang/test/CIR/CodeGen/vector-ext.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,3 +1161,18 @@ void foo20() {
11611161
// OGCG: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
11621162
// OGCG: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
11631163
// OGCG: %[[SHUF:.*]] = shufflevector <4 x i32> %[[TMP_A]], <4 x i32> %[[TMP_B]], <4 x i32> <i32 poison, i32 1, i32 poison, i32 1>
1164+
1165+
void foo21() {
1166+
vi4 a;
1167+
unsigned long size = __builtin_vectorelements(a);
1168+
}
1169+
1170+
// CIR: %[[INIT:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["size", init]
1171+
// CIR: %[[SIZE:.*]] = cir.const #cir.int<4> : !u64i
1172+
// CIR: cir.store align(8) %[[SIZE]], %[[INIT]] : !u64i, !cir.ptr<!u64i>
1173+
1174+
// LLVM: %[[SIZE:.*]] = alloca i64, i64 1, align 8
1175+
// LLVM: store i64 4, ptr %[[SIZE]], align 8
1176+
1177+
// OGCG: %[[SIZE:.*]] = alloca i64, align 8
1178+
// OGCG: store i64 4, ptr %[[SIZE]], align 8

clang/test/CIR/CodeGen/vector.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,3 +1203,18 @@ void foo23() {
12031203
// OGCG: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
12041204
// OGCG: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
12051205
// OGCG: %[[SHUF:.*]] = shufflevector <4 x i32> %[[TMP_A]], <4 x i32> %[[TMP_B]], <4 x i32> <i32 poison, i32 1, i32 poison, i32 1>
1206+
1207+
void foo24() {
1208+
vi4 a;
1209+
unsigned long size = __builtin_vectorelements(a);
1210+
}
1211+
1212+
// CIR: %[[INIT:.*]] = cir.alloca !u64i, !cir.ptr<!u64i>, ["size", init]
1213+
// CIR: %[[SIZE:.*]] = cir.const #cir.int<4> : !u64i
1214+
// CIR: cir.store align(8) %[[SIZE]], %[[INIT]] : !u64i, !cir.ptr<!u64i>
1215+
1216+
// LLVM: %[[SIZE:.*]] = alloca i64, i64 1, align 8
1217+
// LLVM: store i64 4, ptr %[[SIZE]], align 8
1218+
1219+
// OGCG: %[[SIZE:.*]] = alloca i64, align 8
1220+
// OGCG: store i64 4, ptr %[[SIZE]], align 8

0 commit comments

Comments
 (0)