Fix a minor bug where we would go into infinite loops on some constants
authorChris Lattner <sabre@nondot.org>
Tue, 6 Jul 2004 07:11:42 +0000 (07:11 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 6 Jul 2004 07:11:42 +0000 (07:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14638 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index fad2730d84c370f696878c4e1e5f821d9cd9eb45..be1111fbd537a2726086b8e119497366716bb5d5 100644 (file)
@@ -846,7 +846,8 @@ Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
 Instruction *InstCombiner::visitRem(BinaryOperator &I) {
   if (I.getType()->isSigned())
     if (Value *RHSNeg = dyn_castNegVal(I.getOperand(1)))
-      if (RHSNeg != I.getOperand(1)) {           // Avoid problems with MININT
+      if (!isa<ConstantSInt>(RHSNeg) ||
+          cast<ConstantSInt>(RHSNeg)->getValue() >= 0) {
         // X % -Y -> X % Y
         AddUsesToWorkList(I);
         I.setOperand(1, RHSNeg);