@@ -3748,6 +3748,50 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2,
3748
3748
match (V2, m_PtrToIntSameSize (Q.DL , m_Value (B))))
3749
3749
return isKnownNonEqual (A, B, DemandedElts, Depth + 1 , Q);
3750
3750
3751
+ if (!Q.CxtI )
3752
+ return false ;
3753
+
3754
+ // Try to infer NonEqual based on information from dominating conditions.
3755
+ if (Q.DC && Q.DT ) {
3756
+ for (BranchInst *BI : Q.DC ->conditionsFor (V1)) {
3757
+ Value *Cond = BI->getCondition ();
3758
+ BasicBlockEdge Edge0 (BI->getParent (), BI->getSuccessor (0 ));
3759
+ if (isImpliedCondition (Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3760
+ /* LHSIsTrue=*/ true , Depth)
3761
+ .value_or (false ) &&
3762
+ Q.DT ->dominates (Edge0, Q.CxtI ->getParent ()))
3763
+ return true ;
3764
+
3765
+ BasicBlockEdge Edge1 (BI->getParent (), BI->getSuccessor (1 ));
3766
+ if (isImpliedCondition (Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3767
+ /* LHSIsTrue=*/ false , Depth)
3768
+ .value_or (false ) &&
3769
+ Q.DT ->dominates (Edge1, Q.CxtI ->getParent ()))
3770
+ return true ;
3771
+ }
3772
+ }
3773
+
3774
+ if (!Q.AC )
3775
+ return false ;
3776
+
3777
+ // Try to infer NonEqual based on information from assumptions.
3778
+ for (auto &AssumeVH : Q.AC ->assumptionsFor (V1)) {
3779
+ if (!AssumeVH)
3780
+ continue ;
3781
+ CallInst *I = cast<CallInst>(AssumeVH);
3782
+
3783
+ assert (I->getFunction () == Q.CxtI ->getFunction () &&
3784
+ " Got assumption for the wrong function!" );
3785
+ assert (I->getIntrinsicID () == Intrinsic::assume &&
3786
+ " must be an assume intrinsic" );
3787
+
3788
+ if (isImpliedCondition (I->getArgOperand (0 ), ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3789
+ /* LHSIsTrue=*/ true , Depth)
3790
+ .value_or (false ) &&
3791
+ isValidAssumeForContext (I, Q.CxtI , Q.DT ))
3792
+ return true ;
3793
+ }
3794
+
3751
3795
return false ;
3752
3796
}
3753
3797
@@ -10037,10 +10081,10 @@ void llvm::findValuesAffectedByCondition(
10037
10081
Worklist.push_back (B);
10038
10082
}
10039
10083
} else if (match (V, m_ICmp (Pred, m_Value (A), m_Value (B)))) {
10040
- AddCmpOperands (A, B);
10041
-
10042
10084
bool HasRHSC = match (B, m_ConstantInt ());
10043
10085
if (ICmpInst::isEquality (Pred)) {
10086
+ AddAffected (A);
10087
+ AddAffected (B);
10044
10088
if (HasRHSC) {
10045
10089
Value *Y;
10046
10090
// (X & C) or (X | C) or (X ^ C).
@@ -10055,6 +10099,7 @@ void llvm::findValuesAffectedByCondition(
10055
10099
}
10056
10100
}
10057
10101
} else {
10102
+ AddCmpOperands (A, B);
10058
10103
if (HasRHSC) {
10059
10104
// Handle (A + C1) u< C2, which is the canonical form of
10060
10105
// A > C3 && A < C4.
0 commit comments