void visitShiftInst(ShiftInst &I) { visitBinaryOperator(I); }
void visitExtractElementInst(ExtractElementInst &I);
void visitInsertElementInst(InsertElementInst &I);
+ void visitShuffleVectorInst(ShuffleVectorInst &I);
// Instructions that cannot be folded away...
void visitStoreInst (Instruction &I);
IdxState.getConstant()));
}
+void SCCPSolver::visitShuffleVectorInst(ShuffleVectorInst &I) {
+ LatticeVal &V1State = getValueState(I.getOperand(0));
+ LatticeVal &V2State = getValueState(I.getOperand(1));
+ LatticeVal &MaskState = getValueState(I.getOperand(2));
+
+ if (MaskState.isUndefined() ||
+ (V1State.isUndefined() && V2State.isUndefined()))
+ return; // Undefined output if mask or both inputs undefined.
+
+ if (V1State.isOverdefined() || V2State.isOverdefined() ||
+ MaskState.isOverdefined()) {
+ markOverdefined(&I);
+ } else {
+ // A mix of constant/undef inputs.
+ Constant *V1 = V1State.isConstant() ?
+ V1State.getConstant() : UndefValue::get(I.getType());
+ Constant *V2 = V2State.isConstant() ?
+ V2State.getConstant() : UndefValue::get(I.getType());
+ Constant *Mask = MaskState.isConstant() ?
+ MaskState.getConstant() : UndefValue::get(I.getOperand(2)->getType());
+ markConstant(&I, ConstantExpr::getShuffleVector(V1, V2, Mask));
+ }
+}
+
// Handle getelementptr instructions... if all operands are constants then we
// can turn this into a getelementptr ConstantExpr.
//
case Instruction::InsertElement:
if (Constant *Op2 = dyn_cast<Constant>(I->getOperand(2)))
return ConstantExpr::getInsertElement(Op0, Op1, Op2);
+ return 0;
+ case Instruction::ShuffleVector:
+ if (Constant *Op2 = dyn_cast<Constant>(I->getOperand(2)))
+ return ConstantExpr::getShuffleVector(Op0, Op1, Op2);
+ return 0;
case Instruction::GetElementPtr:
std::vector<Constant*> IdxList;
IdxList.reserve(I->getNumOperands()-1);
Constant *MV1 = cast<Constant>(MapValue(CE->getOperand(0), VM));
Constant *MV2 = cast<Constant>(MapValue(CE->getOperand(1), VM));
return VMSlot = ConstantExpr::getExtractElement(MV1, MV2);
+ } else if (CE->getOpcode() == Instruction::ShuffleVector) {
+ Constant *MV1 = cast<Constant>(MapValue(CE->getOperand(0), VM));
+ Constant *MV2 = cast<Constant>(MapValue(CE->getOperand(1), VM));
+ Constant *MV3 = cast<Constant>(CE->getOperand(2));
+ return VMSlot = ConstantExpr::getShuffleVector(MV1, MV2, MV3);
} else {
assert(CE->getNumOperands() == 2 && "Must be binary operator?");
Constant *MV1 = cast<Constant>(MapValue(CE->getOperand(0), VM));