[PATCH] Improve DAG combine pass on certain IR vector patterns

Mehdi Amini mehdi.amini at apple.com
Fri Jan 16 11:54:36 PST 2015


LGTM (I’d like to have Owen or Hal sign-off though) with a few nit:

+    SmallVector<int, 8> Mask;
+    for(unsigned i = 0; i < NumElts; i++)
+      Mask.push_back(SVN->getMaskElt(i));

SmallVector<int, 8> Mask(SVN->getMask().begin(), SVN->getMask().end());

However you can even get rid of the Mask array at all:

  if (NumElemsPerConcat*2 == NumElts && N1.getOpcode() == ISD::UNDEF &&
      std::all_of(SVN->getMask().begin() + NumElemsPerConcat, SVN->getMask().end(),  [](int i){ return i == -1; })) {
      N0 = DAG.getVectorShuffle(ConcatVT, SDLoc(N), N0.getOperand(0), N0.getOperand(1), &SVN->getMask()[0]);

Or if you want to make explicit the fact that we discard part of the mask (no functional change):

      N0 = DAG.getVectorShuffle(ConcatVT, SDLoc(N), N0.getOperand(0), N0.getOperand(1),
                                ArrayRef<int>(SVN->getMask().begin(), NumElemsPerConcat));


Finally, run you code through clang-format to enforce http://llvm.org/docs/CodingStandards.html#supported-c-11-language-and-library-features

Thanks,

Mehdi

 


> On Jan 16, 2015, at 11:24 AM, Fiona Glaser <fglaser at apple.com> wrote:
> 
> Talked about this one offline and decided to implement Mehdi’s strategy.
> 
> Fiona
> 
> <patch.diff>





More information about the llvm-commits mailing list