Fix future bug. Of course, Chris spotted this.
authorDevang Patel <dpatel@apple.com>
Mon, 9 Apr 2007 16:41:46 +0000 (16:41 +0000)
committerDevang Patel <dpatel@apple.com>
Mon, 9 Apr 2007 16:41:46 +0000 (16:41 +0000)
Handle Argument or Undef as an incoming PHI value.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35821 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopRotation.cpp

index 21430d704fc66e9034c1c4951ddb4349fb120be4..4fab1bf7c75d2489f0f9f8546d0a29b0d7fa912e 100644 (file)
@@ -369,7 +369,6 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
   return true;
 }
 
-
 /// Make sure all Exit block PHINodes have required incoming values.
 /// If incoming value is constant or defined outside the loop then
 /// PHINode may not have an entry for new pre-header. 
@@ -382,20 +381,22 @@ void LoopRotate::updateExitBlock() {
     if (!PN)
       break;
 
-    if (PN->getBasicBlockIndex(NewPreHeader) == -1) {
-      Value *V = PN->getIncomingValueForBlock(OrigHeader);
-      if (isa<Constant>(V))
-        PN->addIncoming(V, NewPreHeader);
-      else {
-        RenameData *ILoopHeaderInfo = findReplacementData(cast<Instruction>(V));
-        assert (ILoopHeaderInfo && ILoopHeaderInfo->PreHeader && "Missing New Preheader Instruction");
-        PN->addIncoming(ILoopHeaderInfo->PreHeader, NewPreHeader);
-      }
+    // There is already one incoming value from new pre-header block.
+    if (PN->getBasicBlockIndex(NewPreHeader) != -1)
+      return;
+
+    RenameData *ILoopHeaderInfo;
+    Value *V = PN->getIncomingValueForBlock(OrigHeader);
+    if (isa<Instruction>(V) && 
+        (ILoopHeaderInfo = findReplacementData(cast<Instruction>(V)))) {
+      assert (ILoopHeaderInfo->PreHeader && "Missing New Preheader Instruction");
+      PN->addIncoming(ILoopHeaderInfo->PreHeader, NewPreHeader);
+    } else {
+      PN->addIncoming(V, NewPreHeader);
     }
   }
 }
 
-
 /// Initialize local data
 void LoopRotate::initialize() {
   L = NULL;