summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-12-21 19:21:59 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-12-21 19:21:59 +0000
commitb0761a0c1ba8ec77d3704d2450d481bc25e60a9d (patch)
tree60b39df917b295042b93ffd0f6df61f4f7255767 /llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
parentd8ea85acedc605f7e737ffb32b2b8f2a8f02c67f (diff)
downloadbcm5719-llvm-b0761a0c1ba8ec77d3704d2450d481bc25e60a9d.tar.gz
bcm5719-llvm-b0761a0c1ba8ec77d3704d2450d481bc25e60a9d.zip
Revert "[InstCombine] New opportunities for FoldAndOfICmp and FoldXorOfICmp"
This reverts commit r289813, it caused PR31449. llvm-svn: 290266
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp99
1 files changed, 2 insertions, 97 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 52b611faefa..a59b43d6af5 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -733,44 +733,6 @@ static Value *foldLogOpOfMaskedICmps(ICmpInst *LHS, ICmpInst *RHS, bool IsAnd,
return nullptr;
}
-namespace {
-
-struct BitGroupCheck {
- // If the Cmp, checks the bits in the group are nonzero?
- bool CheckIfSet {false};
- // The mask that identifies the bitgroup in question.
- const APInt *Mask {nullptr};
-};
-}
-/// For an ICMP where RHS is zero, we want to check if the ICMP is equivalent to
-/// comparing a group of bits in an integer value against zero.
-BitGroupCheck isAnyBitSet(Value *LHS, ICmpInst::Predicate CC) {
-
- BitGroupCheck BGC;
- auto *Inst = dyn_cast<Instruction>(LHS);
-
- if (!Inst || Inst->getOpcode() != Instruction::And)
- return BGC;
-
- // TODO Currently this does not work for vectors.
- ConstantInt *Mask;
- if (!match(LHS, m_And(m_Value(), m_ConstantInt(Mask))))
- return BGC;
- // At this point we know that LHS of ICMP is "and" of a value with a constant.
- // Also we know that the RHS is zero. That means we are checking if a certain
- // group of bits in a given integer value are all zero or at least one of them
- // is set to one.
- if (CC == ICmpInst::ICMP_EQ)
- BGC.CheckIfSet = false;
- else if (CC == ICmpInst::ICMP_NE)
- BGC.CheckIfSet = true;
- else
- return BGC;
-
- BGC.Mask = &Mask->getValue();
- return BGC;
-}
-
/// Try to fold a signed range checked with lower bound 0 to an unsigned icmp.
/// Example: (icmp sge x, 0) & (icmp slt x, n) --> icmp ult x, n
/// If \p Inverted is true then the check is for the inverted range, e.g.
@@ -827,32 +789,6 @@ Value *InstCombiner::simplifyRangeCheck(ICmpInst *Cmp0, ICmpInst *Cmp1,
return Builder->CreateICmp(NewPred, Input, RangeEnd);
}
-Value *InstCombiner::FoldXorOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
-
- Value *Val = LHS->getOperand(0), *Val2 = RHS->getOperand(0);
- // TODO The lines below does not work for vectors. ConstantInt is scalar.
- auto *LHSCst = dyn_cast<ConstantInt>(LHS->getOperand(1));
- auto *RHSCst = dyn_cast<ConstantInt>(RHS->getOperand(1));
- if (!LHSCst || !RHSCst)
- return nullptr;
- ICmpInst::Predicate LHSCC = LHS->getPredicate(), RHSCC = RHS->getPredicate();
-
- // E.g. (icmp ne %x, 0) ^ (icmp ne %y, 0) => icmp ne %x, %y if the following
- // conditions hold:
- // 1- (%x = and %a, %mask) and (%y = and %b, %mask)
- // 2- %mask is a power of 2.
- if (RHSCst->isZero() && LHSCst == RHSCst) {
-
- BitGroupCheck BGC1 = isAnyBitSet(Val, LHSCC);
- BitGroupCheck BGC2 = isAnyBitSet(Val2, RHSCC);
- if (BGC1.Mask && BGC2.Mask && BGC1.CheckIfSet == BGC2.CheckIfSet &&
- *BGC1.Mask == *BGC2.Mask && BGC1.Mask->isPowerOf2()) {
- return Builder->CreateICmp(ICmpInst::ICMP_NE, Val2, Val);
- }
- }
- return nullptr;
-}
-
/// Fold (icmp)&(icmp) if possible.
Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
ICmpInst::Predicate LHSCC = LHS->getPredicate(), RHSCC = RHS->getPredicate();
@@ -935,29 +871,6 @@ Value *InstCombiner::FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
}
}
- // E.g. (icmp eq %x, 0) & (icmp ne %y, 0) => icmp ult %x, %y if the following
- // conditions hold:
- // 1- (%x = and %a, %mask1) and (%y = and %b, %mask2)
- // 2- Let %t be the smallest power of 2 where %mask1 & %t != 0. Then for any
- // %s that is a power of 2 and %s & %mask2 != 0, we must have %s <= %t.
- // For example if %mask1 = 24 and %mask2 = 16, setting %s = 16 and %t = 8
- // violates condition (2) above. So this optimization cannot be applied.
- if (RHSCst->isZero() && LHSCst == RHSCst) {
- BitGroupCheck BGC1 = isAnyBitSet(Val, LHSCC);
- BitGroupCheck BGC2 = isAnyBitSet(Val2, RHSCC);
-
- if (BGC1.Mask && BGC2.Mask && (BGC1.CheckIfSet != BGC2.CheckIfSet)) {
- if (!BGC1.CheckIfSet &&
- BGC1.Mask->countTrailingZeros() >=
- BGC2.Mask->getBitWidth() - BGC2.Mask->countLeadingZeros() - 1)
- return Builder->CreateICmp(ICmpInst::ICMP_ULT, Val, Val2);
- else if (!BGC2.CheckIfSet &&
- BGC2.Mask->countTrailingZeros() >=
- BGC1.Mask->getBitWidth() - BGC1.Mask->countLeadingZeros() - 1)
- return Builder->CreateICmp(ICmpInst::ICMP_ULT, Val2, Val);
- }
- }
-
// From here on, we only handle:
// (icmp1 A, C1) & (icmp2 A, C2) --> something simpler.
if (Val != Val2) return nullptr;
@@ -2808,16 +2721,9 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
match(Op1, m_Not(m_Specific(A))))
return BinaryOperator::CreateNot(Builder->CreateAnd(A, B));
+ // (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 A, B)
if (ICmpInst *RHS = dyn_cast<ICmpInst>(I.getOperand(1)))
- if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0))) {
-
- // E.g. if we have xor (icmp eq %A, 0), (icmp eq %B, 0)
- // and we know both A and B are either 8 (power of 2) or 0
- // we can simplify to (icmp ne A, B).
- if (Value *Res = FoldXorOfICmps(LHS, RHS))
- return replaceInstUsesWith(I, Res);
-
- // (icmp1 A, B) ^ (icmp2 A, B) --> (icmp3 A, B)
+ if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0)))
if (PredicatesFoldable(LHS->getPredicate(), RHS->getPredicate())) {
if (LHS->getOperand(0) == RHS->getOperand(1) &&
LHS->getOperand(1) == RHS->getOperand(0))
@@ -2832,7 +2738,6 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
Builder));
}
}
- }
if (Instruction *CastedXor = foldCastedBitwiseLogic(I))
return CastedXor;
OpenPOWER on IntegriCloud