[llvm-dev] Intrinsic::x86_avx2_vperm2i128

Craig Topper via llvm-dev llvm-dev at lists.llvm.org
Sun Nov 12 13:37:36 PST 2017


Everything it could do can be implemented with the generic vector_shuffle
instruction and/or using ConstantAggregateZero input.

Here's the code from lib/IR/AutoUpgrade.cpp that we use to upgrade it if we
see it in IR input to opt or llc

      uint8_t Imm = cast<ConstantInt>(CI->getArgOperand(2))->getZExtValue();

      unsigned NumElts = CI->getType()->getVectorNumElements();
      unsigned HalfSize = NumElts / 2;
      SmallVector<uint32_t, 8> ShuffleMask(NumElts);

      // Determine which operand(s) are actually in use for this
instruction.
      Value *V0 = (Imm & 0x02) ? CI->getArgOperand(1) :
CI->getArgOperand(0);
      Value *V1 = (Imm & 0x20) ? CI->getArgOperand(1) :
CI->getArgOperand(0);

      // If needed, replace operands based on zero mask.
      V0 = (Imm & 0x08) ? ConstantAggregateZero::get(CI->getType()) : V0;
      V1 = (Imm & 0x80) ? ConstantAggregateZero::get(CI->getType()) : V1;

      // Permute low half of result.
      unsigned StartIndex = (Imm & 0x01) ? HalfSize : 0;
      for (unsigned i = 0; i < HalfSize; ++i)
        ShuffleMask[i] = StartIndex + i;

      // Permute high half of result.
      StartIndex = (Imm & 0x10) ? HalfSize : 0;
      for (unsigned i = 0; i < HalfSize; ++i)
        ShuffleMask[i + HalfSize] = NumElts + StartIndex + i;

      Rep = Builder.CreateShuffleVector(V0, V1, ShuffleMask);



~Craig

On Sun, Nov 12, 2017 at 12:55 PM, Rob Cameron via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi, there.   I am unable to use the above intrinsic
> with LLVM 6.0svn.   Is there a substitute?
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171112/b4dedde2/attachment.html>


More information about the llvm-dev mailing list