@@ -3804,6 +3804,63 @@ static bool isNonEqualPointersWithRecursiveGEP(const Value *A, const Value *B,
3804
3804
(StartOffset.sle (OffsetB) && StepOffset.isNegative ()));
3805
3805
}
3806
3806
3807
+ static bool isKnownNonEqualFromContext (const Value *V1, const Value *V2,
3808
+ unsigned Depth, const SimplifyQuery &Q) {
3809
+ if (!Q.CxtI )
3810
+ return false ;
3811
+
3812
+ // Try to infer NonEqual based on information from dominating conditions.
3813
+ if (Q.DC && Q.DT ) {
3814
+ auto IsKnownNonEqualFromDominatingCondition = [&](const Value *V) {
3815
+ for (BranchInst *BI : Q.DC ->conditionsFor (V)) {
3816
+ Value *Cond = BI->getCondition ();
3817
+ BasicBlockEdge Edge0 (BI->getParent (), BI->getSuccessor (0 ));
3818
+ if (Q.DT ->dominates (Edge0, Q.CxtI ->getParent ()) &&
3819
+ isImpliedCondition (Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3820
+ /* LHSIsTrue=*/ true , Depth)
3821
+ .value_or (false ))
3822
+ return true ;
3823
+
3824
+ BasicBlockEdge Edge1 (BI->getParent (), BI->getSuccessor (1 ));
3825
+ if (Q.DT ->dominates (Edge1, Q.CxtI ->getParent ()) &&
3826
+ isImpliedCondition (Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3827
+ /* LHSIsTrue=*/ false , Depth)
3828
+ .value_or (false ))
3829
+ return true ;
3830
+ }
3831
+
3832
+ return false ;
3833
+ };
3834
+
3835
+ if (IsKnownNonEqualFromDominatingCondition (V1) ||
3836
+ IsKnownNonEqualFromDominatingCondition (V2))
3837
+ return true ;
3838
+ }
3839
+
3840
+ if (!Q.AC )
3841
+ return false ;
3842
+
3843
+ // Try to infer NonEqual based on information from assumptions.
3844
+ for (auto &AssumeVH : Q.AC ->assumptionsFor (V1)) {
3845
+ if (!AssumeVH)
3846
+ continue ;
3847
+ CallInst *I = cast<CallInst>(AssumeVH);
3848
+
3849
+ assert (I->getFunction () == Q.CxtI ->getFunction () &&
3850
+ " Got assumption for the wrong function!" );
3851
+ assert (I->getIntrinsicID () == Intrinsic::assume &&
3852
+ " must be an assume intrinsic" );
3853
+
3854
+ if (isImpliedCondition (I->getArgOperand (0 ), ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3855
+ /* LHSIsTrue=*/ true , Depth)
3856
+ .value_or (false ) &&
3857
+ isValidAssumeForContext (I, Q.CxtI , Q.DT ))
3858
+ return true ;
3859
+ }
3860
+
3861
+ return false ;
3862
+ }
3863
+
3807
3864
// / Return true if it is known that V1 != V2.
3808
3865
static bool isKnownNonEqual (const Value *V1, const Value *V2,
3809
3866
const APInt &DemandedElts, unsigned Depth,
@@ -3875,49 +3932,8 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2,
3875
3932
match (V2, m_PtrToIntSameSize (Q.DL , m_Value (B))))
3876
3933
return isKnownNonEqual (A, B, DemandedElts, Depth + 1 , Q);
3877
3934
3878
- if (!Q.CxtI )
3879
- return false ;
3880
-
3881
- // Try to infer NonEqual based on information from dominating conditions.
3882
- if (Q.DC && Q.DT ) {
3883
- for (BranchInst *BI : Q.DC ->conditionsFor (V1)) {
3884
- Value *Cond = BI->getCondition ();
3885
- BasicBlockEdge Edge0 (BI->getParent (), BI->getSuccessor (0 ));
3886
- if (Q.DT ->dominates (Edge0, Q.CxtI ->getParent ()) &&
3887
- isImpliedCondition (Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3888
- /* LHSIsTrue=*/ true , Depth)
3889
- .value_or (false ))
3890
- return true ;
3891
-
3892
- BasicBlockEdge Edge1 (BI->getParent (), BI->getSuccessor (1 ));
3893
- if (Q.DT ->dominates (Edge1, Q.CxtI ->getParent ()) &&
3894
- isImpliedCondition (Cond, ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3895
- /* LHSIsTrue=*/ false , Depth)
3896
- .value_or (false ))
3897
- return true ;
3898
- }
3899
- }
3900
-
3901
- if (!Q.AC )
3902
- return false ;
3903
-
3904
- // Try to infer NonEqual based on information from assumptions.
3905
- for (auto &AssumeVH : Q.AC ->assumptionsFor (V1)) {
3906
- if (!AssumeVH)
3907
- continue ;
3908
- CallInst *I = cast<CallInst>(AssumeVH);
3909
-
3910
- assert (I->getFunction () == Q.CxtI ->getFunction () &&
3911
- " Got assumption for the wrong function!" );
3912
- assert (I->getIntrinsicID () == Intrinsic::assume &&
3913
- " must be an assume intrinsic" );
3914
-
3915
- if (isImpliedCondition (I->getArgOperand (0 ), ICmpInst::ICMP_NE, V1, V2, Q.DL ,
3916
- /* LHSIsTrue=*/ true , Depth)
3917
- .value_or (false ) &&
3918
- isValidAssumeForContext (I, Q.CxtI , Q.DT ))
3919
- return true ;
3920
- }
3935
+ if (isKnownNonEqualFromContext (V1, V2, Depth, Q))
3936
+ return true ;
3921
3937
3922
3938
return false ;
3923
3939
}
@@ -10348,7 +10364,8 @@ void llvm::findValuesAffectedByCondition(
10348
10364
bool HasRHSC = match (B, m_ConstantInt ());
10349
10365
if (ICmpInst::isEquality (Pred)) {
10350
10366
AddAffected (A);
10351
- AddAffected (B);
10367
+ if (IsAssume)
10368
+ AddAffected (B);
10352
10369
if (HasRHSC) {
10353
10370
Value *Y;
10354
10371
// (X & C) or (X | C).
0 commit comments