summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2017-10-03 19:14:23 +0000
committerCraig Topper <craig.topper@intel.com>2017-10-03 19:14:23 +0000
commitdf63b96811d6faea8ccaac79780af9ab2a629356 (patch)
treebd96cf259c38fbc0544b8c8b4bf0ae1a90fd08ba /llvm/lib
parent72800f0436e8420a96f54f48b187a58c161317db (diff)
downloadbcm5719-llvm-df63b96811d6faea8ccaac79780af9ab2a629356.tar.gz
bcm5719-llvm-df63b96811d6faea8ccaac79780af9ab2a629356.zip
[InstCombine] Use isSignBitCheck to simplify an if statement. Directly create new sign bit compares instead of manipulating the constant. NFCI
Since we no longer had the direct constant compares, manipulating the constant seemeded less clear. llvm-svn: 314830
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 5155fa4b0fd..00feb01de40 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -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()) {
OpenPOWER on IntegriCloud