Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1553,13 +1553,14 @@ return DAG.getBlockAddress(BA, VT); VectorType *VecTy = cast(V->getType()); - unsigned NumElements = VecTy->getNumElements(); + ElementCount EltCnt = VecTy->getElementCount(); // Now that we know the number and type of the elements, get that number of // elements into the Ops array based on what kind of constant it is. SmallVector Ops; if (const ConstantVector *CV = dyn_cast(C)) { - for (unsigned i = 0; i != NumElements; ++i) + assert(!EltCnt.Scalable && "ConstantVector used for scalable types"); + for (unsigned i = 0; i != EltCnt.Min; ++i) Ops.push_back(getValue(CV->getOperand(i))); } else { assert(isa(C) && "Unknown vector constant!"); @@ -1571,7 +1572,11 @@ Op = DAG.getConstantFP(0, getCurSDLoc(), EltVT); else Op = DAG.getConstant(0, getCurSDLoc(), EltVT); - Ops.assign(NumElements, Op); + + if (EltCnt.Scalable) + return NodeMap[V] = DAG.getSplatVector(VT, getCurSDLoc(), Op); + + Ops.assign(EltCnt.Min, Op); } // Create a BUILD_VECTOR node. Index: llvm/test/CodeGen/AArch64/sve-zeroinit.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/AArch64/sve-zeroinit.ll @@ -0,0 +1,81 @@ +; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s + +target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" +target triple = "aarch64-none-linux-gnu" + +define @test_zeroinit_2xi64() { +; CHECK-LABEL: test_zeroinit_2xi64 +; CHECK: mov z0.d, #0 +; CHECK-NEXT: ret + ret zeroinitializer +} + +define @test_zeroinit_4xi32() { +; CHECK-LABEL: test_zeroinit_4xi32 +; CHECK: mov z0.s, #0 +; CHECK-NEXT: ret + ret zeroinitializer +} + +define @test_zeroinit_8xi16() { +; CHECK-LABEL: test_zeroinit_8xi16 +; CHECK: mov z0.h, #0 +; CHECK-NEXT: ret + ret zeroinitializer +} + +define @test_zeroinit_16xi8() { +; CHECK-LABEL: test_zeroinit_16xi8 +; CHECK: mov z0.b, #0 +; CHECK-NEXT: ret + ret zeroinitializer +} + +define @test_zeroinit_2xf64() { +; CHECK-LABEL: test_zeroinit_2xf64 +; CHECK: mov z0.d, #0 +; CHECK-NEXT: ret + ret zeroinitializer +} + +define @test_zeroinit_4xf32() { +; CHECK-LABEL: test_zeroinit_4xf32 +; CHECK: mov z0.s, #0 +; CHECK-NEXT: ret + ret zeroinitializer +} + +define @test_zeroinit_8xf16() { +; CHECK-LABEL: test_zeroinit_8xf16 +; CHECK: mov z0.h, #0 +; CHECK-NEXT: ret + ret zeroinitializer +} + +define @test_zeroinit_2xi1() { +; CHECK-LABEL: test_zeroinit_2xi1 +; CHECK: whilelo p0.d, xzr, xzr +; CHECK-NEXT: ret + ret zeroinitializer +} + +define @test_zeroinit_4xi1() { +; CHECK-LABEL: test_zeroinit_4xi1 +; CHECK: whilelo p0.s, xzr, xzr +; CHECK-NEXT: ret + ret zeroinitializer +} + +define @test_zeroinit_8xi1() { +; CHECK-LABEL: test_zeroinit_8xi1 +; CHECK: whilelo p0.h, xzr, xzr +; CHECK-NEXT: ret + ret zeroinitializer +} + +define @test_zeroinit_16xi1() { +; CHECK-LABEL: test_zeroinit_16xi1 +; CHECK: whilelo p0.b, xzr, xzr +; CHECK-NEXT: ret + ret zeroinitializer +}