OSDN Git Service

[X86] Improve some shuffle decoding code to remove a conditional from a loop and...
authorCraig Topper <craig.topper@intel.com>
Fri, 8 Jun 2018 01:09:31 +0000 (01:09 +0000)
committerCraig Topper <craig.topper@intel.com>
Fri, 8 Jun 2018 01:09:31 +0000 (01:09 +0000)
The NumControlBits variable was definitely sketchy. I think that only worked because the expected value was 1 or 2 and the number of lanes was 2 or 4. Had their been 8 lanes the number of bits should have been 3 not 4 as the previous code would have given.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334258 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/Utils/X86ShuffleDecode.cpp

index 8ac1762..fe567f4 100644 (file)
@@ -152,13 +152,12 @@ void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
   if (NumLanes == 0) NumLanes = 1;  // Handle MMX
   unsigned NumLaneElts = NumElts / NumLanes;
 
-  unsigned NewImm = Imm;
+  uint32_t SplatImm = (Imm & 0xff) * 0x01010101;
   for (unsigned l = 0; l != NumElts; l += NumLaneElts) {
     for (unsigned i = 0; i != NumLaneElts; ++i) {
-      ShuffleMask.push_back(NewImm % NumLaneElts + l);
-      NewImm /= NumLaneElts;
+      ShuffleMask.push_back(SplatImm % NumLaneElts + l);
+      SplatImm /= NumLaneElts;
     }
-    if (NumLaneElts == 4) NewImm = Imm; // reload imm
   }
 }
 
@@ -281,16 +280,15 @@ void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize,
                                SmallVectorImpl<int> &ShuffleMask) {
   unsigned NumElementsInLane = 128 / ScalarSize;
   unsigned NumLanes = NumElts / NumElementsInLane;
-  unsigned ControlBitsMask = NumLanes - 1;
-  unsigned NumControlBits  = NumLanes / 2;
 
-  for (unsigned l = 0; l != NumLanes; ++l) {
-    unsigned LaneMask = (Imm >> (l * NumControlBits)) & ControlBitsMask;
+  for (unsigned l = 0; l != NumElts; l += NumElementsInLane) {
+    unsigned Index = (Imm % NumLanes) * NumElementsInLane;
+    Imm /= NumLanes; // Discard the bits we just used.
     // We actually need the other source.
-    if (l >= NumLanes / 2)
-      LaneMask += NumLanes;
+    if (l >= (NumElts / 2))
+      Index += NumElts;
     for (unsigned i = 0; i != NumElementsInLane; ++i)
-      ShuffleMask.push_back(LaneMask * NumElementsInLane + i);
+      ShuffleMask.push_back(Index + i);
   }
 }