Skip to content

Commit

Permalink
[BasicTTI] Return Invalid cost for more scalable vector scalarization…
Browse files Browse the repository at this point in the history
… cases

Instead of crashing on a cast<FixedVectorType>, we should isntead return Invalid for these cases.  This avoids crashes in assert builds, and potential miscompiles in release builds.
  • Loading branch information
preames committed Jun 9, 2022
1 parent 8bbcb98 commit b59c231
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions llvm/include/llvm/CodeGen/BasicTTIImpl.h
Expand Up @@ -195,6 +195,10 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
bool VariableMask,
bool IsGatherScatter,
TTI::TargetCostKind CostKind) {
// We cannot scalarize scalable vectors, so return Invalid.
if (isa<ScalableVectorType>(DataTy))
return InstructionCost::getInvalid();

auto *VT = cast<FixedVectorType>(DataTy);
// Assume the target does not have support for gather/scatter operations
// and provide a rough estimate.
Expand Down Expand Up @@ -1240,6 +1244,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef<unsigned> Indices,
Align Alignment, unsigned AddressSpace, TTI::TargetCostKind CostKind,
bool UseMaskForCond = false, bool UseMaskForGaps = false) {

// We cannot scalarize scalable vectors, so return Invalid.
if (isa<ScalableVectorType>(VecTy))
return InstructionCost::getInvalid();

auto *VT = cast<FixedVectorType>(VecTy);

unsigned NumElts = VT->getNumElements();
Expand Down

0 comments on commit b59c231

Please sign in to comment.