|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | #include "llvm/Analysis/DomConditionCache.h"
|
10 |
| -#include "llvm/IR/PatternMatch.h" |
11 |
| - |
| 10 | +#include "llvm/IR/InstrTypes.h" |
| 11 | +#include "llvm/IR/Instruction.h" |
| 12 | +#include "llvm/IR/Instructions.h" |
12 | 13 | using namespace llvm;
|
13 |
| -using namespace llvm::PatternMatch; |
14 | 14 |
|
15 |
| -// TODO: This code is very similar to findAffectedValues() in |
16 |
| -// AssumptionCache, but currently specialized to just the patterns that |
17 |
| -// computeKnownBits() supports, and without the notion of result elem indices |
18 |
| -// that are AC specific. Deduplicate this code once we have a clearer picture |
19 |
| -// of how much they can be shared. |
| 15 | +// Implemented in ValueTracking.cpp |
| 16 | +void findValuesAffectedByCondition(Value *Cond, bool IsAssume, |
| 17 | + function_ref<void(Value *)> InsertAffected); |
| 18 | + |
20 | 19 | static void findAffectedValues(Value *Cond,
|
21 | 20 | SmallVectorImpl<Value *> &Affected) {
|
22 |
| - auto AddAffected = [&Affected](Value *V) { |
23 |
| - if (isa<Argument>(V) || isa<GlobalValue>(V)) { |
24 |
| - Affected.push_back(V); |
25 |
| - } else if (auto *I = dyn_cast<Instruction>(V)) { |
26 |
| - Affected.push_back(I); |
27 |
| - |
28 |
| - // Peek through unary operators to find the source of the condition. |
29 |
| - Value *Op; |
30 |
| - if (match(I, m_PtrToInt(m_Value(Op)))) { |
31 |
| - if (isa<Instruction>(Op) || isa<Argument>(Op)) |
32 |
| - Affected.push_back(Op); |
33 |
| - } |
34 |
| - } |
35 |
| - }; |
36 |
| - |
37 |
| - SmallVector<Value *, 8> Worklist; |
38 |
| - SmallPtrSet<Value *, 8> Visited; |
39 |
| - Worklist.push_back(Cond); |
40 |
| - while (!Worklist.empty()) { |
41 |
| - Value *V = Worklist.pop_back_val(); |
42 |
| - if (!Visited.insert(V).second) |
43 |
| - continue; |
44 |
| - |
45 |
| - CmpInst::Predicate Pred; |
46 |
| - Value *A, *B; |
47 |
| - if (match(V, m_LogicalOp(m_Value(A), m_Value(B)))) { |
48 |
| - Worklist.push_back(A); |
49 |
| - Worklist.push_back(B); |
50 |
| - } else if (match(V, m_ICmp(Pred, m_Value(A), m_Constant()))) { |
51 |
| - AddAffected(A); |
52 |
| - |
53 |
| - if (ICmpInst::isEquality(Pred)) { |
54 |
| - Value *X; |
55 |
| - // (X & C) or (X | C) or (X ^ C). |
56 |
| - // (X << C) or (X >>_s C) or (X >>_u C). |
57 |
| - if (match(A, m_BitwiseLogic(m_Value(X), m_ConstantInt())) || |
58 |
| - match(A, m_Shift(m_Value(X), m_ConstantInt()))) |
59 |
| - AddAffected(X); |
60 |
| - } else { |
61 |
| - Value *X; |
62 |
| - // Handle (A + C1) u< C2, which is the canonical form of |
63 |
| - // A > C3 && A < C4. |
64 |
| - if (match(A, m_Add(m_Value(X), m_ConstantInt()))) |
65 |
| - AddAffected(X); |
66 |
| - // Handle icmp slt/sgt (bitcast X to int), 0/-1, which is supported by |
67 |
| - // computeKnownFPClass(). |
68 |
| - if ((Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SGT) && |
69 |
| - match(A, m_ElementWiseBitCast(m_Value(X)))) |
70 |
| - Affected.push_back(X); |
71 |
| - } |
72 |
| - } else if (match(Cond, m_CombineOr(m_FCmp(Pred, m_Value(A), m_Constant()), |
73 |
| - m_Intrinsic<Intrinsic::is_fpclass>( |
74 |
| - m_Value(A), m_Constant())))) { |
75 |
| - // Handle patterns that computeKnownFPClass() support. |
76 |
| - AddAffected(A); |
77 |
| - } |
78 |
| - } |
| 21 | + auto InsertAffected = [&Affected](Value *V) { Affected.push_back(V); }; |
| 22 | + findValuesAffectedByCondition(Cond, /*IsAssume*/ false, InsertAffected); |
79 | 23 | }
|
80 | 24 |
|
81 | 25 | void DomConditionCache::registerBranch(BranchInst *BI) {
|
|
0 commit comments