[ARM] Disallow icmp with negative imm and overflow

We allow overflowing instructions if they're decreasing and only used
by an unsigned compare. Add the extra condition that the icmp cannot
be using a negative immediate.

Differential Revision: https://reviews.llvm.org/D52102

llvm-svn: 342392
diff --git a/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp b/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp
index e06f05a..a1241b7 100644
--- a/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp
+++ b/llvm/lib/Target/ARM/ARMCodeGenPrepare.cpp
@@ -257,9 +257,20 @@
       return false;
 
     auto *CI = cast<ICmpInst>(*I->user_begin());
+    
+    // Don't support an icmp that deals with sign bits, including negative
+    // immediates
     if (CI->isSigned())
       return false;
 
+    if (auto *Const = dyn_cast<ConstantInt>(CI->getOperand(0)))
+      if (Const->isNegative())
+        return false;
+
+    if (auto *Const = dyn_cast<ConstantInt>(CI->getOperand(1)))
+      if (Const->isNegative())
+        return false;
+
     bool NegImm = cast<ConstantInt>(I->getOperand(1))->isNegative();
     bool IsDecreasing = ((Opc == Instruction::Sub) && !NegImm) ||
                         ((Opc == Instruction::Add) && NegImm);