diff --git a/llvm/include/llvm/CodeGenTypes/MachineValueType.h b/llvm/include/llvm/CodeGenTypes/MachineValueType.h index 08a9c85a213e0..64687d515d21a 100644 --- a/llvm/include/llvm/CodeGenTypes/MachineValueType.h +++ b/llvm/include/llvm/CodeGenTypes/MachineValueType.h @@ -64,6 +64,9 @@ namespace llvm { bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; } bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; } + /// Return the value type as a string, e.g. `i32`. + std::string getString() const; + /// Support for debugging, callable in GDB: VT.dump() LLVM_ABI void dump() const; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index bff4799963fc2..55715bd51b11a 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -330,6 +330,17 @@ static void diagnosePossiblyInvalidConstraint(LLVMContext &Ctx, const Value *V, return Ctx.emitError(I, ErrMsg); } +/// Emit a fatal error if the broken down registers don't match part type +/// or count. +static void ensureMatchedVecRegParts(unsigned NumRegs, unsigned NumParts, + MVT RegisterVT, MVT PartVT) { + if (NumRegs != NumParts || RegisterVT != PartVT) + llvm::reportFatalInternalError( + Twine("Part count doesn't match vector breakdown! ") + Twine(NumRegs) + + " registers, " + Twine(NumParts) + " parts, " + RegisterVT.getString() + + " RegisterVT, " + PartVT.getString() + " PartVT"); +} + /// getCopyFromPartsVector - Create a value that contains the specified legal /// parts combined into the value they represent. If the parts combine to a /// type larger than ValueVT then AssertOp can be used to specify whether the @@ -364,9 +375,7 @@ static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL, NumIntermediates, RegisterVT); } - assert(NumRegs == NumParts && "Part count doesn't match vector breakdown!"); - NumParts = NumRegs; // Silence a compiler warning. - assert(RegisterVT == PartVT && "Part type doesn't match vector breakdown!"); + ensureMatchedVecRegParts(NumRegs, NumParts, RegisterVT, PartVT); assert(RegisterVT.getSizeInBits() == Parts[0].getSimpleValueType().getSizeInBits() && "Part type sizes don't match!"); @@ -769,10 +778,7 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL, NumIntermediates, RegisterVT); } - assert(NumRegs == NumParts && "Part count doesn't match vector breakdown!"); - NumParts = NumRegs; // Silence a compiler warning. - assert(RegisterVT == PartVT && "Part type doesn't match vector breakdown!"); - + ensureMatchedVecRegParts(NumRegs, NumParts, RegisterVT, PartVT); assert(IntermediateVT.isScalableVector() == ValueVT.isScalableVector() && "Mixing scalable and fixed vectors when copying in parts"); diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp index 0743c92c5b95b..f3e4eaa2ef00f 100644 --- a/llvm/lib/CodeGen/ValueTypes.cpp +++ b/llvm/lib/CodeGen/ValueTypes.cpp @@ -333,6 +333,13 @@ const fltSemantics &EVT::getFltSemantics() const { return getScalarType().getSimpleVT().getFltSemantics(); } +std::string MVT::getString() const { + if (SimpleTy == INVALID_SIMPLE_VALUE_TYPE) + return "invalid"; + + return EVT(*this).getEVTString(); +} + #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void MVT::dump() const { print(dbgs()); @@ -340,9 +347,4 @@ void MVT::dump() const { } #endif -void MVT::print(raw_ostream &OS) const { - if (SimpleTy == INVALID_SIMPLE_VALUE_TYPE) - OS << "invalid"; - else - OS << EVT(*this).getEVTString(); -} +void MVT::print(raw_ostream &OS) const { OS << getString(); }