@@ -9388,17 +9388,32 @@ isImpliedCondMatchingOperands(CmpInst::Predicate LPred,
9388
9388
// / Return true if "icmp LPred X, LCR" implies "icmp RPred X, RCR" is true.
9389
9389
// / Return false if "icmp LPred X, LCR" implies "icmp RPred X, RCR" is false.
9390
9390
// / 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 ;
9398
9399
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
+ }
9402
9417
return std::nullopt;
9403
9418
}
9404
9419
0 commit comments