move a transformation to a more logical place, simplifying it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122183 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp
index b215ee8..5fa930e 100644
--- a/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1147,6 +1147,13 @@
           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: