From 543abdf1d0914228899061b36674fb1c6234aaff Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 8 Apr 2006 01:19:12 +0000 Subject: [PATCH] Add supprot for shufflevector git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27513 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/SCCP.cpp | 25 +++++++++++++++++++++++++ lib/Transforms/Utils/Local.cpp | 5 +++++ lib/Transforms/Utils/ValueMapper.cpp | 5 +++++ 3 files changed, 35 insertions(+) diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index a57cea8b7e5..9328a251d8a 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -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. // diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index a35a1a69af1..a848e7461eb 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -107,6 +107,11 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I) { case Instruction::InsertElement: if (Constant *Op2 = dyn_cast(I->getOperand(2))) return ConstantExpr::getInsertElement(Op0, Op1, Op2); + return 0; + case Instruction::ShuffleVector: + if (Constant *Op2 = dyn_cast(I->getOperand(2))) + return ConstantExpr::getShuffleVector(Op0, Op1, Op2); + return 0; case Instruction::GetElementPtr: std::vector IdxList; IdxList.reserve(I->getNumOperands()-1); diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index 3093acafab2..b309f9c0e2a 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -94,6 +94,11 @@ Value *llvm::MapValue(const Value *V, std::map &VM) { Constant *MV1 = cast(MapValue(CE->getOperand(0), VM)); Constant *MV2 = cast(MapValue(CE->getOperand(1), VM)); return VMSlot = ConstantExpr::getExtractElement(MV1, MV2); + } else if (CE->getOpcode() == Instruction::ShuffleVector) { + Constant *MV1 = cast(MapValue(CE->getOperand(0), VM)); + Constant *MV2 = cast(MapValue(CE->getOperand(1), VM)); + Constant *MV3 = cast(CE->getOperand(2)); + return VMSlot = ConstantExpr::getShuffleVector(MV1, MV2, MV3); } else { assert(CE->getNumOperands() == 2 && "Must be binary operator?"); Constant *MV1 = cast(MapValue(CE->getOperand(0), VM));