[llvm-commits] [llvm] r166366 - /llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp

Nadav Rotem nrotem at apple.com
Fri Oct 19 21:59:06 PDT 2012


Author: nadav
Date: Fri Oct 19 23:59:06 2012
New Revision: 166366

URL: http://llvm.org/viewvc/llvm-project?rev=166366&view=rev
Log:
Vectorizer: refactor the memory checks to a new function. No functionality change.

Modified:
    llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp

Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=166366&r1=166365&r2=166366&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Fri Oct 19 23:59:06 2012
@@ -202,6 +202,12 @@
   /// and we only need to check individual instructions.
   bool canVectorizeBlock(BasicBlock &BB);
 
+  /// When we vectorize loops we may change the order in which
+  /// we read and write from memory. This method checks if it is
+  /// legal to vectorize the code, considering only memory constrains.
+  /// Returns true if BB is vectorizable
+  bool canVectorizeMemory(BasicBlock &BB;)
+
   // Check if a pointer value is known to be disjoint.
   // Example: Alloca, Global, NoAlias.
   bool isIdentifiedSafeObject(Value* Val);
@@ -908,11 +914,7 @@
 }
 
 bool LoopVectorizationLegality::canVectorizeBlock(BasicBlock &BB) {
-  // Holds the read and write pointers that we find.
-  typedef SmallVector<Value*, 10> ValueVector;
-  ValueVector Reads;
-  ValueVector Writes;
-
+  // Scan the instructions in the block and look for hazards.
   for (BasicBlock::iterator it = BB.begin(), e = BB.end(); it != e; ++it) {
     Instruction *I = it;
 
@@ -960,34 +962,6 @@
       }
     }// end of PHI handling
 
-    // If this is a load, record its pointer. If it is not a load, abort.
-    // Notice that we don't handle function calls that read or write.
-    if (I->mayReadFromMemory()) {
-      LoadInst *Ld = dyn_cast<LoadInst>(I);
-      if (!Ld) return false;
-      if (!Ld->isSimple()) {
-        DEBUG(dbgs() << "LV: Found a non-simple load.\n");
-        return false;
-      }
-
-      Value* Ptr = Ld->getPointerOperand();
-      GetUnderlyingObjects(Ptr, Reads, DL);
-    }
-
-    // Record store pointers. Abort on all other instructions that write to
-    // memory.
-    if (I->mayWriteToMemory()) {
-      StoreInst *St = dyn_cast<StoreInst>(I);
-      if (!St) return false;
-      if (!St->isSimple()) {
-        DEBUG(dbgs() << "LV: Found a non-simple store.\n");
-        return false;
-      }
-
-      Value* Ptr = St->getPointerOperand();
-      GetUnderlyingObjects(Ptr, Writes, DL);
-    }
-
     // We still don't handle functions.
     CallInst *CI = dyn_cast<CallInst>(I);
     if (CI) {
@@ -1024,6 +998,50 @@
       return false;
   }
 
+  // If the memory dependencies do not prevent us from
+  // vectorizing, then vectorize.
+  return canVectorizeMemory(BB);
+}
+
+bool LoopVectorizationLegality::canVectorizeMemory(BasicBlock &BB) {
+  // Holds the read and write pointers that we find.
+  typedef SmallVector<Value*, 10> ValueVector;
+  ValueVector Reads;
+  ValueVector Writes;
+
+  for (BasicBlock::iterator it = BB.begin(), e = BB.end(); it != e; ++it) {
+    Instruction *I = it;
+
+    // If this is a load, record its pointer. If it is not a load, abort.
+    // Notice that we don't handle function calls that read or write.
+    if (I->mayReadFromMemory()) {
+      LoadInst *Ld = dyn_cast<LoadInst>(I);
+      if (!Ld) return false;
+      if (!Ld->isSimple()) {
+        DEBUG(dbgs() << "LV: Found a non-simple load.\n");
+        return false;
+      }
+
+      Value* Ptr = Ld->getPointerOperand();
+      GetUnderlyingObjects(Ptr, Reads, DL);
+    }
+
+    // Record store pointers. Abort on all other instructions that write to
+    // memory.
+    if (I->mayWriteToMemory()) {
+      StoreInst *St = dyn_cast<StoreInst>(I);
+      if (!St) return false;
+      if (!St->isSimple()) {
+        DEBUG(dbgs() << "LV: Found a non-simple store.\n");
+        return false;
+      }
+
+      Value* Ptr = St->getPointerOperand();
+      GetUnderlyingObjects(Ptr, Writes, DL);
+    }
+  } // next instr.
+
+
   // Check that the underlying objects of the reads and writes are either
   // disjoint memory locations, or that they are no-alias arguments.
   ValueVector::iterator r, re, w, we;





More information about the llvm-commits mailing list