[llvm-branch-commits] [llvm-branch] r183189 - Merging r183035:

Bill Wendling isanbard at gmail.com
Mon Jun 3 21:35:28 PDT 2013


Author: void
Date: Mon Jun  3 23:35:28 2013
New Revision: 183189

URL: http://llvm.org/viewvc/llvm-project?rev=183189&view=rev
Log:
Merging r183035:
------------------------------------------------------------------------
r183035 | arnolds | 2013-05-31 12:53:50 -0700 (Fri, 31 May 2013) | 7 lines

LoopVectorize: PHIs with only outside users should prevent vectorization

We check that instructions in the loop don't have outside users (except if
they are reduction values). Unfortunately, we skipped this check for
if-convertable PHIs.

Fixes PR16184.
------------------------------------------------------------------------

Added:
    llvm/branches/release_33/test/Transforms/LoopVectorize/no_outside_user.ll
      - copied unchanged from r183035, llvm/trunk/test/Transforms/LoopVectorize/no_outside_user.ll
Modified:
    llvm/branches/release_33/   (props changed)
    llvm/branches/release_33/lib/Transforms/Vectorize/LoopVectorize.cpp

Propchange: llvm/branches/release_33/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jun  3 23:35:28 2013
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,181286,181296,181313,181363,181366,181397,181423,181450,181524,181529,181540,181576-181580,181586,181600,181678,181706,181792,181800,181842,181864,182072,182112-182113,182253-182254,182297-182298,182344,182364,182385,182387,182394,182485-182486,182585,182656,183108
+/llvm/trunk:155241,181286,181296,181313,181363,181366,181397,181423,181450,181524,181529,181540,181576-181580,181586,181600,181678,181706,181792,181800,181842,181864,182072,182112-182113,182253-182254,182297-182298,182344,182364,182385,182387,182394,182485-182486,182585,182656,183035,183108

Modified: llvm/branches/release_33/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_33/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=183189&r1=183188&r2=183189&view=diff
==============================================================================
--- llvm/branches/release_33/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/branches/release_33/lib/Transforms/Vectorize/LoopVectorize.cpp Mon Jun  3 23:35:28 2013
@@ -2378,6 +2378,26 @@ bool LoopVectorizationLegality::canVecto
   return true;
 }
 
+/// \brief Check that the instruction has outside loop users and is not an
+/// identified reduction variable.
+static bool hasOutsideLoopUser(const Loop *TheLoop, Instruction *Inst,
+                               SmallPtrSet<Value *, 4> &Reductions) {
+  // Reduction instructions are allowed to have exit users. All other
+  // instructions must not have external users.
+  if (!Reductions.count(Inst))
+    //Check that all of the users of the loop are inside the BB.
+    for (Value::use_iterator I = Inst->use_begin(), E = Inst->use_end();
+         I != E; ++I) {
+      Instruction *U = cast<Instruction>(*I);
+      // This user may be a reduction exit value.
+      if (!TheLoop->contains(U)) {
+        DEBUG(dbgs() << "LV: Found an outside user for : "<< *U << "\n");
+        return true;
+      }
+    }
+  return false;
+}
+
 bool LoopVectorizationLegality::canVectorizeInstrs() {
   BasicBlock *PreHeader = TheLoop->getLoopPreheader();
   BasicBlock *Header = TheLoop->getHeader();
@@ -2416,8 +2436,13 @@ bool LoopVectorizationLegality::canVecto
         // If this PHINode is not in the header block, then we know that we
         // can convert it to select during if-conversion. No need to check if
         // the PHIs in this block are induction or reduction variables.
-        if (*bb != Header)
-          continue;
+        if (*bb != Header) {
+          // Check that this instruction has no outside users or is an
+          // identified reduction value with an outside user.
+          if(!hasOutsideLoopUser(TheLoop, it, AllowedExit))
+            continue;
+          return false;
+        }
 
         // We only allow if-converted PHIs with more than two incoming values.
         if (Phi->getNumIncomingValues() != 2) {
@@ -2510,17 +2535,9 @@ bool LoopVectorizationLegality::canVecto
 
       // Reduction instructions are allowed to have exit users.
       // All other instructions must not have external users.
-      if (!AllowedExit.count(it))
-        //Check that all of the users of the loop are inside the BB.
-        for (Value::use_iterator I = it->use_begin(), E = it->use_end();
-             I != E; ++I) {
-          Instruction *U = cast<Instruction>(*I);
-          // This user may be a reduction exit value.
-          if (!TheLoop->contains(U)) {
-            DEBUG(dbgs() << "LV: Found an outside user for : "<< *U << "\n");
-            return false;
-          }
-        }
+      if (hasOutsideLoopUser(TheLoop, it, AllowedExit))
+        return false;
+
     } // next instr.
 
   }





More information about the llvm-branch-commits mailing list