Skip to content

Commit 5933d4b

Browse files
authored
[CIR] Backport support zero init for VectorType (#1574)
Backport support for zero init Vector type
1 parent 6c34681 commit 5933d4b

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
146146
return getZeroAttr(complexType);
147147
if (auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty))
148148
return getZeroAttr(arrTy);
149+
if (auto vecTy = mlir::dyn_cast<cir::VectorType>(ty))
150+
return getZeroAttr(vecTy);
149151
if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
150152
return getConstNullPtrAttr(ptrTy);
151153
if (auto RecordTy = mlir::dyn_cast<cir::RecordType>(ty))

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@ typedef double vd2 __attribute__((ext_vector_type(2)));
1010
typedef long vl2 __attribute__((ext_vector_type(2)));
1111
typedef unsigned short vus2 __attribute__((ext_vector_type(2)));
1212

13+
vi4 vec_a;
14+
// CIR: cir.global external @[[VEC_A:.*]] = #cir.zero : !cir.vector<!s32i x 4>
15+
16+
// LLVM: @[[VEC_A:.*]] = global <4 x i32> zeroinitializer
17+
18+
vi3 vec_b;
19+
// CIR: cir.global external @[[VEC_B:.*]] = #cir.zero : !cir.vector<!s32i x 3>
20+
21+
// LLVM: @[[VEC_B:.*]] = global <3 x i32> zeroinitializer
22+
23+
vi2 vec_c;
24+
// CIR: cir.global external @[[VEC_C:.*]] = #cir.zero : !cir.vector<!s32i x 2>
25+
26+
// LLVM: @[[VEC_C:.*]] = global <2 x i32> zeroinitializer
27+
28+
vd2 d;
29+
30+
// CIR: cir.global external @[[VEC_D:.*]] = #cir.zero : !cir.vector<!cir.double x 2>
31+
32+
// LLVM: @[[VEC_D:.*]] = global <2 x double> zeroinitializer
33+
1334
// CIR: cir.func {{@.*vector_int_test.*}}
1435
// LLVM: define dso_local void {{@.*vector_int_test.*}}
1536
void vector_int_test(int x) {

clang/test/CIR/CodeGen/vectype.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ typedef double vd2 __attribute__((vector_size(16)));
55
typedef long long vll2 __attribute__((vector_size(16)));
66
typedef unsigned short vus2 __attribute__((vector_size(4)));
77

8+
vi4 vec_a;
9+
// CHECK: cir.global external @[[VEC_A:.*]] = #cir.zero : !cir.vector<!s32i x 4>
10+
11+
vd2 b;
12+
// CHECK: cir.global external @[[VEC_B:.*]] = #cir.zero : !cir.vector<!cir.double x 2>
13+
14+
vll2 c;
15+
// CHECK: cir.global external @[[VEC_C:.*]] = #cir.zero : !cir.vector<!s64i x 2>
16+
817
void vector_int_test(int x, unsigned short usx) {
918

1019
// Vector constant.

0 commit comments

Comments
 (0)