@@ -3857,6 +3857,50 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2,
3857
3857
match (V2, m_PtrToIntSameSize (Q.DL , m_Value (B))))
3858
3858
return isKnownNonEqual (A, B, DemandedElts, Depth + 1 , Q);
3859
3859
3860
+ if (!Q.CxtI )
3861
+ return false ;
3862
+
3863
+ // Try to infer NonEqual based on information from dominating conditions.
3864
+ if (Q.DC && Q.DT ) {
3865
+ for (BranchInst *BI : Q.DC ->conditionsFor (V1)) {
3866
+ Value *Cond = BI->getCondition ();
3867
+ BasicBlockEdge Edge0 (BI->getParent (), BI->getSuccessor (0 ));
3868
+ if (isImpliedCondition (Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3869
+ /* LHSIsTrue=*/ true , Depth)
3870
+ .value_or (false ) &&
3871
+ Q.DT ->dominates (Edge0, Q.CxtI ->getParent ()))
3872
+ return true ;
3873
+
3874
+ BasicBlockEdge Edge1 (BI->getParent (), BI->getSuccessor (1 ));
3875
+ if (isImpliedCondition (Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3876
+ /* LHSIsTrue=*/ false , Depth)
3877
+ .value_or (false ) &&
3878
+ Q.DT ->dominates (Edge1, Q.CxtI ->getParent ()))
3879
+ return true ;
3880
+ }
3881
+ }
3882
+
3883
+ if (!Q.AC )
3884
+ return false ;
3885
+
3886
+ // Try to infer NonEqual based on information from assumptions.
3887
+ for (auto &AssumeVH : Q.AC ->assumptionsFor (V1)) {
3888
+ if (!AssumeVH)
3889
+ continue ;
3890
+ CallInst *I = cast<CallInst>(AssumeVH);
3891
+
3892
+ assert (I->getFunction () == Q.CxtI ->getFunction () &&
3893
+ " Got assumption for the wrong function!" );
3894
+ assert (I->getIntrinsicID () == Intrinsic::assume &&
3895
+ " must be an assume intrinsic" );
3896
+
3897
+ if (isImpliedCondition (I->getArgOperand (0 ), ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3898
+ /* LHSIsTrue=*/ true , Depth)
3899
+ .value_or (false ) &&
3900
+ isValidAssumeForContext (I, Q.CxtI , Q.DT ))
3901
+ return true ;
3902
+ }
3903
+
3860
3904
return false ;
3861
3905
}
3862
3906
@@ -10231,10 +10275,10 @@ void llvm::findValuesAffectedByCondition(
10231
10275
Worklist.push_back (B);
10232
10276
}
10233
10277
} else if (match (V, m_ICmp (Pred, m_Value (A), m_Value (B)))) {
10234
- AddCmpOperands (A, B);
10235
-
10236
10278
bool HasRHSC = match (B, m_ConstantInt ());
10237
10279
if (ICmpInst::isEquality (Pred)) {
10280
+ AddAffected (A);
10281
+ AddAffected (B);
10238
10282
if (HasRHSC) {
10239
10283
Value *Y;
10240
10284
// (X & C) or (X | C).
@@ -10248,6 +10292,7 @@ void llvm::findValuesAffectedByCondition(
10248
10292
}
10249
10293
}
10250
10294
} else {
10295
+ AddCmpOperands (A, B);
10251
10296
if (HasRHSC) {
10252
10297
// Handle (A + C1) u< C2, which is the canonical form of
10253
10298
// A > C3 && A < C4.
0 commit comments