@@ -42,6 +42,12 @@ static cl::opt<bool>
42
42
cl::desc (" Enable verification of assumption cache" ),
43
43
cl::init(false ));
44
44
45
+ // Implemented in ValueTracking.cpp
46
+ void addValueAffectedByCondition (Value *V,
47
+ function_ref<void (Value *)> InsertAffected);
48
+ void findValuesAffectedByCondition (Value *Cond, bool IsAssume,
49
+ function_ref<void (Value *)> InsertAffected);
50
+
45
51
SmallVector<AssumptionCache::ResultElem, 1 > &
46
52
AssumptionCache::getOrInsertAffectedValues (Value *V) {
47
53
// Try using find_as first to avoid creating extra value handles just for the
@@ -61,85 +67,37 @@ findAffectedValues(CallBase *CI, TargetTransformInfo *TTI,
61
67
// Note: This code must be kept in-sync with the code in
62
68
// computeKnownBitsFromAssume in ValueTracking.
63
69
64
- auto AddAffected = [&Affected](Value *V, unsigned Idx =
65
- AssumptionCache::ExprResultIdx) {
66
- if (isa<Argument>(V) || isa<GlobalValue>(V)) {
67
- 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
- }
70
+ auto InsertAffected = [&Affected](Value *V) {
71
+ Affected.push_back ({V, AssumptionCache::ExprResultIdx});
78
72
};
79
73
80
74
for (unsigned Idx = 0 ; Idx != CI->getNumOperandBundles (); Idx++) {
75
+ auto AddAffectedBundleVal = [&Affected](Value *V, unsigned Idx) {
76
+ if (isa<Argument>(V) || isa<GlobalValue>(V) || isa<Instruction>(V)) {
77
+ Affected.push_back ({V, Idx});
78
+ }
79
+ };
81
80
OperandBundleUse Bundle = CI->getOperandBundleAt (Idx);
82
81
if (Bundle.getTagName () == " separate_storage" ) {
83
82
assert (Bundle.Inputs .size () == 2 &&
84
83
" separate_storage must have two args" );
85
- AddAffected (getUnderlyingObject (Bundle.Inputs [0 ]), Idx);
86
- AddAffected (getUnderlyingObject (Bundle.Inputs [1 ]), Idx);
84
+ AddAffectedBundleVal (getUnderlyingObject (Bundle.Inputs [0 ]), Idx);
85
+ AddAffectedBundleVal (getUnderlyingObject (Bundle.Inputs [1 ]), Idx);
87
86
} else if (Bundle.Inputs .size () > ABA_WasOn &&
88
87
Bundle.getTagName () != IgnoreBundleTag)
89
- AddAffected (Bundle.Inputs [ABA_WasOn], Idx);
88
+ AddAffectedBundleVal (Bundle.Inputs [ABA_WasOn], Idx);
90
89
}
91
90
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
- }
91
+ Value *Cond = CI->getArgOperand (0 );
92
+ findValuesAffectedByCondition (Cond, /* IsAssume*/ true , InsertAffected);
136
93
137
94
if (TTI) {
138
95
const Value *Ptr ;
139
96
unsigned AS;
140
97
std::tie (Ptr , AS) = TTI->getPredicatedAddrSpace (Cond);
141
98
if (Ptr )
142
- AddAffected (const_cast <Value *>(Ptr ->stripInBoundsOffsets ()));
99
+ addValueAffectedByCondition (
100
+ const_cast <Value *>(Ptr ->stripInBoundsOffsets ()), InsertAffected);
143
101
}
144
102
}
145
103
0 commit comments