move a transformation to a more logical place, simplifying it.
authorChris Lattner <sabre@nondot.org>
Sun, 19 Dec 2010 19:43:52 +0000 (19:43 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 19 Dec 2010 19:43:52 +0000 (19:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122183 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCalls.cpp
lib/Transforms/InstCombine/InstructionCombining.cpp

index f3a5e724c61a17d19b980d149bf62fdece4abdca..d53f3291e717cfd69af0f9f4904cbbcbf0f1439b 100644 (file)
@@ -523,21 +523,6 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
         return InsertValueInst::Create(Struct, Add, 0);
       }
     }
-    
-    // If the normal result of the add is dead, and the RHS is a constant, we
-    // can transform this into a range comparison.
-    // overflow = uadd a, -4  -->  overflow = icmp ugt a, 3
-    if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS))
-      if (ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(II->use_back()))
-        if (II->hasOneUse() && EVI->getNumIndices() == 1 && !EVI->use_empty() &&
-            *EVI->idx_begin() == 1) {  // Extract of overflow result.
-          Builder->SetInsertPoint(EVI);
-          Value *R = Builder->CreateICmpUGT(LHS, ConstantExpr::getNot(CI));
-          R->takeName(EVI);
-          ReplaceInstUsesWith(*EVI, R);
-          return II;
-        }
-    
   }
   // FALL THROUGH uadd into sadd
   case Intrinsic::sadd_with_overflow:
@@ -565,7 +550,6 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
         return InsertValueInst::Create(Struct, II->getArgOperand(0), 0);
       }
     }
-      
     break;
   case Intrinsic::usub_with_overflow:
   case Intrinsic::ssub_with_overflow:
index b215ee817b12eefb9d18a213c9c63f2907121f22..5fa930e7541241f87f4cf632de2727f9a5735da9 100644 (file)
@@ -1147,6 +1147,13 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) {
           EraseInstFromFunction(*II);
           return BinaryOperator::CreateAdd(LHS, RHS);
         }
+          
+        // If the normal result of the add is dead, and the RHS is a constant,
+        // we can transform this into a range comparison.
+        // overflow = uadd a, -4  -->  overflow = icmp ugt a, 3
+        if (ConstantInt *CI = dyn_cast<ConstantInt>(II->getArgOperand(1)))
+          return new ICmpInst(ICmpInst::ICMP_UGT, II->getArgOperand(0),
+                              ConstantExpr::getNot(CI));
         break;
       case Intrinsic::usub_with_overflow:
       case Intrinsic::ssub_with_overflow: