I found a better place for this optz'n.
authorNick Lewycky <nicholas@mxc.ca>
Sun, 17 Aug 2008 07:54:14 +0000 (07:54 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Sun, 17 Aug 2008 07:54:14 +0000 (07:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54877 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 065507f060e0ef71b2458a1b666bfdb5d149ee51..32232a6588913b7cbd2c84f78888226bfc2ef21d 100644 (file)
@@ -5241,20 +5241,6 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
       return new ICmpInst(I.getPredicate(), A, B);
     }
     
-    ConstantInt *CI2;
-    // (icmp u/s (xor A SignBit), C) -> (icmp s/u A, (xor C SignBit))
-    if (!I.isEquality() &&
-        match(Op0, m_Xor(m_Value(A), m_ConstantInt(CI2)))) {
-      if (CI2->getValue().isSignBit()) {
-        const APInt &SignBit = CI2->getValue();
-        ICmpInst::Predicate Pred = I.isSignedPredicate()
-                                       ? I.getUnsignedPredicate()
-                                       : I.getSignedPredicate();
-        return new ICmpInst(Pred, A,
-                            ConstantInt::get(CI->getValue() ^ SignBit));
-      }
-    }
-
     // If we have a icmp le or icmp ge instruction, turn it into the appropriate
     // icmp lt or icmp gt instruction.  This allows us to rely on them being
     // folded in the code below.
@@ -5822,6 +5808,16 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
         else
           return new ICmpInst(ICmpInst::ICMP_SLT, CompareVal, AddOne(RHS));
       }
+
+      // (icmp u/s (xor A SignBit), C) -> (icmp s/u A, (xor C SignBit))
+      if (!ICI.isEquality() && XorCST->getValue().isSignBit()) {
+        const APInt &SignBit = XorCST->getValue();
+        ICmpInst::Predicate Pred = ICI.isSignedPredicate()
+                                       ? ICI.getUnsignedPredicate()
+                                       : ICI.getSignedPredicate();
+        return new ICmpInst(Pred, LHSI->getOperand(0),
+                            ConstantInt::get(RHSV ^ SignBit));
+      }
     }
     break;
   case Instruction::And:         // (icmp pred (and X, AndCST), RHS)