Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -4014,7 +4014,7 @@ Type *Ty = I.getAllocatedType(); const TargetLowering &TLI = DAG.getTargetLoweringInfo(); auto &DL = DAG.getDataLayout(); - uint64_t TySize = DL.getTypeAllocSize(Ty); + TypeSize TySize = DL.getTypeAllocSize(Ty); MaybeAlign Alignment = std::max(DL.getPrefTypeAlign(Ty), I.getAlign()); SDValue AllocSize = getValue(I.getArraySize()); @@ -4023,9 +4023,14 @@ if (AllocSize.getValueType() != IntPtr) AllocSize = DAG.getZExtOrTrunc(AllocSize, dl, IntPtr); - AllocSize = DAG.getNode(ISD::MUL, dl, IntPtr, - AllocSize, - DAG.getConstant(TySize, dl, IntPtr)); + if (TySize.isScalable()) + AllocSize = DAG.getNode(ISD::MUL, dl, IntPtr, AllocSize, + DAG.getVScale(dl, IntPtr, + APInt(IntPtr.getScalarSizeInBits(), + TySize.getKnownMinValue()))); + else + AllocSize = DAG.getNode(ISD::MUL, dl, IntPtr, AllocSize, + DAG.getConstant(TySize, dl, IntPtr)); // Handle alignment. If the requested alignment is less than or equal to // the stack alignment, ignore it. If the size is greater than or equal to Index: llvm/test/CodeGen/AArch64/sve-alloca.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/AArch64/sve-alloca.ll @@ -0,0 +1,30 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=aarch64 -mattr=+sve < %s | FileCheck %s + +declare void @bar(*) + +define void @foo( %dst, i1 %cond) { +; CHECK-LABEL: foo: +; CHECK: rdvl x9, #2 +; CHECK-NEXT: mov x8, sp +; CHECK-NEXT: add x9, x9, #15 +; CHECK-NEXT: and x9, x9, #0xfffffffffffffff0 +; CHECK-NEXT: sub x8, x8, x9 +; CHECK-NEXT: and x0, x8, #0xffffffffffffffe0 +; CHECK-NEXT: mov sp, x0 +; CHECK-NEXT: ptrue p0.d +; CHECK-NEXT: st1d { z1.d }, p0, [x0, #1, mul vl] +; CHECK-NEXT: st1d { z0.d }, p0, [x0] +; CHECK-NEXT: bl bar +entry: + br i1 %cond, label %if.then, label %if.end + +if.then: + %ptr = alloca + store %dst, * %ptr + call void @bar(* %ptr) + br label %if.end + +if.end: + ret void +}