@@ -11863,15 +11863,13 @@ bool ScalarEvolution::isImpliedCondBalancedTypes(
11863
11863
}
11864
11864
11865
11865
// Check whether the found predicate is the same as the desired predicate.
11866
- // FIXME: use CmpPredicate::getMatching here.
11867
- if (FoundPred == static_cast<CmpInst::Predicate>(Pred))
11868
- return isImpliedCondOperands(Pred, LHS, RHS, FoundLHS, FoundRHS, CtxI);
11866
+ if (auto P = CmpPredicate::getMatching(FoundPred, Pred))
11867
+ return isImpliedCondOperands(*P, LHS, RHS, FoundLHS, FoundRHS, CtxI);
11869
11868
11870
11869
// Check whether swapping the found predicate makes it the same as the
11871
11870
// desired predicate.
11872
- // FIXME: use CmpPredicate::getMatching here.
11873
- if (ICmpInst::getSwappedCmpPredicate(FoundPred) ==
11874
- static_cast<CmpInst::Predicate>(Pred)) {
11871
+ if (auto P = CmpPredicate::getMatching(
11872
+ ICmpInst::getSwappedCmpPredicate(FoundPred), Pred)) {
11875
11873
// We can write the implication
11876
11874
// 0. LHS Pred RHS <- FoundLHS SwapPred FoundRHS
11877
11875
// using one of the following ways:
@@ -11882,22 +11880,23 @@ bool ScalarEvolution::isImpliedCondBalancedTypes(
11882
11880
// Forms 1. and 2. require swapping the operands of one condition. Don't
11883
11881
// do this if it would break canonical constant/addrec ordering.
11884
11882
if (!isa<SCEVConstant>(RHS) && !isa<SCEVAddRecExpr>(LHS))
11885
- return isImpliedCondOperands(FoundPred , RHS, LHS, FoundLHS, FoundRHS ,
11886
- CtxI);
11883
+ return isImpliedCondOperands(ICmpInst::getSwappedCmpPredicate(*P) , RHS,
11884
+ LHS, FoundLHS, FoundRHS, CtxI);
11887
11885
if (!isa<SCEVConstant>(FoundRHS) && !isa<SCEVAddRecExpr>(FoundLHS))
11888
- return isImpliedCondOperands(Pred , LHS, RHS, FoundRHS, FoundLHS, CtxI);
11886
+ return isImpliedCondOperands(*P , LHS, RHS, FoundRHS, FoundLHS, CtxI);
11889
11887
11890
11888
// There's no clear preference between forms 3. and 4., try both. Avoid
11891
11889
// forming getNotSCEV of pointer values as the resulting subtract is
11892
11890
// not legal.
11893
11891
if (!LHS->getType()->isPointerTy() && !RHS->getType()->isPointerTy() &&
11894
- isImpliedCondOperands(FoundPred, getNotSCEV(LHS), getNotSCEV(RHS),
11895
- FoundLHS, FoundRHS, CtxI))
11892
+ isImpliedCondOperands(ICmpInst::getSwappedCmpPredicate(*P),
11893
+ getNotSCEV(LHS), getNotSCEV(RHS), FoundLHS,
11894
+ FoundRHS, CtxI))
11896
11895
return true;
11897
11896
11898
11897
if (!FoundLHS->getType()->isPointerTy() &&
11899
11898
!FoundRHS->getType()->isPointerTy() &&
11900
- isImpliedCondOperands(Pred , LHS, RHS, getNotSCEV(FoundLHS),
11899
+ isImpliedCondOperands(*P , LHS, RHS, getNotSCEV(FoundLHS),
11901
11900
getNotSCEV(FoundRHS), CtxI))
11902
11901
return true;
11903
11902
@@ -12567,14 +12566,16 @@ bool ScalarEvolution::isImpliedViaOperations(CmpPredicate Pred, const SCEV *LHS,
12567
12566
return false;
12568
12567
12569
12568
// We only want to work with GT comparison so far.
12570
- if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_SLT ) {
12569
+ if (ICmpInst::isLT( Pred) ) {
12571
12570
Pred = ICmpInst::getSwappedCmpPredicate(Pred);
12572
12571
std::swap(LHS, RHS);
12573
12572
std::swap(FoundLHS, FoundRHS);
12574
12573
}
12575
12574
12575
+ CmpInst::Predicate P = Pred.getPreferredSignedPredicate();
12576
+
12576
12577
// For unsigned, try to reduce it to corresponding signed comparison.
12577
- if (Pred == ICmpInst::ICMP_UGT)
12578
+ if (P == ICmpInst::ICMP_UGT)
12578
12579
// We can replace unsigned predicate with its signed counterpart if all
12579
12580
// involved values are non-negative.
12580
12581
// TODO: We could have better support for unsigned.
@@ -12587,10 +12588,10 @@ bool ScalarEvolution::isImpliedViaOperations(CmpPredicate Pred, const SCEV *LHS,
12587
12588
FoundRHS) &&
12588
12589
isImpliedCondOperands(ICmpInst::ICMP_SGT, RHS, MinusOne, FoundLHS,
12589
12590
FoundRHS))
12590
- Pred = ICmpInst::ICMP_SGT;
12591
+ P = ICmpInst::ICMP_SGT;
12591
12592
}
12592
12593
12593
- if (Pred != ICmpInst::ICMP_SGT)
12594
+ if (P != ICmpInst::ICMP_SGT)
12594
12595
return false;
12595
12596
12596
12597
auto GetOpFromSExt = [&](const SCEV *S) {
0 commit comments