[llvm] r275217 - [LV] Remove wrong assumption about LCSSA

Michael Kuperstein via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 12 14:24:06 PDT 2016


Author: mkuper
Date: Tue Jul 12 16:24:06 2016
New Revision: 275217

URL: http://llvm.org/viewvc/llvm-project?rev=275217&view=rev
Log:
[LV] Remove wrong assumption about LCSSA

The LCSSA pass itself will not generate several redundant PHI nodes in a single
exit block. However, such redundant PHI nodes don't violate LCSSA form, and may
be introduced by passes that preserve LCSSA, and/or preserved by the LCSSA pass
itself. So, assuming a single PHI node per exit block is not safe.

Modified:
    llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
    llvm/trunk/test/Transforms/LoopVectorize/iv_outside_user.ll

Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=275217&r1=275216&r2=275217&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Tue Jul 12 16:24:06 2016
@@ -3112,9 +3112,6 @@ void InnerLoopVectorizer::fixupIVUsers(P
   // value (the value that feeds into the phi from the loop latch).
   // We allow both, but they, obviously, have different values.
 
-  // We only expect at most one of each kind of user. This is because LCSSA will
-  // canonicalize the users to a single PHI node per exit block, and we
-  // currently only vectorize loops with a single exit.
   assert(OrigLoop->getExitBlock() && "Expected a single exit block");
 
   // An external user of the last iteration's value should see the value that
@@ -3132,7 +3129,6 @@ void InnerLoopVectorizer::fixupIVUsers(P
       auto *User = cast<PHINode>(UI);
       if (User->getBasicBlockIndex(MiddleBlock) == -1)
         User->addIncoming(EndValue, MiddleBlock);
-      break;
     }
   }
 
@@ -3159,7 +3155,6 @@ void InnerLoopVectorizer::fixupIVUsers(P
       Value *Escape = II.transform(B, CMO, PSE.getSE(), DL);
       Escape->setName("ind.escape");
       User->addIncoming(Escape, MiddleBlock);
-      break;
     }
   }
 }

Modified: llvm/trunk/test/Transforms/LoopVectorize/iv_outside_user.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVectorize/iv_outside_user.ll?rev=275217&r1=275216&r2=275217&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopVectorize/iv_outside_user.ll (original)
+++ llvm/trunk/test/Transforms/LoopVectorize/iv_outside_user.ll Tue Jul 12 16:24:06 2016
@@ -108,3 +108,28 @@ for.body:
 for.end:
   ret i32* %inc.lag1
 }
+
+; CHECK-LABEL: @multiphi
+; CHECK-LABEL: scalar.ph:
+; CHECK: %bc.resume.val = phi i32 [ %n.vec, %middle.block ], [ 0, %entry ]
+; CHECK-LABEL: for.end:
+; CHECK: %phi = phi i32 [ {{.*}}, %for.body ], [ %n.vec, %middle.block ]
+; CHECK: %phi2 = phi i32 [ {{.*}}, %for.body ], [ %n.vec, %middle.block ]
+; CHECK: store i32 %phi2, i32* %p
+; CHECK: ret i32 %phi
+define i32 @multiphi(i32 %k, i32* %p)  {
+entry:
+  br label %for.body
+
+for.body:
+  %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+  %inc = add nsw i32 %inc.phi, 1
+  %cmp = icmp eq i32 %inc, %k
+  br i1 %cmp, label %for.end, label %for.body
+
+for.end:
+  %phi = phi i32 [ %inc, %for.body ]
+  %phi2 = phi i32 [ %inc, %for.body ]
+  store i32 %phi2, i32* %p
+  ret i32 %phi
+}




More information about the llvm-commits mailing list