diff --git a/llvm/include/llvm/Support/TypeSize.h b/llvm/include/llvm/Support/TypeSize.h --- a/llvm/include/llvm/Support/TypeSize.h +++ b/llvm/include/llvm/Support/TypeSize.h @@ -180,7 +180,7 @@ // Use in places where a scalable count doesn't make sense (e.g. non-vector // types, or vectors in backends which don't support scalable vectors). constexpr ScalarTy getFixedValue() const { - assert(!isScalable() && + assert((!isScalable() || isZero()) && "Request for a fixed element count on a scalable object"); return getKnownMinValue(); } diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp --- a/llvm/lib/CodeGen/Analysis.cpp +++ b/llvm/lib/CodeGen/Analysis.cpp @@ -140,15 +140,14 @@ SmallVectorImpl *FixedOffsets, uint64_t StartingOffset) { TypeSize Offset = TypeSize::get(StartingOffset, Ty->isScalableTy()); - SmallVector Offsets; - if (FixedOffsets) + if (FixedOffsets) { + SmallVector Offsets; ComputeValueVTs(TLI, DL, Ty, ValueVTs, &Offsets, Offset); - else - ComputeValueVTs(TLI, DL, Ty, ValueVTs, nullptr, Offset); - - if (FixedOffsets) for (TypeSize Offset : Offsets) - FixedOffsets->push_back(Offset.getKnownMinValue()); + FixedOffsets->push_back(Offset.getFixedValue()); + } else { + ComputeValueVTs(TLI, DL, Ty, ValueVTs, nullptr, Offset); + } } void llvm::ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, @@ -166,15 +165,14 @@ SmallVectorImpl *FixedOffsets, uint64_t StartingOffset) { TypeSize Offset = TypeSize::get(StartingOffset, Ty->isScalableTy()); - SmallVector Offsets; - if (FixedOffsets) + if (FixedOffsets) { + SmallVector Offsets; ComputeValueVTs(TLI, DL, Ty, ValueVTs, MemVTs, &Offsets, Offset); - else - ComputeValueVTs(TLI, DL, Ty, ValueVTs, MemVTs, nullptr, Offset); - - if (FixedOffsets) for (TypeSize Offset : Offsets) - FixedOffsets->push_back(Offset.getKnownMinValue()); + FixedOffsets->push_back(Offset.getFixedValue()); + } else { + ComputeValueVTs(TLI, DL, Ty, ValueVTs, MemVTs, nullptr, Offset); + } } void llvm::computeValueLLTs(const DataLayout &DL, Type &Ty,