[llvm] r272496 - [X86] Greatly simplify the llvm.x86.avx.vpermil.* auto-upgrade code. We can fully derive everything using types of the intrinsic arguments rather than writing separate loops for each intrinsic. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 11 20:10:48 PDT 2016


Author: ctopper
Date: Sat Jun 11 22:10:47 2016
New Revision: 272496

URL: http://llvm.org/viewvc/llvm-project?rev=272496&view=rev
Log:
[X86] Greatly simplify the llvm.x86.avx.vpermil.* auto-upgrade code. We can fully derive everything using types of the intrinsic arguments rather than writing separate loops for each intrinsic. NFC

Modified:
    llvm/trunk/lib/IR/AutoUpgrade.cpp

Modified: llvm/trunk/lib/IR/AutoUpgrade.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AutoUpgrade.cpp?rev=272496&r1=272495&r2=272496&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AutoUpgrade.cpp (original)
+++ llvm/trunk/lib/IR/AutoUpgrade.cpp Sat Jun 11 22:10:47 2016
@@ -888,43 +888,25 @@ void llvm::UpgradeIntrinsicCall(CallInst
       Rep = Builder.CreateShuffleVector(Op0, UndefV, Idxs);
     } else if (Name == "llvm.stackprotectorcheck") {
       Rep = nullptr;
-    } else {
-      bool PD128 = false, PD256 = false, PS128 = false, PS256 = false;
-      if (Name == "llvm.x86.avx.vpermil.pd.256")
-        PD256 = true;
-      else if (Name == "llvm.x86.avx.vpermil.pd")
-        PD128 = true;
-      else if (Name == "llvm.x86.avx.vpermil.ps.256")
-        PS256 = true;
-      else if (Name == "llvm.x86.avx.vpermil.ps")
-        PS128 = true;
-
-      if (PD256 || PD128 || PS256 || PS128) {
-        Value *Op0 = CI->getArgOperand(0);
-        unsigned Imm = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue();
-        SmallVector<uint32_t, 8> Idxs;
+    } else if (Name.startswith("llvm.x86.avx.vpermil.")) {
+      Value *Op0 = CI->getArgOperand(0);
+      unsigned Imm = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue();
+      VectorType *VecTy = cast<VectorType>(CI->getType());
+      unsigned NumElts = VecTy->getNumElements();
+      // Calcuate the size of each index in the immediate.
+      unsigned IdxSize = 64 / VecTy->getScalarSizeInBits();
+      unsigned IdxMask = ((1 << IdxSize) - 1);
 
-        if (PD128)
-          for (unsigned i = 0; i != 2; ++i)
-            Idxs.push_back((Imm >> i) & 0x1);
-        else if (PD256)
-          for (unsigned l = 0; l != 4; l+=2)
-            for (unsigned i = 0; i != 2; ++i)
-              Idxs.push_back(((Imm >> (l+i)) & 0x1) + l);
-        else if (PS128)
-          for (unsigned i = 0; i != 4; ++i)
-            Idxs.push_back((Imm >> (2 * i)) & 0x3);
-        else if (PS256)
-          for (unsigned l = 0; l != 8; l+=4)
-            for (unsigned i = 0; i != 4; ++i)
-              Idxs.push_back(((Imm >> (2 * i)) & 0x3) + l);
-        else
-          llvm_unreachable("Unexpected function");
+      SmallVector<uint32_t, 8> Idxs(NumElts);
+      // Lookup the bits for this element, wrapping around the immediate every
+      // 8-bits. Elements are grouped into sets of 2 or 4 elements so we need
+      // to offset by the first index of each group.
+      for (unsigned i = 0; i != NumElts; ++i)
+        Idxs[i] = ((Imm >> ((i * IdxSize) % 8)) & IdxMask) | (i & ~IdxMask);
 
-        Rep = Builder.CreateShuffleVector(Op0, Op0, Idxs);
-      } else {
-        llvm_unreachable("Unknown function for CallInst upgrade.");
-      }
+      Rep = Builder.CreateShuffleVector(Op0, Op0, Idxs);
+    } else {
+      llvm_unreachable("Unknown function for CallInst upgrade.");
     }
 
     if (Rep)




More information about the llvm-commits mailing list