[llvm-commits] [llvm] r119161 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstCombine/phi.ll

Duncan Sands baldrick at free.fr
Mon Nov 15 09:52:46 PST 2010


Author: baldrick
Date: Mon Nov 15 11:52:45 2010
New Revision: 119161

URL: http://llvm.org/viewvc/llvm-project?rev=119161&view=rev
Log:
Teach InstructionSimplify the trick of skipping incoming phi
values that are equal to the phi itself.

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstCombine/phi.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=119161&r1=119160&r2=119161&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Mon Nov 15 11:52:45 2010
@@ -142,9 +142,12 @@
   // Evaluate the BinOp on the incoming phi values.
   Value *CommonValue = 0;
   for (unsigned i = 0, e = PI->getNumIncomingValues(); i != e; ++i) {
+    Value *Incoming = PI->getIncomingValue(i);
+    // If the incoming value is the phi node itself, it can be safely skipped.
+    if (Incoming == PI) continue;
     Value *V = PI == LHS ?
-      SimplifyBinOp(Opcode, PI->getIncomingValue(i), RHS, TD, MaxRecurse) :
-      SimplifyBinOp(Opcode, LHS, PI->getIncomingValue(i), TD, MaxRecurse);
+      SimplifyBinOp(Opcode, Incoming, RHS, TD, MaxRecurse) :
+      SimplifyBinOp(Opcode, LHS, Incoming, TD, MaxRecurse);
     // If the operation failed to simplify, or simplified to a different value
     // to previously, then give up.
     if (!V || (CommonValue && V != CommonValue))
@@ -172,8 +175,10 @@
   // Evaluate the BinOp on the incoming phi values.
   Value *CommonValue = 0;
   for (unsigned i = 0, e = PI->getNumIncomingValues(); i != e; ++i) {
-    Value *V = SimplifyCmpInst(Pred, PI->getIncomingValue(i), RHS, TD,
-                               MaxRecurse);
+    Value *Incoming = PI->getIncomingValue(i);
+    // If the incoming value is the phi node itself, it can be safely skipped.
+    if (Incoming == PI) continue;
+    Value *V = SimplifyCmpInst(Pred, Incoming, RHS, TD, MaxRecurse);
     // If the operation failed to simplify, or simplified to a different value
     // to previously, then give up.
     if (!V || (CommonValue && V != CommonValue))

Modified: llvm/trunk/test/Transforms/InstCombine/phi.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/phi.ll?rev=119161&r1=119160&r2=119161&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/phi.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/phi.ll Mon Nov 15 11:52:45 2010
@@ -469,3 +469,22 @@
 ; CHECK: @test20
 ; CHECK: ret i1 false
 }
+
+define i1 @test21(i1 %c1, i1 %c2) {
+  %a = alloca i32
+  %b = alloca i32
+  %c = alloca i32
+  br i1 %c1, label %true, label %false
+true:
+  br label %loop
+false:
+  br label %loop
+loop:
+  %p = phi i32* [ %a, %true ], [ %b, %false ], [ %p, %loop ]
+  %r = icmp eq i32* %p, %c
+  br i1 %c2, label %ret, label %loop
+ret:
+  ret i1 %r
+; CHECK: @test21
+; CHECK: ret i1 false
+}





More information about the llvm-commits mailing list