[llvm-commits] [llvm] r126124 - in /llvm/trunk: lib/Transforms/Utils/Local.cpp unittests/Transforms/Utils/Local.cpp

Nick Lewycky nicholas at mxc.ca
Mon Feb 21 14:18:36 PST 2011


Duncan Sands wrote:
> Author: baldrick
> Date: Mon Feb 21 10:27:36 2011
> New Revision: 126124
>
> URL: http://llvm.org/viewvc/llvm-project?rev=126124&view=rev
> Log:
> Simplify RecursivelyDeleteDeadPHINode.  The only functionality change
> should be that if the phi is used by a side-effect free instruction with
> no uses then the phi and the instruction now get zapped (checked by the
> unittest).
>
> Modified:
>      llvm/trunk/lib/Transforms/Utils/Local.cpp
>      llvm/trunk/unittests/Transforms/Utils/Local.cpp
>
> Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=126124&r1=126123&r2=126124&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/Local.cpp Mon Feb 21 10:27:36 2011
> @@ -262,12 +262,13 @@
>
>   /// areAllUsesEqual - Check whether the uses of a value are all the same.
>   /// This is similar to Instruction::hasOneUse() except this will also return
> -/// true when there are multiple uses that all refer to the same value.
> +/// true when there are no uses or multiple uses that all refer to the same
> +/// value.
>   static bool areAllUsesEqual(Instruction *I) {
>     Value::use_iterator UI = I->use_begin();
>     Value::use_iterator UE = I->use_end();
>     if (UI == UE)
> -    return false;
> +    return true;
>
>     User *TheUse = *UI;
>     for (++UI; UI != UE; ++UI) {
> @@ -283,34 +284,21 @@
>   /// delete it.  If that makes any of its operands trivially dead, delete them
>   /// too, recursively.  Return true if the PHI node is actually deleted.
>   bool llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
> -  if (PN->use_empty()) {
> -    PN->eraseFromParent();
> -    return true;
> -  }
> -
> -  // We can remove a PHI if it is on a cycle in the def-use graph
> -  // where each node in the cycle has degree one, i.e. only one use,
> -  // and is an instruction with no side effects.
> -  if (!areAllUsesEqual(PN))
> -    return false;
> +  SmallPtrSet<Instruction*, 4>  Visited;
> +  for (Instruction *I = PN; areAllUsesEqual(I)&&  !I->mayHaveSideEffects();
> +       I = cast<Instruction>(*I->use_begin())) {
> +    if (I->use_empty())
> +      return RecursivelyDeleteTriviallyDeadInstructions(I);
>
> -  bool Changed = false;
> -  SmallPtrSet<PHINode *, 4>  PHIs;
> -  PHIs.insert(PN);
> -  for (Instruction *I = cast<Instruction>(*PN->use_begin());
> -       areAllUsesEqual(I)&&  !I->mayHaveSideEffects();
> -       I = cast<Instruction>(*I->use_begin()))
> -    // If we find a PHI more than once, we're on a cycle that
> +    // If we find an instruction more than once, we're on a cycle that
>       // won't prove fruitful.
> -    if (PHINode *IP = dyn_cast<PHINode>(I))
> -      if (!PHIs.insert(IP)) {
> -        // Break the cycle and delete the PHI and its operands.
> -        IP->replaceAllUsesWith(UndefValue::get(IP->getType()));
> -        (void)RecursivelyDeleteTriviallyDeadInstructions(IP);
> -        Changed = true;
> -        break;
> -      }
> -  return Changed;
> +    if (!Visited.insert(I)) {
> +      // Break the cycle and delete the instruction and its operands.
> +      I->replaceAllUsesWith(UndefValue::get(I->getType()));
> +      return RecursivelyDeleteTriviallyDeadInstructions(I);

return RecursivelyDeleteTriviallyDeadInstructions(I) || Changed; ?

Nick

> +    }
> +  }
> +  return false;
>   }
>
>   /// SimplifyInstructionsInBlock - Scan the specified basic block and try to
>
> Modified: llvm/trunk/unittests/Transforms/Utils/Local.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/Local.cpp?rev=126124&r1=126123&r2=126124&view=diff
> ==============================================================================
> --- llvm/trunk/unittests/Transforms/Utils/Local.cpp (original)
> +++ llvm/trunk/unittests/Transforms/Utils/Local.cpp Mon Feb 21 10:27:36 2011
> @@ -47,6 +47,12 @@
>
>     EXPECT_TRUE(RecursivelyDeleteDeadPHINode(phi));
>
> +  builder.SetInsertPoint(bb0);
> +  phi = builder.CreatePHI(Type::getInt32Ty(C));
> +  builder.CreateAdd(phi, phi);
> +
> +  EXPECT_TRUE(RecursivelyDeleteDeadPHINode(phi));
> +
>     bb0->dropAllReferences();
>     bb1->dropAllReferences();
>     delete bb0;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>




More information about the llvm-commits mailing list