summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-09-24 16:39:03 +0000
committerSanjay Patel <spatel@rotateright.com>2018-09-24 16:39:03 +0000
commit7a52626a081b6a860357b15663ab9731fc4805f5 (patch)
tree6450d7bb379c9e9c296e332f05aeb4cbfa8b7c08 /llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
parent3bdf34f20e9afa3e0c389b3e8df1d30503e77fa7 (diff)
downloadbcm5719-llvm-7a52626a081b6a860357b15663ab9731fc4805f5.tar.gz
bcm5719-llvm-7a52626a081b6a860357b15663ab9731fc4805f5.zip
[InstCombine] improve variable name and use 'match'; NFC
'width' of a vector usually refers to the bit-width. https://bugs.llvm.org/show_bug.cgi?id=39016 shows a case where we could extend this fold to handle a case where the number of elements in the bitcasted vector is not equal to the resulting value. llvm-svn: 342902
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index d40fa9b5b01..03580fc96d4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -181,10 +181,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 (ConstantInt *IdxC = dyn_cast<ConstantInt>(EI.getOperand(1))) {
- unsigned VectorWidth = EI.getVectorOperandType()->getNumElements();
+ unsigned NumElts = EI.getVectorOperandType()->getNumElements();
// InstSimplify should handle cases where the index is invalid.
- if (!IdxC->getValue().ule(VectorWidth))
+ if (!IdxC->getValue().ule(NumElts))
return nullptr;
unsigned IndexVal = IdxC->getZExtValue();
@@ -192,9 +192,9 @@ 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() && VectorWidth != 1) {
- APInt UndefElts(VectorWidth, 0);
- APInt DemandedMask(VectorWidth, 0);
+ if (EI.getOperand(0)->hasOneUse() && NumElts != 1) {
+ APInt UndefElts(NumElts, 0);
+ APInt DemandedMask(NumElts, 0);
DemandedMask.setBit(IndexVal);
if (Value *V = SimplifyDemandedVectorElts(EI.getOperand(0), DemandedMask,
UndefElts)) {
@@ -203,14 +203,16 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
}
}
- // If this extractelement is directly using a bitcast from a vector of
- // the same number of elements, see if we can find the source element from
- // it. In this case, we will end up needing to bitcast the scalars.
- if (BitCastInst *BCI = dyn_cast<BitCastInst>(EI.getOperand(0))) {
- if (VectorType *VT = dyn_cast<VectorType>(BCI->getOperand(0)->getType()))
- if (VT->getNumElements() == VectorWidth)
- if (Value *Elt = findScalarElement(BCI->getOperand(0), IndexVal))
- return new BitCastInst(Elt, EI.getType());
+ Value *X;
+ if (match(EI.getVectorOperand(), m_BitCast(m_Value(X))) &&
+ X->getType()->isVectorTy()) {
+ // If this extractelement is using a bitcast from a vector of the same
+ // number of elements, see if we can find the source element from the
+ // source vector:
+ // extelt (bitcast VecX), IdxC --> bitcast X[IdxC]
+ if (X->getType()->getVectorNumElements() == NumElts)
+ if (Value *Elt = findScalarElement(X, IndexVal))
+ return new BitCastInst(Elt, EI.getType());
}
// If there's a vector PHI feeding a scalar use through this extractelement
OpenPOWER on IntegriCloud