diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VMCore/Instructions.cpp | 27 | ||||
-rw-r--r-- | lib/VMCore/Verifier.cpp | 21 |
2 files changed, 31 insertions, 17 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 5b271d6a31..e2ba9b49b0 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -139,6 +139,33 @@ UnaryInstruction::~UnaryInstruction() { } //===----------------------------------------------------------------------===// +// SelectInst Class +//===----------------------------------------------------------------------===// + +/// areInvalidOperands - Return a string if the specified operands are invalid +/// for a select operation, otherwise return null. +const char *SelectInst::areInvalidOperands(Value *Op0, Value *Op1, Value *Op2) { + if (Op1->getType() != Op2->getType()) + return "both values to select must have same type"; + + if (const VectorType *VT = dyn_cast<VectorType>(Op0->getType())) { + // Vector select. + if (VT->getElementType() != Type::Int1Ty) + return "vector select condition element type must be i1"; + const VectorType *ET = dyn_cast<VectorType>(Op1->getType()); + if (ET == 0) + return "selected values for vector select must be vectors"; + if (ET->getNumElements() != VT->getNumElements()) + return "vector select requires selected vectors to have " + "the same vector length as select condition"; + } else if (Op0->getType() != Type::Int1Ty) { + return "select condition must be i1 or <n x i1>"; + } + return 0; +} + + +//===----------------------------------------------------------------------===// // PHINode Class //===----------------------------------------------------------------------===// diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index 27c640e917..592077344a 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -687,23 +687,10 @@ void Verifier::visitSwitchInst(SwitchInst &SI) { } void Verifier::visitSelectInst(SelectInst &SI) { - if (const VectorType* vt - = dyn_cast<VectorType>(SI.getCondition()->getType())) { - Assert1( vt->getElementType() == Type::Int1Ty, - "Select condition type must be vector of bool!", &SI); - if (const VectorType* val_vt - = dyn_cast<VectorType>(SI.getTrueValue()->getType())) { - Assert1( vt->getNumElements() == val_vt->getNumElements(), - "Select vector size != value vector size", &SI); - } else { - Assert1(0, "Vector select values must have vector types", &SI); - } - } else { - Assert1(SI.getCondition()->getType() == Type::Int1Ty, - "Select condition type must be bool!", &SI); - } - Assert1(SI.getTrueValue()->getType() == SI.getFalseValue()->getType(), - "Select values must have identical types!", &SI); + Assert1(!SelectInst::areInvalidOperands(SI.getOperand(0), SI.getOperand(1), + SI.getOperand(2)), + "Invalid operands for select instruction!", &SI); + Assert1(SI.getTrueValue()->getType() == SI.getType(), "Select values must have same type as select instruction!", &SI); visitInstruction(SI); |