@@ -186,47 +186,30 @@ KnownBits llvm::computeKnownBits(const Value *V, const APInt &DemandedElts,
186
186
SimplifyQuery (DL, DT, AC, safeCxtI (V, CxtI), UseInstrInfo));
187
187
}
188
188
189
- bool llvm::haveNoCommonBitsSet (const WithCache<const Value *> &LHSCache,
190
- const WithCache<const Value *> &RHSCache,
191
- const SimplifyQuery &SQ) {
192
- const Value *LHS = LHSCache.getValue ();
193
- const Value *RHS = RHSCache.getValue ();
194
-
195
- assert (LHS->getType () == RHS->getType () &&
196
- " LHS and RHS should have the same type" );
197
- assert (LHS->getType ()->isIntOrIntVectorTy () &&
198
- " LHS and RHS should be integers" );
189
+ static bool haveNoCommonBitsSetSpecialCases (const Value *LHS,
190
+ const Value *RHS) {
199
191
// Look for an inverted mask: (X & ~M) op (Y & M).
200
192
{
201
193
Value *M;
202
194
if (match (LHS, m_c_And (m_Not (m_Value (M)), m_Value ())) &&
203
195
match (RHS, m_c_And (m_Specific (M), m_Value ())))
204
196
return true ;
205
- if (match (RHS, m_c_And (m_Not (m_Value (M)), m_Value ())) &&
206
- match (LHS, m_c_And (m_Specific (M), m_Value ())))
207
- return true ;
208
197
}
209
198
210
199
// X op (Y & ~X)
211
- if (match (RHS, m_c_And (m_Not (m_Specific (LHS)), m_Value ())) ||
212
- match (LHS, m_c_And (m_Not (m_Specific (RHS)), m_Value ())))
200
+ if (match (RHS, m_c_And (m_Not (m_Specific (LHS)), m_Value ())))
213
201
return true ;
214
202
215
203
// X op ((X & Y) ^ Y) -- this is the canonical form of the previous pattern
216
204
// for constant Y.
217
205
Value *Y;
218
- if (match (RHS,
219
- m_c_Xor (m_c_And (m_Specific (LHS), m_Value (Y)), m_Deferred (Y))) ||
220
- match (LHS, m_c_Xor (m_c_And (m_Specific (RHS), m_Value (Y)), m_Deferred (Y))))
206
+ if (match (RHS, m_c_Xor (m_c_And (m_Specific (LHS), m_Value (Y)), m_Deferred (Y))))
221
207
return true ;
222
208
223
209
// Peek through extends to find a 'not' of the other side:
224
210
// (ext Y) op ext(~Y)
225
- // (ext ~Y) op ext(Y)
226
- if ((match (LHS, m_ZExtOrSExt (m_Value (Y))) &&
227
- match (RHS, m_ZExtOrSExt (m_Not (m_Specific (Y))))) ||
228
- (match (RHS, m_ZExtOrSExt (m_Value (Y))) &&
229
- match (LHS, m_ZExtOrSExt (m_Not (m_Specific (Y))))))
211
+ if (match (LHS, m_ZExtOrSExt (m_Value (Y))) &&
212
+ match (RHS, m_ZExtOrSExt (m_Not (m_Specific (Y)))))
230
213
return true ;
231
214
232
215
// Look for: (A & B) op ~(A | B)
@@ -235,11 +218,26 @@ bool llvm::haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
235
218
if (match (LHS, m_And (m_Value (A), m_Value (B))) &&
236
219
match (RHS, m_Not (m_c_Or (m_Specific (A), m_Specific (B)))))
237
220
return true ;
238
- if (match (RHS, m_And (m_Value (A), m_Value (B))) &&
239
- match (LHS, m_Not (m_c_Or (m_Specific (A), m_Specific (B)))))
240
- return true ;
241
221
}
242
222
223
+ return false ;
224
+ }
225
+
226
+ bool llvm::haveNoCommonBitsSet (const WithCache<const Value *> &LHSCache,
227
+ const WithCache<const Value *> &RHSCache,
228
+ const SimplifyQuery &SQ) {
229
+ const Value *LHS = LHSCache.getValue ();
230
+ const Value *RHS = RHSCache.getValue ();
231
+
232
+ assert (LHS->getType () == RHS->getType () &&
233
+ " LHS and RHS should have the same type" );
234
+ assert (LHS->getType ()->isIntOrIntVectorTy () &&
235
+ " LHS and RHS should be integers" );
236
+
237
+ if (haveNoCommonBitsSetSpecialCases (LHS, RHS) ||
238
+ haveNoCommonBitsSetSpecialCases (RHS, LHS))
239
+ return true ;
240
+
243
241
return KnownBits::haveNoCommonBitsSet (LHSCache.getKnownBits (SQ),
244
242
RHSCache.getKnownBits (SQ));
245
243
}
0 commit comments