diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 575ef10d9bbde..7235005a445bb 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -3602,10 +3602,11 @@ static void emitGlobalConstantArray(const DataLayout &DL, static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP); -static void emitGlobalConstantVector(const DataLayout &DL, - const ConstantVector *CV, AsmPrinter &AP, +static void emitGlobalConstantVector(const DataLayout &DL, const Constant *CV, + AsmPrinter &AP, AsmPrinter::AliasMapTy *AliasList) { - Type *ElementType = CV->getType()->getElementType(); + auto *VTy = cast(CV->getType()); + Type *ElementType = VTy->getElementType(); uint64_t ElementSizeInBits = DL.getTypeSizeInBits(ElementType); uint64_t ElementAllocSizeInBits = DL.getTypeAllocSizeInBits(ElementType); uint64_t EmittedSize; @@ -3618,7 +3619,7 @@ static void emitGlobalConstantVector(const DataLayout &DL, Type *IntT = IntegerType::get(CV->getContext(), DL.getTypeSizeInBits(CV->getType())); ConstantInt *CI = dyn_cast_or_null(ConstantFoldConstant( - ConstantExpr::getBitCast(const_cast(CV), IntT), DL)); + ConstantExpr::getBitCast(const_cast(CV), IntT), DL)); if (!CI) { report_fatal_error( "Cannot lower vector global with unusual element type"); @@ -3627,12 +3628,11 @@ static void emitGlobalConstantVector(const DataLayout &DL, emitGlobalConstantLargeInt(CI, AP); EmittedSize = DL.getTypeStoreSize(CV->getType()); } else { - for (unsigned I = 0, E = CV->getType()->getNumElements(); I != E; ++I) { + for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) { emitGlobalAliasInline(AP, DL.getTypeAllocSize(CV->getType()) * I, AliasList); - emitGlobalConstantImpl(DL, CV->getOperand(I), AP); + emitGlobalConstantImpl(DL, CV->getAggregateElement(I), AP); } - EmittedSize = - DL.getTypeAllocSize(ElementType) * CV->getType()->getNumElements(); + EmittedSize = DL.getTypeAllocSize(ElementType) * VTy->getNumElements(); } unsigned Size = DL.getTypeAllocSize(CV->getType()); @@ -3902,8 +3902,10 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV, return AP.OutStreamer->emitZeros(Size); if (const ConstantInt *CI = dyn_cast(CV)) { - const uint64_t StoreSize = DL.getTypeStoreSize(CV->getType()); + if (isa(CV->getType())) + return emitGlobalConstantVector(DL, CV, AP, AliasList); + const uint64_t StoreSize = DL.getTypeStoreSize(CV->getType()); if (StoreSize <= 8) { if (AP.isVerbose()) AP.OutStreamer->getCommentOS() @@ -3920,8 +3922,12 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV, return; } - if (const ConstantFP *CFP = dyn_cast(CV)) - return emitGlobalConstantFP(CFP, AP); + if (const ConstantFP *CFP = dyn_cast(CV)) { + if (isa(CV->getType())) + return emitGlobalConstantVector(DL, CV, AP, AliasList); + else + return emitGlobalConstantFP(CFP, AP); + } if (isa(CV)) { AP.OutStreamer->emitIntValue(0, Size); @@ -3953,8 +3959,8 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV, } } - if (const ConstantVector *V = dyn_cast(CV)) - return emitGlobalConstantVector(DL, V, AP, AliasList); + if (isa(CV)) + return emitGlobalConstantVector(DL, CV, AP, AliasList); // Otherwise, it must be a ConstantExpr. Lower it to an MCExpr, then emit it // thread the streamer with EmitValue. diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 949c23609c9d0..db5effbd9a43e 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -451,6 +451,13 @@ Constant *Constant::getAggregateElement(unsigned Elt) const { ? ConstantInt::get(getContext(), CI->getValue()) : nullptr; + if (const auto *CFP = dyn_cast(this)) + return Elt < cast(getType()) + ->getElementCount() + .getKnownMinValue() + ? ConstantFP::get(getContext(), CFP->getValue()) + : nullptr; + // FIXME: getNumElements() will fail for non-fixed vector types. if (isa(getType())) return nullptr; diff --git a/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-splat-vector.ll b/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-splat-vector.ll index a4cf5d608fed6..96be762b4c8f6 100644 --- a/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-splat-vector.ll +++ b/llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-splat-vector.ll @@ -1,8 +1,7 @@ ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py ; RUN: llc -mattr=+sve -force-streaming-compatible < %s | FileCheck %s ; RUN: llc -force-streaming-compatible < %s | FileCheck %s --check-prefix=NONEON-NOSVE - - +; RUN: llc -force-streaming-compatible -use-constant-int-for-fixed-length-splat -use-constant-fp-for-fixed-length-splat < %s | FileCheck %s --check-prefix=NONEON-NOSVE target triple = "aarch64-unknown-linux-gnu"