Skip to content

Commit 675231e

Browse files
[SVE ACLE] Allow default zero initialisation for svcount_t. (#69321)
This matches the behaviour of the other SVE ACLE types.
1 parent 975ec83 commit 675231e

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
// CHECK-NEXT: [[B8:%.*]] = alloca <vscale x 16 x i1>, align 2
5656
// CHECK-NEXT: [[B8X2:%.*]] = alloca <vscale x 32 x i1>, align 2
5757
// CHECK-NEXT: [[B8X4:%.*]] = alloca <vscale x 64 x i1>, align 2
58+
// CHECK-NEXT: [[CNT:%.*]] = alloca target("aarch64.svcount"), align 2
5859
// CHECK-NEXT: store <vscale x 16 x i8> zeroinitializer, ptr [[S8]], align 16
5960
// CHECK-NEXT: store <vscale x 8 x i16> zeroinitializer, ptr [[S16]], align 16
6061
// CHECK-NEXT: store <vscale x 4 x i32> zeroinitializer, ptr [[S32]], align 16
@@ -106,6 +107,7 @@
106107
// CHECK-NEXT: store <vscale x 16 x i1> zeroinitializer, ptr [[B8]], align 2
107108
// CHECK-NEXT: store <vscale x 32 x i1> zeroinitializer, ptr [[B8X2]], align 2
108109
// CHECK-NEXT: store <vscale x 64 x i1> zeroinitializer, ptr [[B8X4]], align 2
110+
// CHECK-NEXT: store target("aarch64.svcount") zeroinitializer, ptr [[CNT]], align 2
109111
// CHECK-NEXT: ret void
110112
//
111113
void test_locals(void) {
@@ -164,6 +166,8 @@ void test_locals(void) {
164166
__SVBool_t b8{};
165167
__clang_svboolx2_t b8x2{};
166168
__clang_svboolx4_t b8x4{};
169+
170+
__SVCount_t cnt{};
167171
}
168172

169173
// CHECK-LABEL: define dso_local void @_Z12test_copy_s8u10__SVInt8_t
@@ -879,3 +883,17 @@ void test_copy_b8x2(__clang_svboolx2_t a) {
879883
void test_copy_b8x4(__clang_svboolx4_t a) {
880884
__clang_svboolx4_t b{a};
881885
}
886+
887+
// CHECK-LABEL: define dso_local void @_Z13test_copy_cntu11__SVCount_t
888+
// CHECK-SAME: (target("aarch64.svcount") [[A:%.*]]) #[[ATTR0]] {
889+
// CHECK-NEXT: entry:
890+
// CHECK-NEXT: [[A_ADDR:%.*]] = alloca target("aarch64.svcount"), align 2
891+
// CHECK-NEXT: [[B:%.*]] = alloca target("aarch64.svcount"), align 2
892+
// CHECK-NEXT: store target("aarch64.svcount") [[A]], ptr [[A_ADDR]], align 2
893+
// CHECK-NEXT: [[TMP0:%.*]] = load target("aarch64.svcount"), ptr [[A_ADDR]], align 2
894+
// CHECK-NEXT: store target("aarch64.svcount") [[TMP0]], ptr [[B]], align 2
895+
// CHECK-NEXT: ret void
896+
//
897+
void test_copy_cnt(__SVCount_t a) {
898+
__SVCount_t b{a};
899+
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,12 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
17381738
if (const auto *NC = dyn_cast<NoCFIValue>(C))
17391739
return getValue(NC->getGlobalValue());
17401740

1741+
if (VT == MVT::aarch64svcount) {
1742+
assert(C->isNullValue() && "Can only zero this target type!");
1743+
return DAG.getNode(ISD::BITCAST, getCurSDLoc(), VT,
1744+
DAG.getConstant(0, getCurSDLoc(), MVT::nxv16i1));
1745+
}
1746+
17411747
VectorType *VecTy = cast<VectorType>(V->getType());
17421748

17431749
// Now that we know the number and type of the elements, get that number of

llvm/lib/IR/Type.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,8 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
841841

842842
// Opaque types in the AArch64 name space.
843843
if (Name == "aarch64.svcount")
844-
return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16));
844+
return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16),
845+
TargetExtType::HasZeroInit);
845846

846847
return TargetTypeInfo(Type::getVoidTy(C));
847848
}

llvm/test/CodeGen/AArch64/sve-zeroinit.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,10 @@ define <vscale x 16 x i1> @test_zeroinit_16xi1() {
8686
; CHECK-NEXT: ret
8787
ret <vscale x 16 x i1> zeroinitializer
8888
}
89+
90+
define target("aarch64.svcount") @test_zeroinit_svcount() "target-features"="+sme2" {
91+
; CHECK-LABEL: test_zeroinit_svcount
92+
; CHECK: pfalse p0.b
93+
; CHECK-NEXT: ret
94+
ret target("aarch64.svcount") zeroinitializer
95+
}

0 commit comments

Comments
 (0)