If the phi node was used by an unreachable instruction that ends up using
authorDuncan Sands <baldrick@free.fr>
Mon, 21 Feb 2011 17:32:05 +0000 (17:32 +0000)
committerDuncan Sands <baldrick@free.fr>
Mon, 21 Feb 2011 17:32:05 +0000 (17:32 +0000)
itself without going via a phi node then we could return false here in
spite of making a change.  Also, tweak the comment because this method
can (and always could) return true without deleting the original phi node.
For example, if the phi node was used by a read-only invoke instruction
which is used by another phi node phi2 which is only used by and only uses
the invoke, then phi2 would be deleted but not the invoke instruction and
not the original phi node.

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

include/llvm/Transforms/Utils/Local.h
lib/Transforms/Utils/Local.cpp

index 26b5dd8365f193800be955dbc4e227aa3df97317..2823fbb71997e8d4a1cb2200cb817d02b918d75c 100644 (file)
@@ -60,7 +60,7 @@ bool RecursivelyDeleteTriviallyDeadInstructions(Value *V);
 /// dead PHI node, due to being a def-use chain of single-use nodes that
 /// either forms a cycle or is terminated by a trivially dead instruction,
 /// delete it.  If that makes any of its operands trivially dead, delete them
-/// too, recursively.  Return true if the PHI node is actually deleted.
+/// too, recursively.  Return true if a change was made.
 bool RecursivelyDeleteDeadPHINode(PHINode *PN);
 
   
index 40a56b0c99a5728051379c1215668c51b8422631..3f789fa865897ac6f5bb3593752aabbfbc432faf 100644 (file)
@@ -282,7 +282,7 @@ static bool areAllUsesEqual(Instruction *I) {
 /// dead PHI node, due to being a def-use chain of single-use nodes that
 /// either forms a cycle or is terminated by a trivially dead instruction,
 /// delete it.  If that makes any of its operands trivially dead, delete them
-/// too, recursively.  Return true if the PHI node is actually deleted.
+/// too, recursively.  Return true if a change was made.
 bool llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
   SmallPtrSet<Instruction*, 4> Visited;
   for (Instruction *I = PN; areAllUsesEqual(I) && !I->mayHaveSideEffects();
@@ -295,7 +295,8 @@ bool llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
     if (!Visited.insert(I)) {
       // Break the cycle and delete the instruction and its operands.
       I->replaceAllUsesWith(UndefValue::get(I->getType()));
-      return RecursivelyDeleteTriviallyDeadInstructions(I);
+      (void)RecursivelyDeleteTriviallyDeadInstructions(I);
+      return true;
     }
   }
   return false;