1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

[Value Tracking] Default argument to true and rename accordingly. NFC.

IMHO this is a bit more readable.

llvm-svn: 309739
This commit is contained in:
Chad Rosier 2017-08-01 20:18:54 +00:00
parent 64cece2cf6
commit e36216c004
5 changed files with 19 additions and 21 deletions

View File

@ -528,8 +528,7 @@ template <typename T> class ArrayRef;
/// F | T | T
/// (A)
Optional<bool> isImpliedCondition(const Value *LHS, const Value *RHS,
const DataLayout &DL,
bool LHSIsFalse = false,
const DataLayout &DL, bool LHSIsTrue = true,
unsigned Depth = 0);
} // end namespace llvm

View File

@ -4452,14 +4452,14 @@ isImpliedCondMatchingImmOperands(CmpInst::Predicate APred, const Value *ALHS,
/// false. Otherwise, return None if we can't infer anything.
static Optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
const ICmpInst *RHS,
const DataLayout &DL, bool LHSIsFalse,
const DataLayout &DL, bool LHSIsTrue,
unsigned Depth) {
Value *ALHS = LHS->getOperand(0);
Value *ARHS = LHS->getOperand(1);
// The rest of the logic assumes the LHS condition is true. If that's not the
// case, invert the predicate to make it so.
ICmpInst::Predicate APred =
LHSIsFalse ? LHS->getInversePredicate() : LHS->getPredicate();
LHSIsTrue ? LHS->getPredicate() : LHS->getInversePredicate();
Value *BLHS = RHS->getOperand(0);
Value *BRHS = RHS->getOperand(1);
@ -4498,7 +4498,7 @@ static Optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
/// RHS to be an icmp and the LHS to be an 'and' or an 'or' instruction.
static Optional<bool> isImpliedCondAndOr(const BinaryOperator *LHS,
const ICmpInst *RHS,
const DataLayout &DL, bool LHSIsFalse,
const DataLayout &DL, bool LHSIsTrue,
unsigned Depth) {
// The LHS must be an 'or' or an 'and' instruction.
assert((LHS->getOpcode() == Instruction::And ||
@ -4513,14 +4513,14 @@ static Optional<bool> isImpliedCondAndOr(const BinaryOperator *LHS,
// false. Similarly, if the result of an 'and' is true, then we know both
// legs of the 'and' are true.
Value *ALHS, *ARHS;
if ((LHSIsFalse && match(LHS, m_Or(m_Value(ALHS), m_Value(ARHS)))) ||
(!LHSIsFalse && match(LHS, m_And(m_Value(ALHS), m_Value(ARHS))))) {
if ((!LHSIsTrue && match(LHS, m_Or(m_Value(ALHS), m_Value(ARHS)))) ||
(LHSIsTrue && match(LHS, m_And(m_Value(ALHS), m_Value(ARHS))))) {
// FIXME: Make this non-recursion.
if (Optional<bool> Implication =
isImpliedCondition(ALHS, RHS, DL, LHSIsFalse, Depth + 1))
isImpliedCondition(ALHS, RHS, DL, LHSIsTrue, Depth + 1))
return Implication;
if (Optional<bool> Implication =
isImpliedCondition(ARHS, RHS, DL, LHSIsFalse, Depth + 1))
isImpliedCondition(ARHS, RHS, DL, LHSIsTrue, Depth + 1))
return Implication;
return None;
}
@ -4528,7 +4528,7 @@ static Optional<bool> isImpliedCondAndOr(const BinaryOperator *LHS,
}
Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
const DataLayout &DL, bool LHSIsFalse,
const DataLayout &DL, bool LHSIsTrue,
unsigned Depth) {
// A mismatch occurs when we compare a scalar cmp to a vector cmp, for
// example.
@ -4540,7 +4540,7 @@ Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
// LHS ==> RHS by definition
if (LHS == RHS)
return !LHSIsFalse;
return LHSIsTrue;
// FIXME: Extending the code below to handle vectors.
if (OpTy->isVectorTy())
@ -4552,7 +4552,7 @@ Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
const ICmpInst *LHSCmp = dyn_cast<ICmpInst>(LHS);
const ICmpInst *RHSCmp = dyn_cast<ICmpInst>(RHS);
if (LHSCmp && RHSCmp)
return isImpliedCondICmps(LHSCmp, RHSCmp, DL, LHSIsFalse, Depth);
return isImpliedCondICmps(LHSCmp, RHSCmp, DL, LHSIsTrue, Depth);
// The LHS should be an 'or' or an 'and' instruction. We expect the RHS to be
// an icmp. FIXME: Add support for and/or on the RHS.
@ -4560,7 +4560,7 @@ Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
if (LHSBO && RHSCmp) {
if ((LHSBO->getOpcode() == Instruction::And ||
LHSBO->getOpcode() == Instruction::Or))
return isImpliedCondAndOr(LHSBO, RHSCmp, DL, LHSIsFalse, Depth);
return isImpliedCondAndOr(LHSBO, RHSCmp, DL, LHSIsTrue, Depth);
}
return None;
}

View File

@ -1531,9 +1531,9 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
if (PBI && PBI->isConditional() &&
PBI->getSuccessor(0) != PBI->getSuccessor(1) &&
(PBI->getSuccessor(0) == Parent || PBI->getSuccessor(1) == Parent)) {
bool CondIsFalse = PBI->getSuccessor(1) == Parent;
bool CondIsTrue = PBI->getSuccessor(0) == Parent;
Optional<bool> Implication = isImpliedCondition(
PBI->getCondition(), SI.getCondition(), DL, CondIsFalse);
PBI->getCondition(), SI.getCondition(), DL, CondIsTrue);
if (Implication) {
Value *V = *Implication ? TrueVal : FalseVal;
return replaceInstUsesWith(SI, V);

View File

@ -1036,9 +1036,9 @@ bool JumpThreadingPass::ProcessImpliedCondition(BasicBlock *BB) {
if (PBI->getSuccessor(0) != CurrentBB && PBI->getSuccessor(1) != CurrentBB)
return false;
bool FalseDest = PBI->getSuccessor(1) == CurrentBB;
bool CondIsTrue = PBI->getSuccessor(0) == CurrentBB;
Optional<bool> Implication =
isImpliedCondition(PBI->getCondition(), Cond, DL, FalseDest);
isImpliedCondition(PBI->getCondition(), Cond, DL, CondIsTrue);
if (Implication) {
BI->getSuccessor(*Implication ? 1 : 0)->removePredecessor(BB);
BranchInst::Create(BI->getSuccessor(*Implication ? 0 : 1), BI);
@ -2331,8 +2331,7 @@ bool JumpThreadingPass::ThreadGuard(BasicBlock *BB, IntrinsicInst *Guard,
TrueDestIsSafe = true;
else {
// False dest is safe if !BranchCond => GuardCond.
Impl =
isImpliedCondition(BranchCond, GuardCond, DL, /* InvertAPred */ true);
Impl = isImpliedCondition(BranchCond, GuardCond, DL, /* LHSIsTrue */ false);
if (Impl && *Impl)
FalseDestIsSafe = true;
}

View File

@ -5761,9 +5761,9 @@ bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
if (PBI && PBI->isConditional() &&
PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
assert(PBI->getSuccessor(0) == BB || PBI->getSuccessor(1) == BB);
bool CondIsFalse = PBI->getSuccessor(1) == BB;
bool CondIsTrue = PBI->getSuccessor(0) == BB;
Optional<bool> Implication = isImpliedCondition(
PBI->getCondition(), BI->getCondition(), DL, CondIsFalse);
PBI->getCondition(), BI->getCondition(), DL, CondIsTrue);
if (Implication) {
// Turn this into a branch on constant.
auto *OldCond = BI->getCondition();