[llvm-commits] [llvm] r48252 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/two-entry-phi-return.ll

Dan Gohman gohman at apple.com
Tue Mar 11 14:53:07 PDT 2008


Author: djg
Date: Tue Mar 11 16:53:06 2008
New Revision: 48252

URL: http://llvm.org/viewvc/llvm-project?rev=48252&view=rev
Log:
Check to see if a two-entry PHI block can be simplified
before trying to merge the block into its predecessors.
This allows two-entry-phi-return.ll to be simplified
into a single basic block.

Added:
    llvm/trunk/test/Transforms/SimplifyCFG/two-entry-phi-return.ll
Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=48252&r1=48251&r2=48252&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Tue Mar 11 16:53:06 2008
@@ -1224,6 +1224,12 @@
   // away...
   Changed |= ConstantFoldTerminator(BB);
 
+  // If there is a trivial two-entry PHI node in this basic block, and we can
+  // eliminate it, do so now.
+  if (PHINode *PN = dyn_cast<PHINode>(BB->begin()))
+    if (PN->getNumIncomingValues() == 2)
+      Changed |= FoldTwoEntryPHINode(PN); 
+
   // If this is a returning block with only PHI nodes in it, fold the return
   // instruction into any unconditional branch predecessors.
   //
@@ -1915,11 +1921,5 @@
         }
       }
 
-  // If there is a trivial two-entry PHI node in this basic block, and we can
-  // eliminate it, do so now.
-  if (PHINode *PN = dyn_cast<PHINode>(BB->begin()))
-    if (PN->getNumIncomingValues() == 2)
-      Changed |= FoldTwoEntryPHINode(PN); 
-
   return Changed;
 }

Added: llvm/trunk/test/Transforms/SimplifyCFG/two-entry-phi-return.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/two-entry-phi-return.ll?rev=48252&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/two-entry-phi-return.ll (added)
+++ llvm/trunk/test/Transforms/SimplifyCFG/two-entry-phi-return.ll Tue Mar 11 16:53:06 2008
@@ -0,0 +1,15 @@
+; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | not grep br
+
+define i1 @qux(i8* %m, i8* %n, i8* %o, i8* %p) nounwind  {
+entry:
+        %tmp7 = icmp eq i8* %m, %n
+        br i1 %tmp7, label %bb, label %UnifiedReturnBlock
+
+bb:
+        %tmp15 = icmp eq i8* %o, %p
+        br label %UnifiedReturnBlock
+
+UnifiedReturnBlock:
+        %result = phi i1 [ 0, %entry ], [ %tmp15, %bb ]
+        ret i1 %result
+}





More information about the llvm-commits mailing list