[llvm-commits] [llvm] r119043 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp lib/Transforms/InstCombine/InstCombinePHI.cpp test/Transforms/GVN/2007-07-26-InterlockingLoops.ll test/Transforms/GVN/2010-03-31-RedundantPHIs.ll

Duncan Sands baldrick at free.fr
Sun Nov 14 05:30:18 PST 2010


Author: baldrick
Date: Sun Nov 14 07:30:18 2010
New Revision: 119043

URL: http://llvm.org/viewvc/llvm-project?rev=119043&view=rev
Log:
Teach InstructionSimplify about phi nodes.  I chose to have it simply
offload the work to hasConstantValue rather than do something more
complicated (such handling mutually recursive phis) because (1) it is
not clear it is worth it; and (2) if it is worth it, maybe such logic
would be better placed in hasConstantValue.  Adjust some GVN tests
which are now cleaned up much further (eg: all phi nodes are removed).

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
    llvm/trunk/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll
    llvm/trunk/test/Transforms/GVN/2010-03-31-RedundantPHIs.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=119043&r1=119042&r2=119043&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sun Nov 14 07:30:18 2010
@@ -699,6 +699,8 @@
     SmallVector<Value*, 8> Ops(I->op_begin(), I->op_end());
     return SimplifyGEPInst(&Ops[0], Ops.size(), TD);
   }
+  case Instruction::PHI:
+    return cast<PHINode>(I)->hasConstantValue();
   }
 }
 

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp?rev=119043&r1=119042&r2=119043&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp Sun Nov 14 07:30:18 2010
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "InstCombine.h"
+#include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/STLExtras.h"
@@ -731,8 +732,8 @@
 Instruction *InstCombiner::visitPHINode(PHINode &PN) {
   // If LCSSA is around, don't mess with Phi nodes
   if (MustPreserveLCSSA) return 0;
-  
-  if (Value *V = PN.hasConstantValue())
+
+  if (Value *V = SimplifyInstruction(&PN, TD))
     return ReplaceInstUsesWith(PN, V);
 
   // If all PHI operands are the same operation, pull them through the PHI,

Modified: llvm/trunk/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll?rev=119043&r1=119042&r2=119043&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll (original)
+++ llvm/trunk/test/Transforms/GVN/2007-07-26-InterlockingLoops.ll Sun Nov 14 07:30:18 2010
@@ -1,30 +1,33 @@
-; RUN: opt < %s -basicaa -gvn -S | grep {tmp17625.* = phi i32. }
-; RUN: opt < %s -basicaa -gvn -S | grep {tmp17631.* = phi i32. }
+; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
 
- at last = external global [65 x i32*]		; <[65 x i32*]*> [#uses=1]
+ at last = external global [65 x i32*]
 
 define i32 @NextRootMove(i32 %wtm) {
-cond_next95:		; preds = %cond_true85, %cond_true79, %cond_true73, %bb68
-	%tmp17618 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4		; <i32*> [#uses=0]
+entry:
+	%tmp17618 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4
+; CHECK: entry:
+; CHECK-NEXT: %tmp17618 = load
+; CHECK-NOT: load
+; CHECK-NOT: phi
 	br label %cond_true116
 
-cond_true116:		; preds = %cond_true111
+cond_true116:
 	br i1 false, label %cond_true128, label %cond_true145
 
-cond_true128:		; preds = %cond_true121
-	%tmp17625 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4		; <i32*> [#uses=0]
+cond_true128:
+	%tmp17625 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4
 	br i1 false, label %bb98.backedge, label %return.loopexit
 
-bb98.backedge:		; preds = %bb171, %cond_true145, %cond_true128
+bb98.backedge:
 	br label %cond_true116
 
-cond_true145:		; preds = %cond_false
-	%tmp17631 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4		; <i32*> [#uses=0]
+cond_true145:
+	%tmp17631 = load i32** getelementptr ([65 x i32*]* @last, i32 0, i32 1), align 4
 	br i1 false, label %bb98.backedge, label %return.loopexit
 
-return.loopexit:		; preds = %bb171, %cond_true145, %cond_true128
+return.loopexit:
 	br label %return
 
-return:		; preds = %return.loopexit, %cond_next95, %cond_true85
+return:
 	ret i32 0
 }

Modified: llvm/trunk/test/Transforms/GVN/2010-03-31-RedundantPHIs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/2010-03-31-RedundantPHIs.ll?rev=119043&r1=119042&r2=119043&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/2010-03-31-RedundantPHIs.ll (original)
+++ llvm/trunk/test/Transforms/GVN/2010-03-31-RedundantPHIs.ll Sun Nov 14 07:30:18 2010
@@ -1,5 +1,8 @@
 ; RUN: opt < %s -basicaa -gvn -S | FileCheck %s
 
+; CHECK-NOT: load
+; CHECK-NOT: phi
+
 define i8* @cat(i8* %s1, ...) nounwind {
 entry:
   br i1 undef, label %bb, label %bb3
@@ -29,18 +32,11 @@
   br label %bb11
 
 bb11:                                             ; preds = %bb10, %bb9
-; CHECK: bb11:
-; CHECK: phi
-; CHECK-NOT: phi
   br label %bb12
 
 bb12:                                             ; preds = %bb11, %bb6
-; CHECK: bb12:
-; CHECK: phi
-; CHECK-NOT: phi
   br i1 undef, label %bb8, label %bb13
 
 bb13:                                             ; preds = %bb12
-; CHECK: bb13:
   ret i8* undef
 }





More information about the llvm-commits mailing list