[llvm] r342902 - [InstCombine] improve variable name and use 'match'; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 24 09:39:03 PDT 2018


Author: spatel
Date: Mon Sep 24 09:39:03 2018
New Revision: 342902

URL: http://llvm.org/viewvc/llvm-project?rev=342902&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=342902&r1=342901&r2=342902&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Mon Sep 24 09:39:03 2018
@@ -181,10 +181,10 @@ Instruction *InstCombiner::visitExtractE
   // 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::visitExtractE
     // 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::visitExtractE
       }
     }
 
-    // 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




More information about the llvm-commits mailing list