summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-07-18 19:04:16 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-07-18 19:04:16 +0000
commit76e7ba893fecd35422719acad5ab19af09bf4139 (patch)
treeffff08cd0db9dbd9c37914599327f98a43fd6d73 /lib
parent93f2491cf832e3f4530fab8ce1755c2b501346ae (diff)
downloadllvm-76e7ba893fecd35422719acad5ab19af09bf4139.tar.gz
llvm-76e7ba893fecd35422719acad5ab19af09bf4139.tar.bz2
llvm-76e7ba893fecd35422719acad5ab19af09bf4139.tar.xz
Back out 76300; apparently the preference is to canonicalize the other
way (bitcast -> insert/extractelement). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76325 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp22
1 files changed, 6 insertions, 16 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index e9e5294407..21b51e4cda 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -12374,18 +12374,13 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
if (op0)
return ReplaceInstUsesWith(EI, op0);
}
-
- unsigned VectorWidth =
- cast<VectorType>(EI.getOperand(0)->getType())->getNumElements();
-
- // Canonicalize extractelement from a vector of width 1 to a bitcast
- if (VectorWidth == 1)
- return new BitCastInst(EI.getOperand(0), EI.getType());
-
+
// 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 (ConstantInt *IdxC = dyn_cast<ConstantInt>(EI.getOperand(1))) {
unsigned IndexVal = IdxC->getZExtValue();
+ unsigned VectorWidth =
+ cast<VectorType>(EI.getOperand(0)->getType())->getNumElements();
// If this is extracting an invalid index, turn this into undef, to avoid
// crashing the code below.
@@ -12395,7 +12390,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
// This instruction only demands the single element from the input vector.
// If the input vector has a single use, simplify it based on this use
// property.
- if (EI.getOperand(0)->hasOneUse()) {
+ if (EI.getOperand(0)->hasOneUse() && VectorWidth != 1) {
APInt UndefElts(VectorWidth, 0);
APInt DemandedMask(VectorWidth, 1 << IndexVal);
if (Value *V = SimplifyDemandedVectorElts(EI.getOperand(0),
@@ -12632,18 +12627,13 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
// Inserting an undef or into an undefined place, remove this.
if (isa<UndefValue>(ScalarOp) || isa<UndefValue>(IdxOp))
ReplaceInstUsesWith(IE, VecOp);
-
- unsigned NumVectorElts = IE.getType()->getNumElements();
-
- // Canonicalize insertelement into vector of width 1 to a bitcast
- if (NumVectorElts == 1)
- return new BitCastInst(IE.getOperand(1), IE.getType());
-
+
// If the inserted element was extracted from some other vector, and if the
// indexes are constant, try to turn this into a shufflevector operation.
if (ExtractElementInst *EI = dyn_cast<ExtractElementInst>(ScalarOp)) {
if (isa<ConstantInt>(EI->getOperand(1)) && isa<ConstantInt>(IdxOp) &&
EI->getOperand(0)->getType() == IE.getType()) {
+ unsigned NumVectorElts = IE.getType()->getNumElements();
unsigned ExtractedIdx =
cast<ConstantInt>(EI->getOperand(1))->getZExtValue();
unsigned InsertedIdx = cast<ConstantInt>(IdxOp)->getZExtValue();