[PATCH] support llvm.vectorization.vector_width metadata

Nadav Rotem nrotem at apple.com
Fri May 24 11:07:30 PDT 2013


Hi Paul, 

Thanks for working on this.  Can you also refactor the code that sets metadata on vectorized loops (so that they are not re-vectorized) ?

 
-bool Loop::isAnnotatedParallel() const {
+MDNode *Loop::getLoopID() const {
+  MDNode *LoopID = 0;

Please add braces below. 

+  if (isLoopSimplifyForm())
+    LoopID = getLoopLatch()->getTerminator()->getMetadata("llvm.loop");
+  else {
+    // Go through each predecessor of the loop header and check the
+    // terminator for the metadata.
+    BasicBlock *H


Please add a string for the asserts below.

+void Loop::setLoopID(MDNode *LoopID) const {
+  assert(LoopID);
+  assert(LoopID->getNumOperands() > 0);
+  assert(LoopID->getOperand(0) == LoopID);


Can you outline the code below to a function and use it around the code that checks for the command line flags ?
 
+    unsigned UserVF = VectorizationFactor;
+
+    // Check the loop metadata for vectorization hints.
+    if (const MDNode *LoopID = L->getLoopID()) {
+      assert(LoopID->getNumOperands() > 0);
+      assert(LoopID->getOperand(0) == LoopID);
+      for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) {
+        const MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i));
+        if (!MD)
+          continue;

Use early exits (continue) here: 

+        if (MD->getNumOperands() == 2) {
+          if (const MDString *S = dyn_cast<MDString>(MD->getOperand(0))) {
+            if (S->getString() == "llvm.vectorization.vector_width") {
+              const ConstantInt *C = dyn_cast<ConstantInt>(MD->getOperand(1));
+              UserVF = C ? C->getZExtValue() : UserVF;


Because of this:

+            }
+          }
+        }
+      }
+    }
+
    

Thanks,
Nadav


On May 24, 2013, at 10:49 AM, "Redmond, Paul" <paul.redmond at intel.com> wrote:

> Hi,
> 
> The attached patch modifies LoopVectorizer to recognize llvm.vectorization.vector_width metadata attached to llvm.loop metadata.
> 
> The llvm.loop.parallel metadata has been renamed to llvm.loop to be more generic. Loop::isAnnotatedParallel now looks for llvm.loop and associated llvm.mem.parallel_loop_access. If we decide that we still need an explicit llvm.loop.parallel metadata then it can be added as a child of llvm.loop.
> 
> Loop::setLoopID was added for symmetry and it is used in a forthcoming patch which preserves llvm.loop metadata in loop passes.
> 
> paul
> 
> <Mail Attachment>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130524/32d89411/attachment.html>


More information about the llvm-commits mailing list