[llvm] b59c231 - [BasicTTI] Return Invalid cost for more scalable vector scalarization cases

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 9 16:10:59 PDT 2022


Author: Philip Reames
Date: 2022-06-09T16:10:51-07:00
New Revision: b59c2315af2193b0f09038a6533867b14083af07

URL: https://github.com/llvm/llvm-project/commit/b59c2315af2193b0f09038a6533867b14083af07
DIFF: https://github.com/llvm/llvm-project/commit/b59c2315af2193b0f09038a6533867b14083af07.diff

LOG: [BasicTTI] Return Invalid cost for more scalable vector scalarization 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.

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/BasicTTIImpl.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 8c54ce879fb94..4fd8f81c3e96d 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -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.
@@ -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();


        


More information about the llvm-commits mailing list