]> granicus.if.org Git - llvm/commitdiff
[InstCombine] Use isSignBitCheck to simplify an if statement. Directly create new...
authorCraig Topper <craig.topper@intel.com>
Tue, 3 Oct 2017 19:14:23 +0000 (19:14 +0000)
committerCraig Topper <craig.topper@intel.com>
Tue, 3 Oct 2017 19:14:23 +0000 (19:14 +0000)
Since we no longer had the direct constant compares, manipulating the constant seemeded less clear.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314830 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp

index 5155fa4b0fd493f0d80b98c8ed4fb1328693e00c..00feb01de400eff7ecd9eea7f98ad8c8c1ce40a0 100644 (file)
@@ -1457,8 +1457,8 @@ Instruction *InstCombiner::foldICmpXorConstant(ICmpInst &Cmp,
   // If this is a comparison that tests the signbit (X < 0) or (x > -1),
   // fold the xor.
   ICmpInst::Predicate Pred = Cmp.getPredicate();
-  if ((Pred == ICmpInst::ICMP_SLT && C.isNullValue()) ||
-      (Pred == ICmpInst::ICMP_SGT && C.isAllOnesValue())) {
+  bool TrueIfSigned = false;
+  if (isSignBitCheck(Cmp.getPredicate(), C, TrueIfSigned)) {
 
     // If the sign bit of the XorCst is not set, there is no change to
     // the operation, just stop using the Xor.
@@ -1468,17 +1468,13 @@ Instruction *InstCombiner::foldICmpXorConstant(ICmpInst &Cmp,
       return &Cmp;
     }
 
-    // Was the old condition true if the operand is positive?
-    bool isTrueIfPositive = Pred == ICmpInst::ICMP_SGT;
-
-    // If so, the new one isn't.
-    isTrueIfPositive ^= true;
-
-    Constant *CmpConstant = cast<Constant>(Cmp.getOperand(1));
-    if (isTrueIfPositive)
-      return new ICmpInst(ICmpInst::ICMP_SGT, X, SubOne(CmpConstant));
+    // Emit the opposite comparison.
+    if (TrueIfSigned)
+      return new ICmpInst(ICmpInst::ICMP_SGT, X,
+                          ConstantInt::getAllOnesValue(X->getType()));
     else
-      return new ICmpInst(ICmpInst::ICMP_SLT, X, AddOne(CmpConstant));
+      return new ICmpInst(ICmpInst::ICMP_SLT, X,
+                          ConstantInt::getNullValue(X->getType()));
   }
 
   if (Xor->hasOneUse()) {