@@ -9388,17 +9388,32 @@ isImpliedCondMatchingOperands(CmpInst::Predicate LPred,
93889388// / Return true if "icmp LPred X, LCR" implies "icmp RPred X, RCR" is true.
93899389// / Return false if "icmp LPred X, LCR" implies "icmp RPred X, RCR" is false.
93909390// / Otherwise, return std::nullopt if we can't infer anything.
9391- static std::optional<bool > isImpliedCondCommonOperandWithCR (
9392- CmpInst::Predicate LPred, const ConstantRange &LCR,
9393- CmpInst::Predicate RPred, const ConstantRange &RCR) {
9394- ConstantRange DomCR = ConstantRange::makeAllowedICmpRegion (LPred, LCR);
9395- // If all true values for lhs and true for rhs, lhs implies rhs
9396- if (DomCR.icmp (RPred, RCR))
9397- return true ;
9391+ static std::optional<bool >
9392+ isImpliedCondCommonOperandWithCR (CmpPredicate LPred, const ConstantRange &LCR,
9393+ CmpPredicate RPred, const ConstantRange &RCR) {
9394+ auto CRImpliesPred = [&](ConstantRange CR,
9395+ CmpInst::Predicate Pred) -> std::optional<bool > {
9396+ // If all true values for lhs and true for rhs, lhs implies rhs
9397+ if (CR.icmp (Pred, RCR))
9398+ return true ;
93989399
9399- // If there is no overlap, lhs implies not rhs
9400- if (DomCR.icmp (CmpInst::getInversePredicate (RPred), RCR))
9401- return false ;
9400+ // If there is no overlap, lhs implies not rhs
9401+ if (CR.icmp (CmpInst::getInversePredicate (Pred), RCR))
9402+ return false ;
9403+
9404+ return std::nullopt ;
9405+ };
9406+ if (auto Res = CRImpliesPred (ConstantRange::makeAllowedICmpRegion (LPred, LCR),
9407+ RPred))
9408+ return Res;
9409+ if (LPred.hasSameSign () ^ RPred.hasSameSign ()) {
9410+ LPred = LPred.hasSameSign () ? ICmpInst::getFlippedSignednessPredicate (LPred)
9411+ : static_cast <CmpInst::Predicate>(LPred);
9412+ RPred = RPred.hasSameSign () ? ICmpInst::getFlippedSignednessPredicate (RPred)
9413+ : static_cast <CmpInst::Predicate>(RPred);
9414+ return CRImpliesPred (ConstantRange::makeAllowedICmpRegion (LPred, LCR),
9415+ RPred);
9416+ }
94029417 return std::nullopt ;
94039418}
94049419
0 commit comments