@@ -2999,21 +2999,32 @@ static Value *simplifyICmpWithConstant(CmpPredicate Pred, Value *LHS,
2999
2999
return ConstantInt::getBool (ITy, !TrueIfSigned);
3000
3000
}
3001
3001
3002
- // Rule out tautological comparisons (eg., ult 0 or uge 0).
3003
- ConstantRange RHS_CR = ConstantRange::makeExactICmpRegion (Pred, *C);
3004
- if (RHS_CR.isEmptySet ())
3005
- return ConstantInt::getFalse (ITy);
3006
- if (RHS_CR.isFullSet ())
3007
- return ConstantInt::getTrue (ITy);
3008
-
3009
- ConstantRange LHS_CR =
3002
+ ConstantRange LCR =
3010
3003
computeConstantRange (LHS, CmpInst::isSigned (Pred), IIQ.UseInstrInfo );
3011
- if (!LHS_CR. isFullSet ()) {
3012
- if (RHS_CR. contains (LHS_CR))
3013
- return ConstantInt::getTrue (ITy);
3014
- if (RHS_CR. inverse (). contains (LHS_CR ))
3004
+
3005
+ auto CheckCR = [&]( const ConstantRange &CR) -> Constant * {
3006
+ // Rule out tautological comparisons (eg., ult 0 or uge 0).
3007
+ if (CR. isEmptySet ( ))
3015
3008
return ConstantInt::getFalse (ITy);
3016
- }
3009
+ if (CR.isFullSet ())
3010
+ return ConstantInt::getTrue (ITy);
3011
+
3012
+ if (!LCR.isFullSet ()) {
3013
+ if (CR.contains (LCR))
3014
+ return ConstantInt::getTrue (ITy);
3015
+ if (CR.inverse ().contains (LCR))
3016
+ return ConstantInt::getFalse (ITy);
3017
+ }
3018
+ return nullptr ;
3019
+ };
3020
+
3021
+ // Check unsigned and signed versions of relational predicates with samesign.
3022
+ if (auto *K = CheckCR (ConstantRange::makeExactICmpRegion (Pred, *C)))
3023
+ return K;
3024
+ if (Pred.hasSameSign () && ICmpInst::isRelational (Pred))
3025
+ if (auto *K = CheckCR (ConstantRange::makeExactICmpRegion (
3026
+ ICmpInst::getSignedPredicate (Pred), *C)))
3027
+ return K;
3017
3028
3018
3029
// (mul nuw/nsw X, MulC) != C --> true (if C is not a multiple of MulC)
3019
3030
// (mul nuw/nsw X, MulC) == C --> false (if C is not a multiple of MulC)
0 commit comments