Index: llvm/include/llvm/Support/TypeSize.h =================================================================== --- llvm/include/llvm/Support/TypeSize.h +++ llvm/include/llvm/Support/TypeSize.h @@ -49,6 +49,33 @@ bool operator!=(const ElementCount& RHS) const { return !(*this == RHS); } + + // Returns true if the answer is known at compile time to be >, else we + // return false. Known is only set to false if we cannot prove we know the + // answer at compile time. + bool isGT(const ElementCount &RHS, bool &Known) { + bool Result; + if ((Scalable || !RHS.Scalable) && Min > RHS.Min) + Known = Result = true; + else if ((!Scalable || RHS.Scalable) && Min <= RHS.Min) { + Known = true; + Result = false; + } else + Known = Result = false; + return Result; + } + + bool knownGT(const ElementCount &RHS) { + bool Known; + bool Result = isGT(RHS, Known); + assertKnown(Known); + return Result; + } + +private: + void assertKnown(bool Known) { + assert(Known && "Cannot compare element counts at runtime"); + } }; // This class is used to represent the size of types. If the type is of fixed Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -437,8 +437,10 @@ // parts vector has more elements than the value vector, then we have a // vector widening case (e.g. <2 x float> -> <4 x float>). Extract the // elements we want. + ElementCount PartEC = PartEVT.getVectorElementCount(); + ElementCount ValueEC = ValueVT.getVectorElementCount(); if (PartEVT.getVectorElementType() == ValueVT.getVectorElementType()) { - assert(PartEVT.getVectorNumElements() > ValueVT.getVectorNumElements() && + assert(PartEC.knownGT(ValueEC) && "Cannot narrow, it would be a lossy transformation"); return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, ValueVT, Val, DAG.getVectorIdxConstant(0, DL)); @@ -448,8 +450,7 @@ if (ValueVT.getSizeInBits() == PartEVT.getSizeInBits()) return DAG.getNode(ISD::BITCAST, DL, ValueVT, Val); - assert(PartEVT.getVectorNumElements() == ValueVT.getVectorNumElements() && - "Cannot handle this kind of promotion"); + assert(PartEC == ValueEC && "Cannot handle this kind of promotion"); // Promoted vector extract return DAG.getAnyExtOrTrunc(Val, DL, ValueVT);