@@ -3836,6 +3836,50 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2,
3836
3836
match (V2, m_PtrToIntSameSize (Q.DL , m_Value (B))))
3837
3837
return isKnownNonEqual (A, B, DemandedElts, Depth + 1 , Q);
3838
3838
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
+
3839
3883
return false ;
3840
3884
}
3841
3885
@@ -10206,10 +10250,10 @@ void llvm::findValuesAffectedByCondition(
10206
10250
Worklist.push_back (B);
10207
10251
}
10208
10252
} else if (match (V, m_ICmp (Pred, m_Value (A), m_Value (B)))) {
10209
- AddCmpOperands (A, B);
10210
-
10211
10253
bool HasRHSC = match (B, m_ConstantInt ());
10212
10254
if (ICmpInst::isEquality (Pred)) {
10255
+ AddAffected (A);
10256
+ AddAffected (B);
10213
10257
if (HasRHSC) {
10214
10258
Value *Y;
10215
10259
// (X & C) or (X | C).
@@ -10223,6 +10267,7 @@ void llvm::findValuesAffectedByCondition(
10223
10267
}
10224
10268
}
10225
10269
} else {
10270
+ AddCmpOperands (A, B);
10226
10271
if (HasRHSC) {
10227
10272
// Handle (A + C1) u< C2, which is the canonical form of
10228
10273
// A > C3 && A < C4.
0 commit comments