Skip to content

Commit 5972d06

Browse files
committed
Address code review comments
1 parent 1e4766f commit 5972d06

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,14 +1610,10 @@ mlir::Value ScalarExprEmitter::VisitInitListExpr(InitListExpr *e) {
16101610

16111611
// Zero-initialize any remaining values.
16121612
if (numInitElements < vectorType.getSize()) {
1613-
mlir::TypedAttr zeroInitAttr =
1614-
cgf.getBuilder().getZeroInitAttr(vectorType.getElementType());
1615-
cir::ConstantOp zeroValue = cgf.getBuilder().getConstant(
1616-
cgf.getLoc(e->getSourceRange()), zeroInitAttr);
1617-
1618-
for (uint64_t i = numInitElements; i < vectorType.getSize(); ++i) {
1619-
elements.push_back(zeroValue);
1620-
}
1613+
const mlir::Value zeroValue = cgf.getBuilder().getNullValue(
1614+
vectorType.getElementType(), cgf.getLoc(e->getSourceRange()));
1615+
std::fill_n(std::back_inserter(elements),
1616+
vectorType.getSize() - numInitElements, zeroValue);
16211617
}
16221618

16231619
return cgf.getBuilder().create<cir::VecCreateOp>(

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void foo() {
5959
vi4 e = { 1, 2, 3, 4 };
6060

6161
vi4 f = { x, 5, 6, x + 1 };
62+
63+
vi4 g = { 5 };
6264
}
6365

6466
// CIR: %[[VEC_A:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["a"]
@@ -67,28 +69,35 @@ void foo() {
6769
// CIR: %[[VEC_D:.*]] = cir.alloca !cir.vector<2 x !cir.double>, !cir.ptr<!cir.vector<2 x !cir.double>>, ["d"]
6870
// CIR: %[[VEC_E:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["e", init]
6971
// CIR: %[[VEC_F:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["f", init]
72+
// CIR: %[[VEC_G:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["g", init]
7073
// CIR: %[[VEC_E_VAL:.*]] = cir.vec.create({{.*}}, {{.*}}, {{.*}}, {{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
7174
// CIR: cir.store %[[VEC_E_VAL]], %[[VEC_E]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
7275
// CIR: %[[VEC_F_VAL:.*]] = cir.vec.create({{.*}}, {{.*}}, {{.*}}, {{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
7376
// CIR: cir.store %[[VEC_F_VAL]], %[[VEC_F]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
77+
// CIR: %[[VEC_G_VAL:.*]] = cir.vec.create({{.*}}, {{.*}}, {{.*}}, {{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
78+
// CIR: cir.store %[[VEC_G_VAL]], %[[VEC_G]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
7479

7580
// LLVM: %[[VEC_A:.*]] = alloca <4 x i32>, i64 1, align 16
7681
// LLVM: %[[VEC_B:.*]] = alloca <3 x i32>, i64 1, align 16
7782
// LLVM: %[[VEC_C:.*]] = alloca <2 x i32>, i64 1, align 8
7883
// LLVM: %[[VEC_D:.*]] = alloca <2 x double>, i64 1, align 16
7984
// LLVM: %[[VEC_E:.*]] = alloca <4 x i32>, i64 1, align 16
8085
// LLVM: %[[VEC_F:.*]] = alloca <4 x i32>, i64 1, align 16
86+
// LLVM: %[[VEC_G:.*]] = alloca <4 x i32>, i64 1, align 16
8187
// LLVM: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_E]], align 16
82-
// LLVM: store <4 x i32> {{.*}}, ptr %[[VEC_F:.*]], align 16
88+
// LLVM: store <4 x i32> {{.*}}, ptr %[[VEC_F]], align 16
89+
// LLVM: store <4 x i32> <i32 5, i32 0, i32 0, i32 0>, ptr %[[VEC_G]], align 16
8390

8491
// OGCG: %[[VEC_A:.*]] = alloca <4 x i32>, align 16
8592
// OGCG: %[[VEC_B:.*]] = alloca <3 x i32>, align 16
8693
// OGCG: %[[VEC_C:.*]] = alloca <2 x i32>, align 8
8794
// OGCG: %[[VEC_D:.*]] = alloca <2 x double>, align 16
8895
// OGCG: %[[VEC_E:.*]] = alloca <4 x i32>, align 16
8996
// OGCG: %[[VEC_F:.*]] = alloca <4 x i32>, align 16
97+
// OGCG: %[[VEC_G:.*]] = alloca <4 x i32>, align 16
9098
// OGCG: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_E]], align 16
91-
// OGCG: store <4 x i32> {{.*}}, ptr %[[VEC_F:.*]], align 16
99+
// OGCG: store <4 x i32> {{.*}}, ptr %[[VEC_F]], align 16
100+
// OGCG: store <4 x i32> <i32 5, i32 0, i32 0, i32 0>, ptr %[[VEC_G]], align 16
92101

93102
void foo2(vi4 p) {}
94103

clang/test/CIR/CodeGen/vector.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,42 @@ void foo() {
4949
vi4 d = { 1, 2, 3, 4 };
5050

5151
vi4 e = { x, 5, 6, x + 1 };
52+
53+
vi4 f = { 5 };
5254
}
5355

5456
// CIR: %[[VEC_A:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["a"]
5557
// CIR: %[[VEC_B:.*]] = cir.alloca !cir.vector<2 x !cir.double>, !cir.ptr<!cir.vector<2 x !cir.double>>, ["b"]
5658
// CIR: %[[VEC_C:.*]] = cir.alloca !cir.vector<2 x !s64i>, !cir.ptr<!cir.vector<2 x !s64i>>, ["c"]
5759
// CIR: %[[VEC_D:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["d", init]
5860
// CIR: %[[VEC_E:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["e", init]
61+
// CIR: %[[VEC_F:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["f", init]
5962
// CIR: %[[VEC_D_VAL:.*]] = cir.vec.create({{.*}}, {{.*}}, {{.*}}, {{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
6063
// CIR: cir.store %[[VEC_D_VAL]], %[[VEC_D]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
6164
// CIR: %[[VEC_E_VAL:.*]] = cir.vec.create({{.*}}, {{.*}}, {{.*}}, {{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
6265
// CIR: cir.store %[[VEC_E_VAL]], %[[VEC_E]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
66+
// CIR: %[[VEC_F_VAL:.*]] = cir.vec.create({{.*}}, {{.*}}, {{.*}}, {{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
67+
// CIR: cir.store %[[VEC_F_VAL]], %[[VEC_F]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
6368

6469
// LLVM: %[[VEC_A:.*]] = alloca <4 x i32>, i64 1, align 16
6570
// LLVM: %[[VEC_B:.*]] = alloca <2 x double>, i64 1, align 16
6671
// LLVM: %[[VEC_C:.*]] = alloca <2 x i64>, i64 1, align 16
6772
// LLVM: %[[VEC_D:.*]] = alloca <4 x i32>, i64 1, align 16
6873
// LLVM: %[[VEC_E:.*]] = alloca <4 x i32>, i64 1, align 16
74+
// LLVM: %[[VEC_F:.*]] = alloca <4 x i32>, i64 1, align 16
6975
// LLVM: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_D]], align 16
70-
// LLVM: store <4 x i32> {{.*}}, ptr %[[VEC_E:.*]], align 16
76+
// LLVM: store <4 x i32> {{.*}}, ptr %[[VEC_E]], align 16
77+
// LLVM: store <4 x i32> <i32 5, i32 0, i32 0, i32 0>, ptr %[[VEC_F]], align 16
7178

7279
// OGCG: %[[VEC_A:.*]] = alloca <4 x i32>, align 16
7380
// OGCG: %[[VEC_B:.*]] = alloca <2 x double>, align 16
7481
// OGCG: %[[VEC_C:.*]] = alloca <2 x i64>, align 16
7582
// OGCG: %[[VEC_D:.*]] = alloca <4 x i32>, align 16
7683
// OGCG: %[[VEC_E:.*]] = alloca <4 x i32>, align 16
84+
// OGCG: %[[VEC_F:.*]] = alloca <4 x i32>, align 16
7785
// OGCG: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_D]], align 16
78-
// OGCG: store <4 x i32> {{.*}}, ptr %[[VEC_E:.*]], align 16
86+
// OGCG: store <4 x i32> {{.*}}, ptr %[[VEC_E]], align 16
87+
// OGCG: store <4 x i32> <i32 5, i32 0, i32 0, i32 0>, ptr %[[VEC_F]], align 16
7988

8089
void foo2(vi4 p) {}
8190

0 commit comments

Comments
 (0)