[PATCH] D11124: Extracting a splat value from vector

Elena Demikhovsky elena.demikhovsky at intel.com
Sun Jul 12 07:05:42 PDT 2015


delena created this revision.
delena added reviewers: hfinkel, dblaikie.
delena added a subscriber: llvm-commits.
delena set the repository for this revision to rL LLVM.

We have the following interface in IRBuilder.h:
Value *CreateVectorSplat( unsigned NumElts , Value * V , const Twine &  Name = "" ) { ..}

This function creates 2 instructions - “insertelement” and “shuffle” with all-zero mask.

Now I'm adding 
Value *getSplatValue(Value *Val)

This function recognizes the pattern - insertelement+shuffle and returns the splat value (or nullptr).
It also returns a splat value form ConstantDataVector, for completeness. 

( I don't know why functions in this file are not wrapped with "namespace llvm")


Repository:
  rL LLVM

http://reviews.llvm.org/D11124

Files:
  include/llvm/Analysis/VectorUtils.h
  lib/Analysis/VectorUtils.cpp

Index: include/llvm/Analysis/VectorUtils.h
===================================================================
--- include/llvm/Analysis/VectorUtils.h
+++ include/llvm/Analysis/VectorUtils.h
@@ -74,6 +74,11 @@
 /// strides "a[i*stride]". Returns the symbolic stride, or null otherwise.
 Value *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp);
 
+/// \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
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
@@ -357,3 +358,15 @@
 
   return Stride;
 }
+
+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);
+}


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


More information about the llvm-commits mailing list