llvm.org GIT mirror llvm / fae96e0
[X86][SSE] createVariablePermute - create index scaling helper. NFCI. This will help in some future changes for custom lowering. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327217 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Pilgrim 2 years ago
1 changed file(s) with 26 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
79337933 DAG.getNode(ISD::INSERT_SUBVECTOR, SDLoc(SrcVec), VT, DAG.getUNDEF(VT),
79347934 SrcVec, DAG.getIntPtrConstant(0, SDLoc(SrcVec)));
79357935
7936 auto ScaleIndices = [&DAG](SDValue Idx, uint64_t Scale) {
7937 assert(isPowerOf2_64(Scale) && "Illegal variable permute shuffle scale");
7938 EVT SrcVT = Idx.getValueType();
7939 unsigned NumDstBits = SrcVT.getScalarSizeInBits() / Scale;
7940 uint64_t IndexScale = 0;
7941 uint64_t IndexOffset = 0;
7942
7943 // If we're scaling a smaller permute op, then we need to repeat the
7944 // indices, scaling and offsetting them as well.
7945 // e.g. v4i32 -> v16i8 (Scale = 4)
7946 // IndexScale = v4i32 Splat(4 << 24 | 4 << 16 | 4 << 8 | 4)
7947 // IndexOffset = v4i32 Splat(3 << 24 | 2 << 16 | 1 << 8 | 0)
7948 for (uint64_t i = 0; i != Scale; ++i) {
7949 IndexScale |= Scale << (i * NumDstBits);
7950 IndexOffset |= i << (i * NumDstBits);
7951 }
7952
7953 Idx = DAG.getNode(ISD::MUL, SDLoc(Idx), SrcVT, Idx,
7954 DAG.getConstant(IndexScale, SDLoc(Idx), SrcVT));
7955 Idx = DAG.getNode(ISD::ADD, SDLoc(Idx), SrcVT, Idx,
7956 DAG.getConstant(IndexOffset, SDLoc(Idx), SrcVT));
7957 return Idx;
7958 };
7959
79367960 unsigned Opcode = 0;
79377961 switch (VT.SimpleTy) {
79387962 default:
80248048 "Illegal variable permute shuffle type");
80258049
80268050 uint64_t Scale = VT.getScalarSizeInBits() / ShuffleVT.getScalarSizeInBits();
8027 if (Scale > 1) {
8028 assert(isPowerOf2_64(Scale) && "Illegal variable permute shuffle scale");
8029 unsigned ShuffleBits = ShuffleVT.getScalarSizeInBits();
8030 uint64_t IndexScale = 0;
8031 uint64_t IndexOffset = 0;
8032
8033 // If we're scaling a smaller permute op, then we need to repeat the
8034 // indices, scaling and offsetting them as well.
8035 // e.g. v4i32 -> v16i8 (Scale = 4)
8036 // IndexScale = v4i32 Splat(4 << 24 | 4 << 16 | 4 << 8 | 4)
8037 // IndexOffset = v4i32 Splat(3 << 24 | 2 << 16 | 1 << 8 | 0)
8038 for (uint64_t i = 0; i != Scale; ++i) {
8039 IndexScale |= Scale << (i * ShuffleBits);
8040 IndexOffset |= i << (i * ShuffleBits);
8041 }
8042
8043 IndicesVec =
8044 DAG.getNode(ISD::MUL, SDLoc(IndicesVec), IndicesVT, IndicesVec,
8045 DAG.getConstant(IndexScale, SDLoc(IndicesVec), IndicesVT));
8046 IndicesVec =
8047 DAG.getNode(ISD::ADD, SDLoc(IndicesVec), IndicesVT, IndicesVec,
8048 DAG.getConstant(IndexOffset, SDLoc(IndicesVec), IndicesVT));
8049 }
8051 if (Scale > 1)
8052 IndicesVec = ScaleIndices(IndicesVec, Scale);
80508053
80518054 EVT ShuffleIdxVT = EVT(ShuffleVT).changeVectorElementTypeToInteger();
80528055 IndicesVec = DAG.getBitcast(ShuffleIdxVT, IndicesVec);