From 00d0315a7cd37e28988950c2cf415c01958858c6 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Fri, 19 Mar 2021 10:07:12 -0700 Subject: [PATCH] [SCEV] Factor out a lambda for strict condition splitting [NFC] --- llvm/lib/Analysis/ScalarEvolution.cpp | 42 +++++++++++++++------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 7dd05d0751f1..f12ebe3a8727 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -10028,13 +10028,23 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB, bool ProvedNonStrictComparison = false; bool ProvedNonEquality = false; - if (ProvingStrictComparison) { - ProvedNonStrictComparison = - isKnownViaNonRecursiveReasoning(NonStrictPredicate, LHS, RHS); - ProvedNonEquality = - isKnownViaNonRecursiveReasoning(ICmpInst::ICMP_NE, LHS, RHS); + auto SplitAndProve = + [&](std::function Fn) -> bool { + if (!ProvedNonStrictComparison) + ProvedNonStrictComparison = Fn(NonStrictPredicate); + if (!ProvedNonEquality) + ProvedNonEquality = Fn(ICmpInst::ICMP_NE); if (ProvedNonStrictComparison && ProvedNonEquality) return true; + return false; + }; + + if (ProvingStrictComparison) { + auto ProofFn = [&](ICmpInst::Predicate P) { + return isKnownViaNonRecursiveReasoning(P, LHS, RHS); + }; + if (SplitAndProve(ProofFn)) + return true; } // Try to prove (Pred, LHS, RHS) using isImpliedViaGuard. @@ -10042,13 +10052,10 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB, if (isImpliedViaGuard(Block, Pred, LHS, RHS)) return true; if (ProvingStrictComparison) { - if (!ProvedNonStrictComparison) - ProvedNonStrictComparison = - isImpliedViaGuard(Block, NonStrictPredicate, LHS, RHS); - if (!ProvedNonEquality) - ProvedNonEquality = - isImpliedViaGuard(Block, ICmpInst::ICMP_NE, LHS, RHS); - if (ProvedNonStrictComparison && ProvedNonEquality) + auto ProofFn = [&](ICmpInst::Predicate P) { + return isImpliedViaGuard(Block, P, LHS, RHS); + }; + if (SplitAndProve(ProofFn)) return true; } return false; @@ -10060,13 +10067,10 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB, if (isImpliedCond(Pred, LHS, RHS, Condition, Inverse, Context)) return true; if (ProvingStrictComparison) { - if (!ProvedNonStrictComparison) - ProvedNonStrictComparison = isImpliedCond(NonStrictPredicate, LHS, RHS, - Condition, Inverse, Context); - if (!ProvedNonEquality) - ProvedNonEquality = isImpliedCond(ICmpInst::ICMP_NE, LHS, RHS, - Condition, Inverse, Context); - if (ProvedNonStrictComparison && ProvedNonEquality) + auto ProofFn = [&](ICmpInst::Predicate P) { + return isImpliedCond(P, LHS, RHS, Condition, Inverse, Context); + }; + if (SplitAndProve(ProofFn)) return true; } return false;