Intrinsic::x86_avx2_vperm2i128

Hi, there. I am unable to use the above intrinsic
with LLVM 6.0svn. Is there a substitute?

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(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);