[PATCH] D11124: Extracting a splat value from vector

Elena Demikhovsky elena.demikhovsky at intel.com
Mon Jul 13 07:12:07 PDT 2015


delena updated this revision to Diff 29563.
delena added a comment.

I use the new getSplatValue() interface in DAG building.


Repository:
  rL LLVM

http://reviews.llvm.org/D11124

Files:
  include/llvm/Analysis/VectorUtils.h
  lib/Analysis/VectorUtils.cpp
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Index: lib/Analysis/VectorUtils.cpp
===================================================================
--- lib/Analysis/VectorUtils.cpp
+++ lib/Analysis/VectorUtils.cpp
@@ -18,6 +18,7 @@
 #include "llvm/IR/GetElementPtrTypeIterator.h"
 #include "llvm/IR/PatternMatch.h"
 #include "llvm/IR/Value.h"
+#include "llvm/IR/Constants.h"
 
 /// \brief Identify if the intrinsic is trivially vectorizable.
 /// This method returns true if the intrinsic's argument types are all
@@ -409,3 +410,15 @@
   // Otherwise, we don't know.
   return nullptr;
 }
+
+llvm::Value *llvm::getSplatValue(Value *V) {
+  llvm::ConstantDataVector *CV = dyn_cast<llvm::ConstantDataVector>(V);
+  if (CV)
+    return CV->getSplatValue();
+  llvm::ShuffleVectorInst *ShuffleInst = dyn_cast<llvm::ShuffleVectorInst>(V);
+  if (!ShuffleInst || !ShuffleInst->getMask()->isNullValue() ||
+      !isa<llvm::InsertElementInst>(ShuffleInst->getOperand(0)))
+    return nullptr;
+
+  return cast<InsertElementInst>(ShuffleInst->getOperand(0))->getOperand(1);
+}
Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/ValueTracking.h"
+#include "llvm/Analysis/VectorUtils.h"
 #include "llvm/CodeGen/FastISel.h"
 #include "llvm/CodeGen/FunctionLoweringInfo.h"
 #include "llvm/CodeGen/GCMetadata.h"
@@ -3091,28 +3092,23 @@
   GetElementPtrInst *Gep = dyn_cast<GetElementPtrInst>(Ptr);
   if (!Gep || Gep->getNumOperands() > 2)
     return false;
-  ShuffleVectorInst *ShuffleInst = 
-    dyn_cast<ShuffleVectorInst>(Gep->getPointerOperand());
-  if (!ShuffleInst || !ShuffleInst->getMask()->isNullValue() ||
-      cast<Instruction>(ShuffleInst->getOperand(0))->getOpcode() !=
-      Instruction::InsertElement)
+  Value *GepPtrs = Gep->getPointerOperand();
+  if (!(Ptr = getSplatValue(GepPtrs)))
     return false;
 
-  Ptr = cast<InsertElementInst>(ShuffleInst->getOperand(0))->getOperand(1);
-
   SelectionDAG& DAG = SDB->DAG;
   const TargetLowering &TLI = DAG.getTargetLoweringInfo();
   // Check is the Ptr is inside current basic block
   // If not, look for the shuffle instruction
   if (SDB->findValue(Ptr))
     Base = SDB->getValue(Ptr);
-  else if (SDB->findValue(ShuffleInst)) {
-    SDValue ShuffleNode = SDB->getValue(ShuffleInst);
-    SDLoc sdl = ShuffleNode;
-    Base = DAG.getNode(
-        ISD::EXTRACT_VECTOR_ELT, sdl,
-        ShuffleNode.getValueType().getScalarType(), ShuffleNode,
-        DAG.getConstant(0, sdl, TLI.getVectorIdxTy(DAG.getDataLayout())));
+  else if (SDB->findValue(GepPtrs)) {
+    SDValue GepPtrsVal = SDB->getValue(GepPtrs);
+    SDLoc sdl = GepPtrsVal;
+    EVT IdxVT = TLI.getVectorIdxTy(DAG.getDataLayout());
+    Base = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, sdl,
+                       GepPtrsVal.getValueType().getScalarType(), GepPtrsVal,
+                       DAG.getConstant(0, sdl, IdxVT));
     SDB->setValue(Ptr, Base);
   }
   else
Index: include/llvm/Analysis/VectorUtils.h
===================================================================
--- include/llvm/Analysis/VectorUtils.h
+++ include/llvm/Analysis/VectorUtils.h
@@ -79,6 +79,11 @@
 /// from the vector.
 Value *findScalarElement(Value *V, unsigned EltNo);
 
+/// \brief Get splat value if the input is a splat vector or return nullptr.
+/// The value may be extracted from a splat constants vector or from
+/// a sequence of instructions that broadcast a single value into a vector.
+Value *getSplatValue(Value *V);
+
 } // llvm namespace
 
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11124.29563.patch
Type: text/x-patch
Size: 3741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150713/b5f8e8bf/attachment.bin>


More information about the llvm-commits mailing list