aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-04-10 23:06:36 +0000
committerChris Lattner <sabre@nondot.org>2006-04-10 23:06:36 +0000
commit389a6f58f7d07930eaf4865b17a0682b0ee4c488 (patch)
tree99df22bbd32b02809d7cbe0825883d6797471ec8 /lib/Transforms
parent0bb1681337a91c974229889f00ef017576fff943 (diff)
downloadexternal_llvm-389a6f58f7d07930eaf4865b17a0682b0ee4c488.zip
external_llvm-389a6f58f7d07930eaf4865b17a0682b0ee4c488.tar.gz
external_llvm-389a6f58f7d07930eaf4865b17a0682b0ee4c488.tar.bz2
Implement vec_shuffle.ll:test3
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27573 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 7674bd2..f79a48e 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -6779,7 +6779,8 @@ static bool CheapToScalarize(Value *V, bool isConstant) {
static Value *FindScalarElement(Value *V, unsigned EltNo) {
assert(isa<PackedType>(V->getType()) && "Not looking at a vector?");
const PackedType *PTy = cast<PackedType>(V->getType());
- if (EltNo >= PTy->getNumElements()) // Out of range access.
+ unsigned Width = PTy->getNumElements();
+ if (EltNo >= Width) // Out of range access.
return UndefValue::get(PTy->getElementType());
if (isa<UndefValue>(V))
@@ -6800,6 +6801,19 @@ static Value *FindScalarElement(Value *V, unsigned EltNo) {
// Otherwise, the insertelement doesn't modify the value, recurse on its
// vector input.
return FindScalarElement(III->getOperand(0), EltNo);
+ } else if (ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(V)) {
+ if (isa<ConstantAggregateZero>(SVI->getOperand(2))) {
+ return FindScalarElement(SVI->getOperand(0), 0);
+ } else if (ConstantPacked *CP =
+ dyn_cast<ConstantPacked>(SVI->getOperand(2))) {
+ if (isa<UndefValue>(CP->getOperand(EltNo)))
+ return UndefValue::get(PTy->getElementType());
+ unsigned InEl = cast<ConstantUInt>(CP->getOperand(EltNo))->getValue();
+ if (InEl < Width)
+ return FindScalarElement(SVI->getOperand(0), InEl);
+ else
+ return FindScalarElement(SVI->getOperand(1), InEl - Width);
+ }
}
// Otherwise, we don't know.
@@ -6831,9 +6845,10 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
// If extracting a specified index from the vector, see if we can recursively
// find a previously computed scalar that was inserted into the vector.
- if (ConstantUInt *IdxC = dyn_cast<ConstantUInt>(EI.getOperand(1)))
+ if (ConstantUInt *IdxC = dyn_cast<ConstantUInt>(EI.getOperand(1))) {
if (Value *Elt = FindScalarElement(EI.getOperand(0), IdxC->getValue()))
return ReplaceInstUsesWith(EI, Elt);
+ }
if (Instruction *I = dyn_cast<Instruction>(EI.getOperand(0)))
if (I->hasOneUse()) {