Add supprot for shufflevector

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27513 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-04-08 01:19:12 +00:00
parent d5efe84646
commit 543abdf1d0
3 changed files with 35 additions and 0 deletions

View File

@ -330,6 +330,7 @@ private:
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);
@ -782,6 +783,30 @@ void SCCPSolver::visitInsertElementInst(InsertElementInst &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.
//

View File

@ -107,6 +107,11 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I) {
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);

View File

@ -94,6 +94,11 @@ Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) {
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));