@@ -61,19 +61,13 @@ findAffectedValues(CallBase *CI, TargetTransformInfo *TTI,
61
61
// Note: This code must be kept in-sync with the code in
62
62
// computeKnownBitsFromAssume in ValueTracking.
63
63
64
- auto AddAffected = [&Affected](Value *V, unsigned Idx =
65
- AssumptionCache::ExprResultIdx) {
66
- if (isa<Argument>(V) || isa<GlobalValue>(V)) {
64
+ auto InsertAffected = [&Affected](Value *V) {
65
+ Affected.push_back ({V, AssumptionCache::ExprResultIdx});
66
+ };
67
+
68
+ auto AddAffectedVal = [&Affected](Value *V, unsigned Idx) {
69
+ if (isa<Argument>(V) || isa<GlobalValue>(V) || isa<Instruction>(V)) {
67
70
Affected.push_back ({V, Idx});
68
- } else if (auto *I = dyn_cast<Instruction>(V)) {
69
- Affected.push_back ({I, Idx});
70
-
71
- // Peek through unary operators to find the source of the condition.
72
- Value *Op;
73
- if (match (I, m_PtrToInt (m_Value (Op)))) {
74
- if (isa<Instruction>(Op) || isa<Argument>(Op))
75
- Affected.push_back ({Op, Idx});
76
- }
77
71
}
78
72
};
79
73
@@ -82,64 +76,23 @@ findAffectedValues(CallBase *CI, TargetTransformInfo *TTI,
82
76
if (Bundle.getTagName () == " separate_storage" ) {
83
77
assert (Bundle.Inputs .size () == 2 &&
84
78
" separate_storage must have two args" );
85
- AddAffected (getUnderlyingObject (Bundle.Inputs [0 ]), Idx);
86
- AddAffected (getUnderlyingObject (Bundle.Inputs [1 ]), Idx);
79
+ AddAffectedVal (getUnderlyingObject (Bundle.Inputs [0 ]), Idx);
80
+ AddAffectedVal (getUnderlyingObject (Bundle.Inputs [1 ]), Idx);
87
81
} else if (Bundle.Inputs .size () > ABA_WasOn &&
88
82
Bundle.getTagName () != IgnoreBundleTag)
89
- AddAffected (Bundle.Inputs [ABA_WasOn], Idx);
83
+ AddAffectedVal (Bundle.Inputs [ABA_WasOn], Idx);
90
84
}
91
85
92
- Value *Cond = CI->getArgOperand (0 ), *A, *B;
93
- AddAffected (Cond);
94
- if (match (Cond, m_Not (m_Value (A))))
95
- AddAffected (A);
96
-
97
- CmpInst::Predicate Pred;
98
- if (match (Cond, m_Cmp (Pred, m_Value (A), m_Value (B)))) {
99
- AddAffected (A);
100
- AddAffected (B);
101
-
102
- if (Pred == ICmpInst::ICMP_EQ) {
103
- if (match (B, m_ConstantInt ())) {
104
- Value *X;
105
- // (X & C) or (X | C) or (X ^ C).
106
- // (X << C) or (X >>_s C) or (X >>_u C).
107
- if (match (A, m_BitwiseLogic (m_Value (X), m_ConstantInt ())) ||
108
- match (A, m_Shift (m_Value (X), m_ConstantInt ())))
109
- AddAffected (X);
110
- }
111
- } else if (Pred == ICmpInst::ICMP_NE) {
112
- Value *X;
113
- // Handle (X & pow2 != 0).
114
- if (match (A, m_And (m_Value (X), m_Power2 ())) && match (B, m_Zero ()))
115
- AddAffected (X);
116
- } else if (Pred == ICmpInst::ICMP_ULT) {
117
- Value *X;
118
- // Handle (A + C1) u< C2, which is the canonical form of A > C3 && A < C4,
119
- // and recognized by LVI at least.
120
- if (match (A, m_Add (m_Value (X), m_ConstantInt ())) &&
121
- match (B, m_ConstantInt ()))
122
- AddAffected (X);
123
- } else if (CmpInst::isFPPredicate (Pred)) {
124
- // fcmp fneg(x), y
125
- // fcmp fabs(x), y
126
- // fcmp fneg(fabs(x)), y
127
- if (match (A, m_FNeg (m_Value (A))))
128
- AddAffected (A);
129
- if (match (A, m_FAbs (m_Value (A))))
130
- AddAffected (A);
131
- }
132
- } else if (match (Cond, m_Intrinsic<Intrinsic::is_fpclass>(m_Value (A),
133
- m_Value (B)))) {
134
- AddAffected (A);
135
- }
86
+ Value *Cond = CI->getArgOperand (0 );
87
+ findValuesAffectedByCondition (Cond, /* IsAssume=*/ true , InsertAffected);
136
88
137
89
if (TTI) {
138
90
const Value *Ptr ;
139
91
unsigned AS;
140
92
std::tie (Ptr , AS) = TTI->getPredicatedAddrSpace (Cond);
141
93
if (Ptr )
142
- AddAffected (const_cast <Value *>(Ptr ->stripInBoundsOffsets ()));
94
+ AddAffectedVal (const_cast <Value *>(Ptr ->stripInBoundsOffsets ()),
95
+ AssumptionCache::ExprResultIdx);
143
96
}
144
97
}
145
98
0 commit comments