[PATCH] D37236: [InstCombine] add insertelement + shuffle demanded element fold

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 16:58:46 PDT 2017


craig.topper added a comment.

  --- a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
  +++ b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
  @@ -996,19 +996,21 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
       // If this is inserting an element that isn't demanded, remove this
       // insertelement.
       unsigned IdxNo = Idx->getZExtValue();
  -    if (IdxNo >= VWidth || !DemandedElts[IdxNo]) {
  -      Worklist.Add(I);
  -      return I->getOperand(0);
  -    }
  
       // Otherwise, the element inserted overwrites whatever was there, so the
       // input demanded set is simpler than the output set.
       APInt DemandedElts2 = DemandedElts;
  -    DemandedElts2.clearBit(IdxNo);
  +    if (IdxNo < VWidth)
  +      DemandedElts2.clearBit(IdxNo);
       TmpV = SimplifyDemandedVectorElts(I->getOperand(0), DemandedElts2,
                                         UndefElts, Depth + 1);
       if (TmpV) { I->setOperand(0, TmpV); MadeChange = true; }
  
  +    if (IdxNo >= VWidth || !DemandedElts[IdxNo]) {
  +      Worklist.Add(I);
  +      return I->getOperand(0);
  +    }
  +
       // The inserted element is defined.
       UndefElts.clearBit(IdxNo);
       break;


https://reviews.llvm.org/D37236





More information about the llvm-commits mailing list