@@ -3836,6 +3836,50 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2,
38363836 match (V2, m_PtrToIntSameSize (Q.DL , m_Value (B))))
38373837 return isKnownNonEqual (A, B, DemandedElts, Depth + 1 , Q);
38383838
3839+ if (!Q.CxtI )
3840+ return false ;
3841+
3842+ // Try to infer NonEqual based on information from dominating conditions.
3843+ if (Q.DC && Q.DT ) {
3844+ for (BranchInst *BI : Q.DC ->conditionsFor (V1)) {
3845+ Value *Cond = BI->getCondition ();
3846+ BasicBlockEdge Edge0 (BI->getParent (), BI->getSuccessor (0 ));
3847+ if (isImpliedCondition (Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3848+ /* LHSIsTrue=*/ true , Depth)
3849+ .value_or (false ) &&
3850+ Q.DT ->dominates (Edge0, Q.CxtI ->getParent ()))
3851+ return true ;
3852+
3853+ BasicBlockEdge Edge1 (BI->getParent (), BI->getSuccessor (1 ));
3854+ if (isImpliedCondition (Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3855+ /* LHSIsTrue=*/ false , Depth)
3856+ .value_or (false ) &&
3857+ Q.DT ->dominates (Edge1, Q.CxtI ->getParent ()))
3858+ return true ;
3859+ }
3860+ }
3861+
3862+ if (!Q.AC )
3863+ return false ;
3864+
3865+ // Try to infer NonEqual based on information from assumptions.
3866+ for (auto &AssumeVH : Q.AC ->assumptionsFor (V1)) {
3867+ if (!AssumeVH)
3868+ continue ;
3869+ CallInst *I = cast<CallInst>(AssumeVH);
3870+
3871+ assert (I->getFunction () == Q.CxtI ->getFunction () &&
3872+ " Got assumption for the wrong function!" );
3873+ assert (I->getIntrinsicID () == Intrinsic::assume &&
3874+ " must be an assume intrinsic" );
3875+
3876+ if (isImpliedCondition (I->getArgOperand (0 ), ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3877+ /* LHSIsTrue=*/ true , Depth)
3878+ .value_or (false ) &&
3879+ isValidAssumeForContext (I, Q.CxtI , Q.DT ))
3880+ return true ;
3881+ }
3882+
38393883 return false ;
38403884}
38413885
@@ -10206,10 +10250,10 @@ void llvm::findValuesAffectedByCondition(
1020610250 Worklist.push_back (B);
1020710251 }
1020810252 } else if (match (V, m_ICmp (Pred, m_Value (A), m_Value (B)))) {
10209- AddCmpOperands (A, B);
10210-
1021110253 bool HasRHSC = match (B, m_ConstantInt ());
1021210254 if (ICmpInst::isEquality (Pred)) {
10255+ AddAffected (A);
10256+ AddAffected (B);
1021310257 if (HasRHSC) {
1021410258 Value *Y;
1021510259 // (X & C) or (X | C).
@@ -10223,6 +10267,7 @@ void llvm::findValuesAffectedByCondition(
1022310267 }
1022410268 }
1022510269 } else {
10270+ AddCmpOperands (A, B);
1022610271 if (HasRHSC) {
1022710272 // Handle (A + C1) u< C2, which is the canonical form of
1022810273 // A > C3 && A < C4.
0 commit comments