llvm.org GIT mirror llvm / 8de3a54
Revert @llvm.assume with operator bundles (r289755-r289757) This creates non-linear behavior in the inliner (see more details in r289755's commit thread). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290086 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Jasper 2 years ago
108 changed file(s) with 1192 addition(s) and 868 deletion(s). Raw diff Collapse all Expand all
17511751 site, these bundles may contain any values that are needed by the
17521752 generated code. For more details, see :ref:`GC Transitions
17531753 `.
1754
1755 Affected Operand Bundles
1756 ^^^^^^^^^^^^^^^^^^^^^^^^
1757
1758 Affected operand bundles are characterized by the ``"affected"`` operand bundle
1759 tag. These operand bundles indicate that a call, specifically a call to an
1760 intrinsic like ``llvm.assume``, implies some additional knowledge about the
1761 values within the bundle. This enables the optimizer to efficiently find these
1762 relationships. The optimizer will add these automatically.
17631754
17641755 .. _moduleasm:
17651756
1515
1616 #include "llvm/ADT/SmallPtrSet.h"
1717 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/Analysis/AssumptionCache.h"
1819 #include "llvm/Analysis/TargetLibraryInfo.h"
1920 #include "llvm/IR/Function.h"
2021 #include "llvm/IR/GetElementPtrTypeIterator.h"
2526 #include "llvm/Support/ErrorHandling.h"
2627
2728 namespace llvm {
29 class AssumptionCache;
2830 class DominatorTree;
2931 class LoopInfo;
3032
3840
3941 const DataLayout &DL;
4042 const TargetLibraryInfo &TLI;
43 AssumptionCache ∾
4144 DominatorTree *DT;
4245 LoopInfo *LI;
4346
4447 public:
4548 BasicAAResult(const DataLayout &DL, const TargetLibraryInfo &TLI,
46 DominatorTree *DT = nullptr,
49 AssumptionCache &AC, DominatorTree *DT = nullptr,
4750 LoopInfo *LI = nullptr)
48 : AAResultBase(), DL(DL), TLI(TLI), DT(DT), LI(LI) {}
51 : AAResultBase(), DL(DL), TLI(TLI), AC(AC), DT(DT), LI(LI) {}
4952
5053 BasicAAResult(const BasicAAResult &Arg)
51 : AAResultBase(Arg), DL(Arg.DL), TLI(Arg.TLI), DT(Arg.DT),
54 : AAResultBase(Arg), DL(Arg.DL), TLI(Arg.TLI), AC(Arg.AC), DT(Arg.DT),
5255 LI(Arg.LI) {}
5356 BasicAAResult(BasicAAResult &&Arg)
54 : AAResultBase(std::move(Arg)), DL(Arg.DL), TLI(Arg.TLI),
57 : AAResultBase(std::move(Arg)), DL(Arg.DL), TLI(Arg.TLI), AC(Arg.AC),
5558 DT(Arg.DT), LI(Arg.LI) {}
5659
5760 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB);
141144 static const Value *
142145 GetLinearExpression(const Value *V, APInt &Scale, APInt &Offset,
143146 unsigned &ZExtBits, unsigned &SExtBits,
144 const DataLayout &DL, unsigned Depth,
147 const DataLayout &DL, unsigned Depth, AssumptionCache *AC,
145148 DominatorTree *DT, bool &NSW, bool &NUW);
146149
147150 static bool DecomposeGEPExpression(const Value *V, DecomposedGEP &Decomposed,
148 const DataLayout &DL, DominatorTree *DT);
151 const DataLayout &DL, AssumptionCache *AC, DominatorTree *DT);
149152
150153 static bool isGEPBaseAtNegativeOffset(const GEPOperator *GEPOp,
151154 const DecomposedGEP &DecompGEP, const DecomposedGEP &DecompObject,
162165 bool
163166 constantOffsetHeuristic(const SmallVectorImpl &VarIndices,
164167 uint64_t V1Size, uint64_t V2Size, int64_t BaseOffset,
165 DominatorTree *DT);
168 AssumptionCache *AC, DominatorTree *DT);
166169
167170 bool isValueEqualInPotentialCycles(const Value *V1, const Value *V2);
168171
1919 #include "llvm/IR/CallSite.h"
2020
2121 namespace llvm {
22 class AssumptionCache;
2223 class BasicBlock;
2324 class Loop;
2425 class Function;
8990
9091 /// \brief Collect a loop's ephemeral values (those used only by an assume
9192 /// or similar intrinsics in the loop).
92 static void collectEphemeralValues(const Loop *L,
93 static void collectEphemeralValues(const Loop *L, AssumptionCache *AC,
9394 SmallPtrSetImpl &EphValues);
9495
9596 /// \brief Collect a functions's ephemeral values (those used only by an
9697 /// assume or similar intrinsics in the function).
97 static void collectEphemeralValues(const Function *L,
98 static void collectEphemeralValues(const Function *L, AssumptionCache *AC,
9899 SmallPtrSetImpl &EphValues);
99100 };
100101
3333 class Function;
3434 class Instruction;
3535 class DominatorTree;
36 class AssumptionCache;
3637
3738 class DemandedBits {
3839 public:
39 DemandedBits(Function &F, DominatorTree &DT) :
40 F(F), DT(DT), Analyzed(false) {}
40 DemandedBits(Function &F, AssumptionCache &AC, DominatorTree &DT) :
41 F(F), AC(AC), DT(DT), Analyzed(false) {}
4142
4243 /// Return the bits demanded from instruction I.
4344 APInt getDemandedBits(Instruction *I);
4950
5051 private:
5152 Function &F;
53 AssumptionCache ∾
5254 DominatorTree &DT;
5355
5456 void performAnalysis();
2121
2222 namespace llvm {
2323
24 class AssumptionCache;
2425 class DominatorTree;
2526 class Instruction;
2627 class Value;
9293 class IVUsers {
9394 friend class IVStrideUse;
9495 Loop *L;
96 AssumptionCache *AC;
9597 LoopInfo *LI;
9698 DominatorTree *DT;
9799 ScalarEvolution *SE;
105107 SmallPtrSet EphValues;
106108
107109 public:
108 IVUsers(Loop *L, LoopInfo *LI, DominatorTree *DT,
110 IVUsers(Loop *L, AssumptionCache *AC, LoopInfo *LI, DominatorTree *DT,
109111 ScalarEvolution *SE);
110112
111113 IVUsers(IVUsers &&X)
112 : L(std::move(X.L)), DT(std::move(X.DT)),
114 : L(std::move(X.L)), AC(std::move(X.AC)), DT(std::move(X.DT)),
113115 SE(std::move(X.SE)), Processed(std::move(X.Processed)),
114116 IVUses(std::move(X.IVUses)), EphValues(std::move(X.EphValues)) {
115117 for (IVStrideUse &U : IVUses)
1414 #define LLVM_ANALYSIS_INLINECOST_H
1515
1616 #include "llvm/Analysis/CallGraphSCCPass.h"
17 #include "llvm/Analysis/AssumptionCache.h"
1718 #include
1819 #include
1920
2021 namespace llvm {
22 class AssumptionCacheTracker;
2123 class CallSite;
2224 class DataLayout;
2325 class Function;
167169 InlineCost
168170 getInlineCost(CallSite CS, const InlineParams &Params,
169171 TargetTransformInfo &CalleeTTI,
172 std::function &GetAssumptionCache,
170173 ProfileSummaryInfo *PSI);
171174
172175 /// \brief Get an InlineCost with the callee explicitly specified.
177180 InlineCost
178181 getInlineCost(CallSite CS, Function *Callee, const InlineParams &Params,
179182 TargetTransformInfo &CalleeTTI,
183 std::function &GetAssumptionCache,
180184 ProfileSummaryInfo *PSI);
181185
182186 /// \brief Minimal filter to detect invalid constructs for inlining.
3636 namespace llvm {
3737 template
3838 class ArrayRef;
39 class AssumptionCache;
3940 class DominatorTree;
4041 class Instruction;
4142 class DataLayout;
4950 const DataLayout &DL,
5051 const TargetLibraryInfo *TLI = nullptr,
5152 const DominatorTree *DT = nullptr,
53 AssumptionCache *AC = nullptr,
5254 const Instruction *CxtI = nullptr);
5355
5456 /// Given operands for a Sub, fold the result or return null.
5658 const DataLayout &DL,
5759 const TargetLibraryInfo *TLI = nullptr,
5860 const DominatorTree *DT = nullptr,
61 AssumptionCache *AC = nullptr,
5962 const Instruction *CxtI = nullptr);
6063
6164 /// Given operands for an FAdd, fold the result or return null.
6366 const DataLayout &DL,
6467 const TargetLibraryInfo *TLI = nullptr,
6568 const DominatorTree *DT = nullptr,
69 AssumptionCache *AC = nullptr,
6670 const Instruction *CxtI = nullptr);
6771
6872 /// Given operands for an FSub, fold the result or return null.
7074 const DataLayout &DL,
7175 const TargetLibraryInfo *TLI = nullptr,
7276 const DominatorTree *DT = nullptr,
77 AssumptionCache *AC = nullptr,
7378 const Instruction *CxtI = nullptr);
7479
7580 /// Given operands for an FMul, fold the result or return null.
7782 const DataLayout &DL,
7883 const TargetLibraryInfo *TLI = nullptr,
7984 const DominatorTree *DT = nullptr,
85 AssumptionCache *AC = nullptr,
8086 const Instruction *CxtI = nullptr);
8187
8288 /// Given operands for a Mul, fold the result or return null.
8389 Value *SimplifyMulInst(Value *LHS, Value *RHS, const DataLayout &DL,
8490 const TargetLibraryInfo *TLI = nullptr,
8591 const DominatorTree *DT = nullptr,
92 AssumptionCache *AC = nullptr,
8693 const Instruction *CxtI = nullptr);
8794
8895 /// Given operands for an SDiv, fold the result or return null.
8996 Value *SimplifySDivInst(Value *LHS, Value *RHS, const DataLayout &DL,
9097 const TargetLibraryInfo *TLI = nullptr,
9198 const DominatorTree *DT = nullptr,
99 AssumptionCache *AC = nullptr,
92100 const Instruction *CxtI = nullptr);
93101
94102 /// Given operands for a UDiv, fold the result or return null.
95103 Value *SimplifyUDivInst(Value *LHS, Value *RHS, const DataLayout &DL,
96104 const TargetLibraryInfo *TLI = nullptr,
97105 const DominatorTree *DT = nullptr,
106 AssumptionCache *AC = nullptr,
98107 const Instruction *CxtI = nullptr);
99108
100109 /// Given operands for an FDiv, fold the result or return null.
102111 const DataLayout &DL,
103112 const TargetLibraryInfo *TLI = nullptr,
104113 const DominatorTree *DT = nullptr,
114 AssumptionCache *AC = nullptr,
105115 const Instruction *CxtI = nullptr);
106116
107117 /// Given operands for an SRem, fold the result or return null.
108118 Value *SimplifySRemInst(Value *LHS, Value *RHS, const DataLayout &DL,
109119 const TargetLibraryInfo *TLI = nullptr,
110120 const DominatorTree *DT = nullptr,
121 AssumptionCache *AC = nullptr,
111122 const Instruction *CxtI = nullptr);
112123
113124 /// Given operands for a URem, fold the result or return null.
114125 Value *SimplifyURemInst(Value *LHS, Value *RHS, const DataLayout &DL,
115126 const TargetLibraryInfo *TLI = nullptr,
116127 const DominatorTree *DT = nullptr,
128 AssumptionCache *AC = nullptr,
117129 const Instruction *CxtI = nullptr);
118130
119131 /// Given operands for an FRem, fold the result or return null.
121133 const DataLayout &DL,
122134 const TargetLibraryInfo *TLI = nullptr,
123135 const DominatorTree *DT = nullptr,
136 AssumptionCache *AC = nullptr,
124137 const Instruction *CxtI = nullptr);
125138
126139 /// Given operands for a Shl, fold the result or return null.
128141 const DataLayout &DL,
129142 const TargetLibraryInfo *TLI = nullptr,
130143 const DominatorTree *DT = nullptr,
144 AssumptionCache *AC = nullptr,
131145 const Instruction *CxtI = nullptr);
132146
133147 /// Given operands for a LShr, fold the result or return null.
135149 const DataLayout &DL,
136150 const TargetLibraryInfo *TLI = nullptr,
137151 const DominatorTree *DT = nullptr,
152 AssumptionCache *AC = nullptr,
138153 const Instruction *CxtI = nullptr);
139154
140155 /// Given operands for a AShr, fold the result or return nulll.
142157 const DataLayout &DL,
143158 const TargetLibraryInfo *TLI = nullptr,
144159 const DominatorTree *DT = nullptr,
160 AssumptionCache *AC = nullptr,
145161 const Instruction *CxtI = nullptr);
146162
147163 /// Given operands for an And, fold the result or return null.
148164 Value *SimplifyAndInst(Value *LHS, Value *RHS, const DataLayout &DL,
149165 const TargetLibraryInfo *TLI = nullptr,
150166 const DominatorTree *DT = nullptr,
167 AssumptionCache *AC = nullptr,
151168 const Instruction *CxtI = nullptr);
152169
153170 /// Given operands for an Or, fold the result or return null.
154171 Value *SimplifyOrInst(Value *LHS, Value *RHS, const DataLayout &DL,
155172 const TargetLibraryInfo *TLI = nullptr,
156173 const DominatorTree *DT = nullptr,
174 AssumptionCache *AC = nullptr,
157175 const Instruction *CxtI = nullptr);
158176
159177 /// Given operands for an Xor, fold the result or return null.
160178 Value *SimplifyXorInst(Value *LHS, Value *RHS, const DataLayout &DL,
161179 const TargetLibraryInfo *TLI = nullptr,
162180 const DominatorTree *DT = nullptr,
181 AssumptionCache *AC = nullptr,
163182 const Instruction *CxtI = nullptr);
164183
165184 /// Given operands for an ICmpInst, fold the result or return null.
167186 const DataLayout &DL,
168187 const TargetLibraryInfo *TLI = nullptr,
169188 const DominatorTree *DT = nullptr,
189 AssumptionCache *AC = nullptr,
170190 const Instruction *CxtI = nullptr);
171191
172192 /// Given operands for an FCmpInst, fold the result or return null.
174194 FastMathFlags FMF, const DataLayout &DL,
175195 const TargetLibraryInfo *TLI = nullptr,
176196 const DominatorTree *DT = nullptr,
197 AssumptionCache *AC = nullptr,
177198 const Instruction *CxtI = nullptr);
178199
179200 /// Given operands for a SelectInst, fold the result or return null.
181202 const DataLayout &DL,
182203 const TargetLibraryInfo *TLI = nullptr,
183204 const DominatorTree *DT = nullptr,
205 AssumptionCache *AC = nullptr,
184206 const Instruction *CxtI = nullptr);
185207
186208 /// Given operands for a GetElementPtrInst, fold the result or return null.
188210 const DataLayout &DL,
189211 const TargetLibraryInfo *TLI = nullptr,
190212 const DominatorTree *DT = nullptr,
213 AssumptionCache *AC = nullptr,
191214 const Instruction *CxtI = nullptr);
192215
193216 /// Given operands for an InsertValueInst, fold the result or return null.
195218 ArrayRef Idxs, const DataLayout &DL,
196219 const TargetLibraryInfo *TLI = nullptr,
197220 const DominatorTree *DT = nullptr,
221 AssumptionCache *AC = nullptr,
198222 const Instruction *CxtI = nullptr);
199223
200224 /// Given operands for an ExtractValueInst, fold the result or return null.
202226 const DataLayout &DL,
203227 const TargetLibraryInfo *TLI = nullptr,
204228 const DominatorTree *DT = nullptr,
229 AssumptionCache *AC = nullptr,
205230 const Instruction *CxtI = nullptr);
206231
207232 /// Given operands for an ExtractElementInst, fold the result or return null.
209234 const DataLayout &DL,
210235 const TargetLibraryInfo *TLI = nullptr,
211236 const DominatorTree *DT = nullptr,
237 AssumptionCache *AC = nullptr,
212238 const Instruction *CxtI = nullptr);
213239
214240 /// Given operands for a CastInst, fold the result or return null.
216242 const DataLayout &DL,
217243 const TargetLibraryInfo *TLI = nullptr,
218244 const DominatorTree *DT = nullptr,
245 AssumptionCache *AC = nullptr,
219246 const Instruction *CxtI = nullptr);
220247
221248 //=== Helper functions for higher up the class hierarchy.
226253 const DataLayout &DL,
227254 const TargetLibraryInfo *TLI = nullptr,
228255 const DominatorTree *DT = nullptr,
256 AssumptionCache *AC = nullptr,
229257 const Instruction *CxtI = nullptr);
230258
231259 /// Given operands for a BinaryOperator, fold the result or return null.
233261 const DataLayout &DL,
234262 const TargetLibraryInfo *TLI = nullptr,
235263 const DominatorTree *DT = nullptr,
264 AssumptionCache *AC = nullptr,
236265 const Instruction *CxtI = nullptr);
237266
238267 /// Given operands for an FP BinaryOperator, fold the result or return null.
242271 const FastMathFlags &FMF, const DataLayout &DL,
243272 const TargetLibraryInfo *TLI = nullptr,
244273 const DominatorTree *DT = nullptr,
274 AssumptionCache *AC = nullptr,
245275 const Instruction *CxtI = nullptr);
246276
247277 /// Given a function and iterators over arguments, fold the result or return
250280 User::op_iterator ArgEnd, const DataLayout &DL,
251281 const TargetLibraryInfo *TLI = nullptr,
252282 const DominatorTree *DT = nullptr,
283 AssumptionCache *AC = nullptr,
253284 const Instruction *CxtI = nullptr);
254285
255286 /// Given a function and set of arguments, fold the result or return null.
256287 Value *SimplifyCall(Value *V, ArrayRef Args, const DataLayout &DL,
257288 const TargetLibraryInfo *TLI = nullptr,
258289 const DominatorTree *DT = nullptr,
290 AssumptionCache *AC = nullptr,
259291 const Instruction *CxtI = nullptr);
260292
261293 /// See if we can compute a simplified version of this instruction. If not,
262294 /// return null.
263295 Value *SimplifyInstruction(Instruction *I, const DataLayout &DL,
264296 const TargetLibraryInfo *TLI = nullptr,
265 const DominatorTree *DT = nullptr);
297 const DominatorTree *DT = nullptr,
298 AssumptionCache *AC = nullptr);
266299
267300 /// Replace all uses of 'I' with 'SimpleV' and simplify the uses recursively.
268301 ///
273306 /// The function returns true if any simplifications were performed.
274307 bool replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
275308 const TargetLibraryInfo *TLI = nullptr,
276 const DominatorTree *DT = nullptr);
309 const DominatorTree *DT = nullptr,
310 AssumptionCache *AC = nullptr);
277311
278312 /// Recursively attempt to simplify an instruction.
279313 ///
283317 /// performed.
284318 bool recursivelySimplifyInstruction(Instruction *I,
285319 const TargetLibraryInfo *TLI = nullptr,
286 const DominatorTree *DT = nullptr);
320 const DominatorTree *DT = nullptr,
321 AssumptionCache *AC = nullptr);
287322 } // end namespace llvm
288323
289324 #endif
1818 #include "llvm/Pass.h"
1919
2020 namespace llvm {
21 class AssumptionCache;
2122 class Constant;
2223 class ConstantRange;
2324 class DataLayout;
2930 /// This pass computes, caches, and vends lazy value constraint information.
3031 class LazyValueInfo {
3132 friend class LazyValueInfoWrapperPass;
33 AssumptionCache *AC = nullptr;
3234 class TargetLibraryInfo *TLI = nullptr;
3335 DominatorTree *DT = nullptr;
3436 void *PImpl = nullptr;
3739 public:
3840 ~LazyValueInfo();
3941 LazyValueInfo() {}
40 LazyValueInfo(TargetLibraryInfo *TLI_,
42 LazyValueInfo(AssumptionCache *AC_, TargetLibraryInfo *TLI_,
4143 DominatorTree *DT_)
42 : TLI(TLI_), DT(DT_) {}
44 : AC(AC_), TLI(TLI_), DT(DT_) {}
4345 LazyValueInfo(LazyValueInfo &&Arg)
44 : TLI(Arg.TLI), DT(Arg.DT), PImpl(Arg.PImpl) {
46 : AC(Arg.AC), TLI(Arg.TLI), DT(Arg.DT), PImpl(Arg.PImpl) {
4547 Arg.PImpl = nullptr;
4648 }
4749 LazyValueInfo &operator=(LazyValueInfo &&Arg) {
4850 releaseMemory();
51 AC = Arg.AC;
4952 TLI = Arg.TLI;
5053 DT = Arg.DT;
5154 PImpl = Arg.PImpl;
2929 class FunctionPass;
3030 class Instruction;
3131 class CallSite;
32 class AssumptionCache;
3233 class MemoryDependenceResults;
3334 class PredIteratorCache;
3435 class DominatorTree;
337338
338339 /// Current AA implementation, just a cache.
339340 AliasAnalysis &AA;
341 AssumptionCache ∾
340342 const TargetLibraryInfo &TLI;
341343 DominatorTree &DT;
342344 PredIteratorCache PredCache;
343345
344346 public:
345 MemoryDependenceResults(AliasAnalysis &AA,
347 MemoryDependenceResults(AliasAnalysis &AA, AssumptionCache &AC,
346348 const TargetLibraryInfo &TLI,
347349 DominatorTree &DT)
348 : AA(AA), TLI(TLI), DT(DT) {}
350 : AA(AA), AC(AC), TLI(TLI), DT(DT) {}
349351
350352 /// Some methods limit the number of instructions they will examine.
351353 /// The return value of this method is the default limit that will be
1717 #include "llvm/IR/Instruction.h"
1818
1919 namespace llvm {
20 class AssumptionCache;
2021 class DominatorTree;
2122 class DataLayout;
2223 class TargetLibraryInfo;
4142 /// TLI - The target library info if known, otherwise null.
4243 const TargetLibraryInfo *TLI;
4344
45 /// A cache of @llvm.assume calls used by SimplifyInstruction.
46 AssumptionCache *AC;
47
4448 /// InstInputs - The inputs for our symbolic address.
4549 SmallVector InstInputs;
4650
4751 public:
48 PHITransAddr(Value *addr, const DataLayout &DL)
49 : Addr(addr), DL(DL), TLI(nullptr) {
52 PHITransAddr(Value *addr, const DataLayout &DL, AssumptionCache *AC)
53 : Addr(addr), DL(DL), TLI(nullptr), AC(AC) {
5054 // If the address is an instruction, the whole thing is considered an input.
5155 if (Instruction *I = dyn_cast(Addr))
5256 InstInputs.push_back(I);
3636
3737 namespace llvm {
3838 class APInt;
39 class AssumptionCache;
3940 class Constant;
4041 class ConstantInt;
4142 class DominatorTree;
473474 ///
474475 TargetLibraryInfo &TLI;
475476
477 /// The tracker for @llvm.assume intrinsics in this function.
478 AssumptionCache ∾
479
476480 /// The dominator tree.
477481 ///
478482 DominatorTree &DT;
526530 /// This is a cache of the values we have analyzed so far.
527531 ///
528532 ValueExprMapType ValueExprMap;
529
530 /// This is a map of SCEVs to intrinsics (e.g. assumptions) that might affect
531 /// (i.e. imply something about) them.
532 DenseMap> AffectedMap;
533533
534534 /// Mark predicate values currently being processed by isImpliedCond.
535535 SmallPtrSet PendingLoopPredicates;
799799 ConstantRange getRangeViaFactoring(const SCEV *Start, const SCEV *Stop,
800800 const SCEV *MaxBECount, unsigned BitWidth);
801801
802 /// Add to the AffectedMap this SCEV if its operands are in the AffectedMap.
803 void addAffectedFromOperands(const SCEV *S);
804
805802 /// We know that there is no SCEV for the specified value. Analyze the
806803 /// expression.
807804 const SCEV *createSCEV(Value *V);
11091106 bool isAddRecNeverPoison(const Instruction *I, const Loop *L);
11101107
11111108 public:
1112 ScalarEvolution(Function &F, TargetLibraryInfo &TLI,
1109 ScalarEvolution(Function &F, TargetLibraryInfo &TLI, AssumptionCache &AC,
11131110 DominatorTree &DT, LoopInfo &LI);
11141111 ~ScalarEvolution();
11151112 ScalarEvolution(ScalarEvolution &&Arg);
2323 template class ArrayRef;
2424 class APInt;
2525 class AddOperator;
26 class AssumptionCache;
2627 class DataLayout;
2728 class DominatorTree;
2829 class GEPOperator;
4849 /// for all of the elements in the vector.
4950 void computeKnownBits(const Value *V, APInt &KnownZero, APInt &KnownOne,
5051 const DataLayout &DL, unsigned Depth = 0,
52 AssumptionCache *AC = nullptr,
5153 const Instruction *CxtI = nullptr,
5254 const DominatorTree *DT = nullptr);
5355 /// Compute known bits from the range metadata.
5860 /// Return true if LHS and RHS have no common bits set.
5961 bool haveNoCommonBitsSet(const Value *LHS, const Value *RHS,
6062 const DataLayout &DL,
63 AssumptionCache *AC = nullptr,
6164 const Instruction *CxtI = nullptr,
6265 const DominatorTree *DT = nullptr);
6366
6568 /// wrapper around computeKnownBits.
6669 void ComputeSignBit(const Value *V, bool &KnownZero, bool &KnownOne,
6770 const DataLayout &DL, unsigned Depth = 0,
71 AssumptionCache *AC = nullptr,
6872 const Instruction *CxtI = nullptr,
6973 const DominatorTree *DT = nullptr);
7074
7579 /// value is either a power of two or zero.
7680 bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL,
7781 bool OrZero = false, unsigned Depth = 0,
82 AssumptionCache *AC = nullptr,
7883 const Instruction *CxtI = nullptr,
7984 const DominatorTree *DT = nullptr);
8085
8388 /// defined. Supports values with integer or pointer type and vectors of
8489 /// integers.
8590 bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth = 0,
91 AssumptionCache *AC = nullptr,
8692 const Instruction *CxtI = nullptr,
8793 const DominatorTree *DT = nullptr);
8894
8995 /// Returns true if the give value is known to be non-negative.
9096 bool isKnownNonNegative(const Value *V, const DataLayout &DL,
9197 unsigned Depth = 0,
98 AssumptionCache *AC = nullptr,
9299 const Instruction *CxtI = nullptr,
93100 const DominatorTree *DT = nullptr);
94101
95102 /// Returns true if the given value is known be positive (i.e. non-negative
96103 /// and non-zero).
97104 bool isKnownPositive(const Value *V, const DataLayout &DL, unsigned Depth = 0,
105 AssumptionCache *AC = nullptr,
98106 const Instruction *CxtI = nullptr,
99107 const DominatorTree *DT = nullptr);
100108
101109 /// Returns true if the given value is known be negative (i.e. non-positive
102110 /// and non-zero).
103111 bool isKnownNegative(const Value *V, const DataLayout &DL, unsigned Depth = 0,
112 AssumptionCache *AC = nullptr,
104113 const Instruction *CxtI = nullptr,
105114 const DominatorTree *DT = nullptr);
106115
107116 /// Return true if the given values are known to be non-equal when defined.
108117 /// Supports scalar integer types only.
109118 bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL,
119 AssumptionCache *AC = nullptr,
110120 const Instruction *CxtI = nullptr,
111121 const DominatorTree *DT = nullptr);
112122
121131 /// for all of the elements in the vector.
122132 bool MaskedValueIsZero(const Value *V, const APInt &Mask,
123133 const DataLayout &DL,
124 unsigned Depth = 0,
134 unsigned Depth = 0, AssumptionCache *AC = nullptr,
125135 const Instruction *CxtI = nullptr,
126136 const DominatorTree *DT = nullptr);
127137
133143 /// sign bits for the vector element with the mininum number of known sign
134144 /// bits.
135145 unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL,
136 unsigned Depth = 0,
146 unsigned Depth = 0, AssumptionCache *AC = nullptr,
137147 const Instruction *CxtI = nullptr,
138148 const DominatorTree *DT = nullptr);
139149
314324 OverflowResult computeOverflowForUnsignedMul(const Value *LHS,
315325 const Value *RHS,
316326 const DataLayout &DL,
327 AssumptionCache *AC,
317328 const Instruction *CxtI,
318329 const DominatorTree *DT);
319330 OverflowResult computeOverflowForUnsignedAdd(const Value *LHS,
320331 const Value *RHS,
321332 const DataLayout &DL,
333 AssumptionCache *AC,
322334 const Instruction *CxtI,
323335 const DominatorTree *DT);
324336 OverflowResult computeOverflowForSignedAdd(const Value *LHS, const Value *RHS,
325337 const DataLayout &DL,
338 AssumptionCache *AC = nullptr,
326339 const Instruction *CxtI = nullptr,
327340 const DominatorTree *DT = nullptr);
328341 /// This version also leverages the sign bit of Add if known.
329342 OverflowResult computeOverflowForSignedAdd(const AddOperator *Add,
330343 const DataLayout &DL,
344 AssumptionCache *AC = nullptr,
331345 const Instruction *CxtI = nullptr,
332346 const DominatorTree *DT = nullptr);
333347
460474 const DataLayout &DL,
461475 bool InvertAPred = false,
462476 unsigned Depth = 0,
477 AssumptionCache *AC = nullptr,
463478 const Instruction *CxtI = nullptr,
464479 const DominatorTree *DT = nullptr);
465480 } // end namespace llvm
6767 void initializeAlignmentFromAssumptionsPass(PassRegistry&);
6868 void initializeAlwaysInlinerLegacyPassPass(PassRegistry&);
6969 void initializeArgPromotionPass(PassRegistry&);
70 void initializeAssumptionCacheTrackerPass(PassRegistry &);
7071 void initializeAtomicExpandPass(PassRegistry&);
7172 void initializeBBVectorizePass(PassRegistry&);
7273 void initializeBDCELegacyPassPass(PassRegistry &);
2222 #include "llvm/Transforms/Utils/ImportedFunctionsInliningStatistics.h"
2323
2424 namespace llvm {
25 class AssumptionCacheTracker;
2526 class CallSite;
2627 class DataLayout;
2728 class InlineCost;
7576 bool InsertLifetime;
7677
7778 protected:
79 AssumptionCacheTracker *ACT;
7880 ProfileSummaryInfo *PSI;
7981 ImportedFunctionsInliningStatistics ImportedFunctionsStats;
8082 };
2929 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
3030
3131 // Glue for old PM.
32 bool runImpl(Function &F, ScalarEvolution *SE_, DominatorTree *DT_);
32 bool runImpl(Function &F, AssumptionCache &AC, ScalarEvolution *SE_,
33 DominatorTree *DT_);
3334
3435 // For memory transfers, we need a common alignment for both the source and
3536 // destination. If we have a new alignment for only one operand of a transfer
2020 #include "llvm/ADT/SetVector.h"
2121 #include "llvm/ADT/SmallPtrSet.h"
2222 #include "llvm/Analysis/AliasAnalysis.h"
23 #include "llvm/Analysis/AssumptionCache.h"
2324 #include "llvm/Analysis/LoopInfo.h"
2425 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
2526 #include "llvm/IR/Dominators.h"
107108 MemoryDependenceResults *MD;
108109 DominatorTree *DT;
109110 const TargetLibraryInfo *TLI;
111 AssumptionCache *AC;
110112 SetVector DeadBlocks;
111113 OptimizationRemarkEmitter *ORE;
112114
132134 typedef SmallVector AvailValInBlkVect;
133135 typedef SmallVector UnavailBlkVect;
134136
135 bool runImpl(Function &F, DominatorTree &RunDT,
137 bool runImpl(Function &F, AssumptionCache &RunAC, DominatorTree &RunDT,
136138 const TargetLibraryInfo &RunTLI, AAResults &RunAA,
137139 MemoryDependenceResults *RunMD, LoopInfo *LI,
138140 OptimizationRemarkEmitter *ORE);
1616
1717 #include "llvm/ADT/STLExtras.h"
1818 #include "llvm/Analysis/AliasAnalysis.h"
19 #include "llvm/Analysis/AssumptionCache.h"
1920 #include "llvm/Analysis/GlobalsModRef.h"
2021 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
2122 #include "llvm/Analysis/TargetLibraryInfo.h"
3132 MemoryDependenceResults *MD = nullptr;
3233 TargetLibraryInfo *TLI = nullptr;
3334 std::function LookupAliasAnalysis;
35 std::function LookupAssumptionCache;
3436 std::function LookupDomTree;
3537
3638 public:
4042 bool runImpl(Function &F, MemoryDependenceResults *MD_,
4143 TargetLibraryInfo *TLI_,
4244 std::function LookupAliasAnalysis_,
45 std::function LookupAssumptionCache_,
4346 std::function LookupDomTree_);
4447
4548 private:
8080
8181 #include "llvm/ADT/DenseMap.h"
8282 #include "llvm/ADT/SmallVector.h"
83 #include "llvm/Analysis/AssumptionCache.h"
8384 #include "llvm/Analysis/ScalarEvolution.h"
8485 #include "llvm/Analysis/TargetLibraryInfo.h"
8586 #include "llvm/Analysis/TargetTransformInfo.h"
9394 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
9495
9596 // Glue for old PM.
96 bool runImpl(Function &F, DominatorTree *DT_,
97 bool runImpl(Function &F, AssumptionCache *AC_, DominatorTree *DT_,
9798 ScalarEvolution *SE_, TargetLibraryInfo *TLI_,
9899 TargetTransformInfo *TTI_);
99100
150151 // to be an index of GEP.
151152 bool requiresSignExtension(Value *Index, GetElementPtrInst *GEP);
152153
154 AssumptionCache *AC;
153155 const DataLayout *DL;
154156 DominatorTree *DT;
155157 ScalarEvolution *SE;
1616 #define LLVM_TRANSFORMS_SCALAR_SROA_H
1717
1818 #include "llvm/ADT/SetVector.h"
19 #include "llvm/Analysis/AssumptionCache.h"
1920 #include "llvm/IR/Dominators.h"
2021 #include "llvm/IR/Function.h"
2122 #include "llvm/IR/PassManager.h"
2223
2324 namespace llvm {
24 class AllocaInst;
25 class SelectInst;
26 class PHINode;
2725
2826 /// A private "module" namespace for types and utilities used by SROA. These
2927 /// are implementation details and should not be used by clients.
5553 class SROA : public PassInfoMixin {
5654 LLVMContext *C;
5755 DominatorTree *DT;
56 AssumptionCache *AC;
5857
5958 /// \brief Worklist of alloca instructions to simplify.
6059 ///
9998 SetVector> SpeculatableSelects;
10099
101100 public:
102 SROA() : C(nullptr), DT(nullptr) {}
101 SROA() : C(nullptr), DT(nullptr), AC(nullptr) {}
103102
104103 /// \brief Run the pass over the function.
105104 PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
109108 friend class sroa::SROALegacyPass;
110109
111110 /// Helper used by both the public run method and by the legacy pass.
112 PreservedAnalyses runImpl(Function &F, DominatorTree &RunDT);
111 PreservedAnalyses runImpl(Function &F, DominatorTree &RunDT,
112 AssumptionCache &RunAC);
113113
114114 bool presplitLoadsAndStores(AllocaInst &AI, sroa::AllocaSlices &AS);
115115 AllocaInst *rewritePartition(AllocaInst &AI, sroa::AllocaSlices &AS,
2020 #include "llvm/ADT/SmallVector.h"
2121 #include "llvm/ADT/Twine.h"
2222 #include "llvm/Analysis/AliasAnalysis.h"
23 #include "llvm/Analysis/AssumptionCache.h"
2324 #include "llvm/IR/ValueHandle.h"
2425 #include "llvm/IR/ValueMap.h"
2526 #include "llvm/Transforms/Utils/ValueMapper.h"
4445 class Loop;
4546 class LoopInfo;
4647 class AllocaInst;
48 class AssumptionCacheTracker;
4749 class DominatorTree;
4850
4951 /// Return an exact copy of the specified module
173175 /// InlineFunction call, and records the auxiliary results produced by it.
174176 class InlineFunctionInfo {
175177 public:
176 explicit InlineFunctionInfo(CallGraph *cg = nullptr)
177 : CG(cg) {}
178 explicit InlineFunctionInfo(CallGraph *cg = nullptr,
179 std::function
180 *GetAssumptionCache = nullptr)
181 : CG(cg), GetAssumptionCache(GetAssumptionCache) {}
178182
179183 /// CG - If non-null, InlineFunction will update the callgraph to reflect the
180184 /// changes it makes.
181185 CallGraph *CG;
186 std::function *GetAssumptionCache;
182187
183188 /// StaticAllocas - InlineFunction fills this in with all static allocas that
184189 /// get copied into the caller.
3737 class Value;
3838 class PHINode;
3939 class AllocaInst;
40 class AssumptionCache;
4041 class ConstantExpr;
4142 class DataLayout;
4243 class TargetLibraryInfo;
135136 /// parameter, providing the set of loop header that SimplifyCFG should not
136137 /// eliminate.
137138 bool SimplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
138 unsigned BonusInstThreshold,
139 unsigned BonusInstThreshold, AssumptionCache *AC = nullptr,
139140 SmallPtrSetImpl *LoopHeaders = nullptr);
140141
141142 /// This function is used to flatten a CFG. For example, it uses parallel-and
174175 unsigned getOrEnforceKnownAlignment(Value *V, unsigned PrefAlign,
175176 const DataLayout &DL,
176177 const Instruction *CxtI = nullptr,
178 AssumptionCache *AC = nullptr,
177179 const DominatorTree *DT = nullptr);
178180
179181 /// Try to infer an alignment for the specified pointer.
180182 static inline unsigned getKnownAlignment(Value *V, const DataLayout &DL,
181183 const Instruction *CxtI = nullptr,
184 AssumptionCache *AC = nullptr,
182185 const DominatorTree *DT = nullptr) {
183 return getOrEnforceKnownAlignment(V, 0, DL, CxtI, DT);
186 return getOrEnforceKnownAlignment(V, 0, DL, CxtI, AC, DT);
184187 }
185188
186189 /// Given a getelementptr instruction/constantexpr, emit the code necessary to
3838 #ifndef LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H
3939 #define LLVM_TRANSFORMS_UTILS_LOOPSIMPLIFY_H
4040
41 #include "llvm/Analysis/AssumptionCache.h"
4142 #include "llvm/Analysis/ScalarEvolution.h"
4243 #include "llvm/IR/Dominators.h"
4344 #include "llvm/IR/PassManager.h"
5657 /// it into a simplified loop nest with preheaders and single backedges. It will
5758 /// update \c AliasAnalysis and \c ScalarEvolution analyses if they're non-null.
5859 bool simplifyLoop(Loop *L, DominatorTree *DT, LoopInfo *LI, ScalarEvolution *SE,
59 bool PreserveLCSSA);
60 AssumptionCache *AC, bool PreserveLCSSA);
6061
6162 } // end namespace llvm
6263
2222 namespace llvm {
2323 class AliasSet;
2424 class AliasSetTracker;
25 class AssumptionCache;
2526 class BasicBlock;
2627 class DataLayout;
2728 class DominatorTree;
962962 if (WalkingPhi && Location.Ptr) {
963963 PHITransAddr Translator(
964964 const_cast(Location.Ptr),
965 OriginalAccess->getBlock()->getModule()->getDataLayout());
965 OriginalAccess->getBlock()->getModule()->getDataLayout(), nullptr);
966966 if (!Translator.PHITranslateValue(OriginalAccess->getBlock(),
967967 DefIterator.getPhiArgBlock(), nullptr,
968968 false))
2020 class AllocaInst;
2121 class DominatorTree;
2222 class AliasSetTracker;
23 class AssumptionCache;
2324
2425 /// \brief Return true if this alloca is legal for promotion.
2526 ///
3940 /// If AST is specified, the specified tracker is updated to reflect changes
4041 /// made to the IR.
4142 void PromoteMemToReg(ArrayRef Allocas, DominatorTree &DT,
42 AliasSetTracker *AST = nullptr);
43 AliasSetTracker *AST = nullptr,
44 AssumptionCache *AC = nullptr);
4345
4446 } // End llvm namespace
4547
2222 namespace llvm {
2323
2424 class StringRef;
25 class AssumptionCache;
2526 class DominatorTree;
2627 class Loop;
2728 class LoopInfo;
3536 bool AllowRuntime, bool AllowExpensiveTripCount,
3637 bool PreserveCondBr, bool PreserveOnlyFirst,
3738 unsigned TripMultiple, unsigned PeelCount, LoopInfo *LI,
38 ScalarEvolution *SE, DominatorTree *DT,
39 ScalarEvolution *SE, DominatorTree *DT, AssumptionCache *AC,
3940 OptimizationRemarkEmitter *ORE, bool PreserveLCSSA);
4041
4142 bool UnrollRuntimeLoopRemainder(Loop *L, unsigned Count,
5050
5151 #include "llvm/ADT/MapVector.h"
5252 #include "llvm/Analysis/AliasAnalysis.h"
53 #include "llvm/Analysis/AssumptionCache.h"
5354 #include "llvm/Analysis/BasicAliasAnalysis.h"
5455 #include "llvm/Analysis/BlockFrequencyInfo.h"
5556 #include "llvm/Analysis/DemandedBits.h"
8182 TargetLibraryInfo *TLI;
8283 DemandedBits *DB;
8384 AliasAnalysis *AA;
85 AssumptionCache *AC;
8486 std::function *GetLAA;
8587 OptimizationRemarkEmitter *ORE;
8688
9294 bool runImpl(Function &F, ScalarEvolution &SE_, LoopInfo &LI_,
9395 TargetTransformInfo &TTI_, DominatorTree &DT_,
9496 BlockFrequencyInfo &BFI_, TargetLibraryInfo *TLI_,
95 DemandedBits &DB_, AliasAnalysis &AA_,
97 DemandedBits &DB_, AliasAnalysis &AA_, AssumptionCache &AC_,
9698 std::function &GetLAA_,
9799 OptimizationRemarkEmitter &ORE);
98100
2020
2121 #include "llvm/ADT/MapVector.h"
2222 #include "llvm/Analysis/AliasAnalysis.h"
23 #include "llvm/Analysis/AssumptionCache.h"
2324 #include "llvm/Analysis/DemandedBits.h"
2425 #include "llvm/Analysis/LoopInfo.h"
2526 #include "llvm/Analysis/ScalarEvolution.h"
4748 AliasAnalysis *AA = nullptr;
4849 LoopInfo *LI = nullptr;
4950 DominatorTree *DT = nullptr;
51 AssumptionCache *AC = nullptr;
5052 DemandedBits *DB = nullptr;
5153 const DataLayout *DL = nullptr;
5254
5658 // Glue for old PM.
5759 bool runImpl(Function &F, ScalarEvolution *SE_, TargetTransformInfo *TTI_,
5860 TargetLibraryInfo *TLI_, AliasAnalysis *AA_, LoopInfo *LI_,
59 DominatorTree *DT_, DemandedBits *DB_);
61 DominatorTree *DT_, AssumptionCache *AC_, DemandedBits *DB_);
6062
6163 private:
6264 /// \brief Collect store and getelementptr instructions and organize them
2222 #include "llvm/Analysis/LoopInfo.h"
2323 #include "llvm/Analysis/MemoryBuiltins.h"
2424 #include "llvm/Analysis/ValueTracking.h"
25 #include "llvm/Analysis/AssumptionCache.h"
2526 #include "llvm/IR/Constants.h"
2627 #include "llvm/IR/DataLayout.h"
2728 #include "llvm/IR/DerivedTypes.h"
180181 /*static*/ const Value *BasicAAResult::GetLinearExpression(
181182 const Value *V, APInt &Scale, APInt &Offset, unsigned &ZExtBits,
182183 unsigned &SExtBits, const DataLayout &DL, unsigned Depth,
183 DominatorTree *DT, bool &NSW, bool &NUW) {
184 AssumptionCache *AC, DominatorTree *DT, bool &NSW, bool &NUW) {
184185 assert(V->getType()->isIntegerTy() && "Not an integer value");
185186
186187 // Limit our recursion depth.
219220 case Instruction::Or:
220221 // X|C == X+C if all the bits in C are unset in X. Otherwise we can't
221222 // analyze it.
222 if (!MaskedValueIsZero(BOp->getOperand(0), RHSC->getValue(), DL, 0,
223 if (!MaskedValueIsZero(BOp->getOperand(0), RHSC->getValue(), DL, 0, AC,
223224 BOp, DT)) {
224225 Scale = 1;
225226 Offset = 0;
228229 LLVM_FALLTHROUGH;
229230 case Instruction::Add:
230231 V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, ZExtBits,
231 SExtBits, DL, Depth + 1, DT, NSW, NUW);
232 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
232233 Offset += RHS;
233234 break;
234235 case Instruction::Sub:
235236 V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, ZExtBits,
236 SExtBits, DL, Depth + 1, DT, NSW, NUW);
237 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
237238 Offset -= RHS;
238239 break;
239240 case Instruction::Mul:
240241 V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, ZExtBits,
241 SExtBits, DL, Depth + 1, DT, NSW, NUW);
242 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
242243 Offset *= RHS;
243244 Scale *= RHS;
244245 break;
245246 case Instruction::Shl:
246247 V = GetLinearExpression(BOp->getOperand(0), Scale, Offset, ZExtBits,
247 SExtBits, DL, Depth + 1, DT, NSW, NUW);
248 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
248249 Offset <<= RHS.getLimitedValue();
249250 Scale <<= RHS.getLimitedValue();
250251 // the semantics of nsw and nuw for left shifts don't match those of
271272 unsigned OldZExtBits = ZExtBits, OldSExtBits = SExtBits;
272273 const Value *Result =
273274 GetLinearExpression(CastOp, Scale, Offset, ZExtBits, SExtBits, DL,
274 Depth + 1, DT, NSW, NUW);
275 Depth + 1, AC, DT, NSW, NUW);
275276
276277 // zext(zext(%x)) == zext(%x), and similarly for sext; we'll handle this
277278 // by just incrementing the number of bits we've extended by.
342343 /// depth (MaxLookupSearchDepth). When DataLayout not is around, it just looks
343344 /// through pointer casts.
344345 bool BasicAAResult::DecomposeGEPExpression(const Value *V,
345 DecomposedGEP &Decomposed, const DataLayout &DL,
346 DecomposedGEP &Decomposed, const DataLayout &DL, AssumptionCache *AC,
346347 DominatorTree *DT) {
347348 // Limit recursion depth to limit compile time in crazy cases.
348349 unsigned MaxLookup = MaxLookupSearchDepth;
383384 // If it's not a GEP, hand it off to SimplifyInstruction to see if it
384385 // can come up with something. This matches what GetUnderlyingObject does.
385386 if (const Instruction *I = dyn_cast(V))
386 // TODO: Get a DominatorTree and use it here (it is now available in
387 // this function, but this should be updated when GetUnderlyingObject
388 // is updated). TLI should be provided also.
387 // TODO: Get a DominatorTree and AssumptionCache and use them here
388 // (these are both now available in this function, but this should be
389 // updated when GetUnderlyingObject is updated). TLI should be
390 // provided also.
389391 if (const Value *Simplified =
390392 SimplifyInstruction(const_cast(I), DL)) {
391393 V = Simplified;
447449 APInt IndexScale(Width, 0), IndexOffset(Width, 0);
448450 bool NSW = true, NUW = true;
449451 Index = GetLinearExpression(Index, IndexScale, IndexOffset, ZExtBits,
450 SExtBits, DL, 0, DT, NSW, NUW);
452 SExtBits, DL, 0, AC, DT, NSW, NUW);
451453
452454 // The GEP index scale ("Scale") scales C1*V+C2, yielding (C1*V+C2)*Scale.
453455 // This gives us an aggregate computation of (C1*Scale)*V + C2*Scale.
10561058 const Value *UnderlyingV2) {
10571059 DecomposedGEP DecompGEP1, DecompGEP2;
10581060 bool GEP1MaxLookupReached =
1059 DecomposeGEPExpression(GEP1, DecompGEP1, DL, DT);
1061 DecomposeGEPExpression(GEP1, DecompGEP1, DL, &AC, DT);
10601062 bool GEP2MaxLookupReached =
1061 DecomposeGEPExpression(V2, DecompGEP2, DL, DT);
1063 DecomposeGEPExpression(V2, DecompGEP2, DL, &AC, DT);
10621064
10631065 int64_t GEP1BaseOffset = DecompGEP1.StructOffset + DecompGEP1.OtherOffset;
10641066 int64_t GEP2BaseOffset = DecompGEP2.StructOffset + DecompGEP2.OtherOffset;
12201222
12211223 bool SignKnownZero, SignKnownOne;
12221224 ComputeSignBit(const_cast(V), SignKnownZero, SignKnownOne, DL,
1223 0, nullptr, DT);
1225 0, &AC, nullptr, DT);
12241226
12251227 // Zero-extension widens the variable, and so forces the sign
12261228 // bit to zero.
12551257 return NoAlias;
12561258
12571259 if (constantOffsetHeuristic(DecompGEP1.VarIndices, V1Size, V2Size,
1258 GEP1BaseOffset, DT))
1260 GEP1BaseOffset, &AC, DT))
12591261 return NoAlias;
12601262 }
12611263
16571659
16581660 bool BasicAAResult::constantOffsetHeuristic(
16591661 const SmallVectorImpl &VarIndices, uint64_t V1Size,
1660 uint64_t V2Size, int64_t BaseOffset,
1662 uint64_t V2Size, int64_t BaseOffset, AssumptionCache *AC,
16611663 DominatorTree *DT) {
16621664 if (VarIndices.size() != 2 || V1Size == MemoryLocation::UnknownSize ||
16631665 V2Size == MemoryLocation::UnknownSize)
16801682 bool NSW = true, NUW = true;
16811683 unsigned V0ZExtBits = 0, V0SExtBits = 0, V1ZExtBits = 0, V1SExtBits = 0;
16821684 const Value *V0 = GetLinearExpression(Var0.V, V0Scale, V0Offset, V0ZExtBits,
1683 V0SExtBits, DL, 0, DT, NSW, NUW);
1685 V0SExtBits, DL, 0, AC, DT, NSW, NUW);
16841686 NSW = true;
16851687 NUW = true;
16861688 const Value *V1 = GetLinearExpression(Var1.V, V1Scale, V1Offset, V1ZExtBits,
1687 V1SExtBits, DL, 0, DT, NSW, NUW);
1689 V1SExtBits, DL, 0, AC, DT, NSW, NUW);
16881690
16891691 if (V0Scale != V1Scale || V0ZExtBits != V1ZExtBits ||
16901692 V0SExtBits != V1SExtBits || !isValueEqualInPotentialCycles(V0, V1))
17181720 BasicAAResult BasicAA::run(Function &F, FunctionAnalysisManager &AM) {
17191721 return BasicAAResult(F.getParent()->getDataLayout(),
17201722 AM.getResult(F),
1723 AM.getResult(F),
17211724 &AM.getResult(F),
17221725 AM.getCachedResult(F));
17231726 }
17311734
17321735 INITIALIZE_PASS_BEGIN(BasicAAWrapperPass, "basicaa",
17331736 "Basic Alias Analysis (stateless AA impl)", true, true)
1737 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
17341738 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
17351739 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
17361740 INITIALIZE_PASS_END(BasicAAWrapperPass, "basicaa",
17411745 }
17421746
17431747 bool BasicAAWrapperPass::runOnFunction(Function &F) {
1748 auto &ACT = getAnalysis();
17441749 auto &TLIWP = getAnalysis();
17451750 auto &DTWP = getAnalysis();
17461751 auto *LIWP = getAnalysisIfAvailable();
17471752
17481753 Result.reset(new BasicAAResult(F.getParent()->getDataLayout(), TLIWP.getTLI(),
1749 &DTWP.getDomTree(),
1754 ACT.getAssumptionCache(F), &DTWP.getDomTree(),
17501755 LIWP ? &LIWP->getLoopInfo() : nullptr));
17511756
17521757 return false;
17541759
17551760 void BasicAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
17561761 AU.setPreservesAll();
1762 AU.addRequired();
17571763 AU.addRequired();
17581764 AU.addRequired();
17591765 }
17611767 BasicAAResult llvm::createLegacyPMBasicAAResult(Pass &P, Function &F) {
17621768 return BasicAAResult(
17631769 F.getParent()->getDataLayout(),
1764 P.getAnalysis().getTLI());
1765 }
1770 P.getAnalysis().getTLI(),
1771 P.getAnalysis().getAssumptionCache(F));
1772 }
33 AliasAnalysisSummary.cpp
44 AliasSetTracker.cpp
55 Analysis.cpp
6 AssumptionCache.cpp
67 BasicAliasAnalysis.cpp
78 BlockFrequencyInfo.cpp
89 BlockFrequencyInfoImpl.cpp
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/Analysis/AssumptionCache.h"
1314 #include "llvm/Analysis/CodeMetrics.h"
1415 #include "llvm/Analysis/LoopInfo.h"
1516 #include "llvm/Analysis/TargetTransformInfo.h"
6970
7071 // Find all ephemeral values.
7172 void CodeMetrics::collectEphemeralValues(
72 const Loop *L, SmallPtrSetImpl &EphValues) {
73 const Loop *L, AssumptionCache *AC,
74 SmallPtrSetImpl &EphValues) {
7375 SmallPtrSet Visited;
7476 SmallVector Worklist;
7577
76 for (auto &B : L->blocks())
77 for (auto &I : *B)
78 if (auto *II = dyn_cast(&I))
79 if (II->getIntrinsicID() == Intrinsic::assume &&
80 EphValues.insert(II).second)
81 appendSpeculatableOperands(II, Visited, Worklist);
78 for (auto &AssumeVH : AC->assumptions()) {
79 if (!AssumeVH)
80 continue;
81 Instruction *I = cast(AssumeVH);
82
83 // Filter out call sites outside of the loop so we don't do a function's
84 // worth of work for each of its loops (and, in the common case, ephemeral
85 // values in the loop are likely due to @llvm.assume calls in the loop).
86 if (!L->contains(I->getParent()))
87 continue;
88
89 if (EphValues.insert(I).second)
90 appendSpeculatableOperands(I, Visited, Worklist);
91 }
8292
8393 completeEphemeralValues(Visited, Worklist, EphValues);
8494 }
8595
8696 void CodeMetrics::collectEphemeralValues(
87 const Function *F, SmallPtrSetImpl &EphValues) {
97 const Function *F, AssumptionCache *AC,
98 SmallPtrSetImpl &EphValues) {
8899 SmallPtrSet Visited;
89100 SmallVector Worklist;
90101
91 for (auto &B : *F)
92 for (auto &I : B)
93 if (auto *II = dyn_cast(&I))
94 if (II->getIntrinsicID() == Intrinsic::assume &&
95 EphValues.insert(II).second)
96 appendSpeculatableOperands(II, Visited, Worklist);
102 for (auto &AssumeVH : AC->assumptions()) {
103 if (!AssumeVH)
104 continue;
105 Instruction *I = cast(AssumeVH);
106 assert(I->getParent()->getParent() == F &&
107 "Found assumption for the wrong function!");
108
109 if (EphValues.insert(I).second)
110 appendSpeculatableOperands(I, Visited, Worklist);
111 }
97112
98113 completeEphemeralValues(Visited, Worklist, EphValues);
99114 }
2323 #include "llvm/ADT/SmallPtrSet.h"
2424 #include "llvm/ADT/SmallVector.h"
2525 #include "llvm/ADT/StringExtras.h"
26 #include "llvm/Analysis/AssumptionCache.h"
2627 #include "llvm/Analysis/ValueTracking.h"
2728 #include "llvm/IR/BasicBlock.h"
2829 #include "llvm/IR/CFG.h"
4344 char DemandedBitsWrapperPass::ID = 0;
4445 INITIALIZE_PASS_BEGIN(DemandedBitsWrapperPass, "demanded-bits",
4546 "Demanded bits analysis", false, false)
47 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
4648 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
4749 INITIALIZE_PASS_END(DemandedBitsWrapperPass, "demanded-bits",
4850 "Demanded bits analysis", false, false)
5355
5456 void DemandedBitsWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
5557 AU.setPreservesCFG();
58 AU.addRequired();
5659 AU.addRequired();
5760 AU.setPreservesAll();
5861 }
8487 KnownZero = APInt(BitWidth, 0);
8588 KnownOne = APInt(BitWidth, 0);
8689 computeKnownBits(const_cast(V1), KnownZero, KnownOne, DL, 0,
87 UserI, &DT);
90 &AC, UserI, &DT);
8891
8992 if (V2) {
9093 KnownZero2 = APInt(BitWidth, 0);
9194 KnownOne2 = APInt(BitWidth, 0);
9295 computeKnownBits(const_cast(V2), KnownZero2, KnownOne2, DL,
93 0, UserI, &DT);
96 0, &AC, UserI, &DT);
9497 }
9598 };
9699
244247 }
245248
246249 bool DemandedBitsWrapperPass::runOnFunction(Function &F) {
250 auto &AC = getAnalysis().getAssumptionCache(F);
247251 auto &DT = getAnalysis().getDomTree();
248 DB.emplace(F, DT);
252 DB.emplace(F, AC, DT);
249253 return false;
250254 }
251255
385389
386390 DemandedBits DemandedBitsAnalysis::run(Function &F,
387391 FunctionAnalysisManager &AM) {
392 auto &AC = AM.getResult(F);
388393 auto &DT = AM.getResult(F);
389 return DemandedBits(F, DT);
394 return DemandedBits(F, AC, DT);
390395 }
391396
392397 PreservedAnalyses DemandedBitsPrinterPass::run(Function &F,
1313
1414 #include "llvm/Analysis/IVUsers.h"
1515 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/Analysis/AssumptionCache.h"
1617 #include "llvm/Analysis/CodeMetrics.h"
1718 #include "llvm/Analysis/LoopPass.h"
1819 #include "llvm/Analysis/LoopPassManager.h"
3940 AM.getResult(L).getManager();
4041 Function *F = L.getHeader()->getParent();
4142
42 return IVUsers(&L, FAM.getCachedResult<LoopAnalysis>(*F),
43 return IVUsers(&L, FAM.getCachedResult<AssumptionAnalysis>(*F),
44 FAM.getCachedResult(*F),
4345 FAM.getCachedResult(*F),
4446 FAM.getCachedResult(*F));
4547 }
5254 char IVUsersWrapperPass::ID = 0;
5355 INITIALIZE_PASS_BEGIN(IVUsersWrapperPass, "iv-users",
5456 "Induction Variable Users", false, true)
57 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
5558 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
5659 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
5760 INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
259262 return IVUses.back();
260263 }
261264
262 IVUsers::IVUsers(Loop *L, LoopInfo *LI, DominatorTree *DT, ScalarEvolution *SE)
263 : L(L), LI(LI), DT(DT), SE(SE), IVUses() {
265 IVUsers::IVUsers(Loop *L, AssumptionCache *AC, LoopInfo *LI, DominatorTree *DT,
266 ScalarEvolution *SE)
267 : L(L), AC(AC), LI(LI), DT(DT), SE(SE), IVUses() {
264268 // Collect ephemeral values so that AddUsersIfInteresting skips them.
265269 EphValues.clear();
266 CodeMetrics::collectEphemeralValues(L, EphValues);
270 CodeMetrics::collectEphemeralValues(L, AC, EphValues);
267271
268272 // Find all uses of induction variables in this loop, and categorize
269273 // them by stride. Start by finding all of the PHI nodes in the header for
312316 }
313317
314318 void IVUsersWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
319 AU.addRequired();
315320 AU.addRequired();
316321 AU.addRequired();
317322 AU.addRequired();
319324 }
320325
321326 bool IVUsersWrapperPass::runOnLoop(Loop *L, LPPassManager &LPM) {
327 auto *AC = &getAnalysis().getAssumptionCache(
328 *L->getHeader()->getParent());
322329 auto *LI = &getAnalysis().getLoopInfo();
323330 auto *DT = &getAnalysis().getDomTree();
324331 auto *SE = &getAnalysis().getSE();
325332
326 IU.reset(new IVUsers(L, LI, DT, SE));
333 IU.reset(new IVUsers(L, AC, LI, DT, SE));
327334 return false;
328335 }
329336
1616 #include "llvm/ADT/SmallPtrSet.h"
1717 #include "llvm/ADT/SmallVector.h"
1818 #include "llvm/ADT/Statistic.h"
19 #include "llvm/Analysis/AssumptionCache.h"
1920 #include "llvm/Analysis/CodeMetrics.h"
2021 #include "llvm/Analysis/ConstantFolding.h"
2122 #include "llvm/Analysis/InstructionSimplify.h"
6667
6768 /// The TargetTransformInfo available for this compilation.
6869 const TargetTransformInfo &TTI;
70
71 /// Getter for the cache of @llvm.assume intrinsics.
72 std::function &GetAssumptionCache;
6973
7074 /// Profile summary information.
7175 ProfileSummaryInfo *PSI;
196200
197201 public:
198202 CallAnalyzer(const TargetTransformInfo &TTI,
203 std::function &GetAssumptionCache,
199204 ProfileSummaryInfo *PSI, Function &Callee, CallSite CSArg,
200205 const InlineParams &Params)
201 : TTI(TTI), PSI(PSI), F(Callee), CandidateCS(CSArg), Params(Params),
202 Threshold(Params.DefaultThreshold), Cost(0), IsCallerRecursive(false),
203 IsRecursiveCall(false), ExposesReturnsTwice(false),
204 HasDynamicAlloca(false), ContainsNoDuplicateCall(false),
205 HasReturn(false), HasIndirectBr(false), HasFrameEscape(false),
206 AllocatedSize(0), NumInstructions(0), NumVectorInstructions(0),
207 FiftyPercentVectorBonus(0), TenPercentVectorBonus(0), VectorBonus(0),
208 NumConstantArgs(0), NumConstantOffsetPtrArgs(0), NumAllocaArgs(0),
209 NumConstantPtrCmps(0), NumConstantPtrDiffs(0),
210 NumInstructionsSimplified(0), SROACostSavings(0),
211 SROACostSavingsLost(0) {}
206 : TTI(TTI), GetAssumptionCache(GetAssumptionCache), PSI(PSI), F(Callee),
207 CandidateCS(CSArg), Params(Params), Threshold(Params.DefaultThreshold),
208 Cost(0), IsCallerRecursive(false), IsRecursiveCall(false),
209 ExposesReturnsTwice(false), HasDynamicAlloca(false),
210 ContainsNoDuplicateCall(false), HasReturn(false), HasIndirectBr(false),
211 HasFrameEscape(false), AllocatedSize(0), NumInstructions(0),
212 NumVectorInstructions(0), FiftyPercentVectorBonus(0),
213 TenPercentVectorBonus(0), VectorBonus(0), NumConstantArgs(0),
214 NumConstantOffsetPtrArgs(0), NumAllocaArgs(0), NumConstantPtrCmps(0),
215 NumConstantPtrDiffs(0), NumInstructionsSimplified(0),
216 SROACostSavings(0), SROACostSavingsLost(0) {}
212217
213218 bool analyzeCall(CallSite CS);
214219
956961 // out. Pretend to inline the function, with a custom threshold.
957962 auto IndirectCallParams = Params;
958963 IndirectCallParams.DefaultThreshold = InlineConstants::IndirectCallThreshold;
959 CallAnalyzer CA(TTI, PSI, *F, CS, IndirectCallParams);
964 CallAnalyzer CA(TTI, GetAssumptionCache, PSI, *F, CS, IndirectCallParams);
960965 if (CA.analyzeCall(CS)) {
961966 // We were able to inline the indirect call! Subtract the cost from the
962967 // threshold to get the bonus we want to apply, but don't go below zero.
13121317 // the ephemeral values multiple times (and they're completely determined by
13131318 // the callee, so this is purely duplicate work).
13141319 SmallPtrSet EphValues;
1315 CodeMetrics::collectEphemeralValues(&F, EphValues);
1320 CodeMetrics::collectEphemeralValues(&F, &GetAssumptionCache(F), EphValues);
13161321
13171322 // The worklist of live basic blocks in the callee *after* inlining. We avoid
13181323 // adding basic blocks of the callee which can be proven to be dead for this
14451450
14461451 InlineCost llvm::getInlineCost(
14471452 CallSite CS, const InlineParams &Params, TargetTransformInfo &CalleeTTI,
1453 std::function &GetAssumptionCache,
14481454 ProfileSummaryInfo *PSI) {
1449 return getInlineCost(CS, CS.getCalledFunction(), Params, CalleeTTI, PSI);
1455 return getInlineCost(CS, CS.getCalledFunction(), Params, CalleeTTI,
1456 GetAssumptionCache, PSI);
14501457 }
14511458
14521459 InlineCost llvm::getInlineCost(
14531460 CallSite CS, Function *Callee, const InlineParams &Params,
1454 TargetTransformInfo &CalleeTTI, ProfileSummaryInfo *PSI) {
1461 TargetTransformInfo &CalleeTTI,
1462 std::function &GetAssumptionCache,
1463 ProfileSummaryInfo *PSI) {
14551464
14561465 // Cannot inline indirect calls.
14571466 if (!Callee)
14851494 DEBUG(llvm::dbgs() << " Analyzing call of " << Callee->getName()
14861495 << "...\n");
14871496
1488 CallAnalyzer CA(CalleeTTI, PSI, *Callee, CS, Params);
1497 CallAnalyzer CA(CalleeTTI, GetAssumptionCache, PSI, *Callee, CS, Params);
14891498 bool ShouldInline = CA.analyzeCall(CS);
14901499
14911500 DEBUG(CA.dump());
4949 const DataLayout &DL;
5050 const TargetLibraryInfo *TLI;
5151 const DominatorTree *DT;
52 AssumptionCache *AC;
5253 const Instruction *CxtI;
5354
5455 Query(const DataLayout &DL, const TargetLibraryInfo *tli,
55 const DominatorTree *dt, const Instruction *cxti = nullptr)
56 : DL(DL), TLI(tli), DT(dt), CxtI(cxti) {}
56 const DominatorTree *dt, AssumptionCache *ac = nullptr,
57 const Instruction *cxti = nullptr)
58 : DL(DL), TLI(tli), DT(dt), AC(ac), CxtI(cxti) {}
5759 };
5860 } // end anonymous namespace
5961
581583
582584 Value *llvm::SimplifyAddInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
583585 const DataLayout &DL, const TargetLibraryInfo *TLI,
584 const DominatorTree *DT, const Instruction *CxtI) {
585 return ::SimplifyAddInst(Op0, Op1, isNSW, isNUW, Query(DL, TLI, DT, CxtI),
586 const DominatorTree *DT, AssumptionCache *AC,
587 const Instruction *CxtI) {
588 return ::SimplifyAddInst(Op0, Op1, isNSW, isNUW, Query(DL, TLI, DT, AC, CxtI),
586589 RecursionLimit);
587590 }
588591
687690 unsigned BitWidth = Op1->getType()->getScalarSizeInBits();
688691 APInt KnownZero(BitWidth, 0);
689692 APInt KnownOne(BitWidth, 0);
690 computeKnownBits(Op1, KnownZero, KnownOne, Q.DL, 0, Q.CxtI, Q.DT);
693 computeKnownBits(Op1, KnownZero, KnownOne, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
691694 if (KnownZero == ~APInt::getSignBit(BitWidth)) {
692695 // Op1 is either 0 or the minimum signed value. If the sub is NSW, then
693696 // Op1 must be 0 because negating the minimum signed value is undefined.
793796
794797 Value *llvm::SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
795798 const DataLayout &DL, const TargetLibraryInfo *TLI,
796 const DominatorTree *DT, const Instruction *CxtI) {
797 return ::SimplifySubInst(Op0, Op1, isNSW, isNUW, Query(DL, TLI, DT, CxtI),
799 const DominatorTree *DT, AssumptionCache *AC,
800 const Instruction *CxtI) {
801 return ::SimplifySubInst(Op0, Op1, isNSW, isNUW, Query(DL, TLI, DT, AC, CxtI),
798802 RecursionLimit);
799803 }
800804
961965 Value *llvm::SimplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
962966 const DataLayout &DL,
963967 const TargetLibraryInfo *TLI,
964 const DominatorTree *DT,
968 const DominatorTree *DT, AssumptionCache *AC,
965969 const Instruction *CxtI) {
966 return ::SimplifyFAddInst(Op0, Op1, FMF, Query(DL, TLI, DT, CxtI),
970 return ::SimplifyFAddInst(Op0, Op1, FMF, Query(DL, TLI, DT, AC, CxtI),
967971 RecursionLimit);
968972 }
969973
970974 Value *llvm::SimplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
971975 const DataLayout &DL,
972976 const TargetLibraryInfo *TLI,
973 const DominatorTree *DT,
977 const DominatorTree *DT, AssumptionCache *AC,
974978 const Instruction *CxtI) {
975 return ::SimplifyFSubInst(Op0, Op1, FMF, Query(DL, TLI, DT, CxtI),
979 return ::SimplifyFSubInst(Op0, Op1, FMF, Query(DL, TLI, DT, AC, CxtI),
976980 RecursionLimit);
977981 }
978982
979983 Value *llvm::SimplifyFMulInst(Value *Op0, Value *Op1, FastMathFlags FMF,
980984 const DataLayout &DL,
981985 const TargetLibraryInfo *TLI,
982 const DominatorTree *DT,
986 const DominatorTree *DT, AssumptionCache *AC,
983987 const Instruction *CxtI) {
984 return ::SimplifyFMulInst(Op0, Op1, FMF, Query(DL, TLI, DT, CxtI),
988 return ::SimplifyFMulInst(Op0, Op1, FMF, Query(DL, TLI, DT, AC, CxtI),
985989 RecursionLimit);
986990 }
987991
988992 Value *llvm::SimplifyMulInst(Value *Op0, Value *Op1, const DataLayout &DL,
989993 const TargetLibraryInfo *TLI,
990 const DominatorTree *DT,
994 const DominatorTree *DT, AssumptionCache *AC,
991995 const Instruction *CxtI) {
992 return ::SimplifyMulInst(Op0, Op1, Query(DL, TLI, DT, CxtI),
996 return ::SimplifyMulInst(Op0, Op1, Query(DL, TLI, DT, AC, CxtI),
993997 RecursionLimit);
994998 }
995999
10881092
10891093 Value *llvm::SimplifySDivInst(Value *Op0, Value *Op1, const DataLayout &DL,
10901094 const TargetLibraryInfo *TLI,
1091 const DominatorTree *DT,
1095 const DominatorTree *DT, AssumptionCache *AC,
10921096 const Instruction *CxtI) {
1093 return ::SimplifySDivInst(Op0, Op1, Query(DL, TLI, DT, CxtI),
1097 return ::SimplifySDivInst(Op0, Op1, Query(DL, TLI, DT, AC, CxtI),
10941098 RecursionLimit);
10951099 }
10961100
11061110
11071111 Value *llvm::SimplifyUDivInst(Value *Op0, Value *Op1, const DataLayout &DL,
11081112 const TargetLibraryInfo *TLI,
1109 const DominatorTree *DT,
1113 const DominatorTree *DT, AssumptionCache *AC,
11101114 const Instruction *CxtI) {
1111 return ::SimplifyUDivInst(Op0, Op1, Query(DL, TLI, DT, CxtI),
1115 return ::SimplifyUDivInst(Op0, Op1, Query(DL, TLI, DT, AC, CxtI),
11121116 RecursionLimit);
11131117 }
11141118
11531157 Value *llvm::SimplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF,
11541158 const DataLayout &DL,
11551159 const TargetLibraryInfo *TLI,
1156 const DominatorTree *DT,
1160 const DominatorTree *DT, AssumptionCache *AC,
11571161 const Instruction *CxtI) {
1158 return ::SimplifyFDivInst(Op0, Op1, FMF, Query(DL, TLI, DT, CxtI),
1162 return ::SimplifyFDivInst(Op0, Op1, FMF, Query(DL, TLI, DT, AC, CxtI),
11591163 RecursionLimit);
11601164 }
11611165
12291233
12301234 Value *llvm::SimplifySRemInst(Value *Op0, Value *Op1, const DataLayout &DL,
12311235 const TargetLibraryInfo *TLI,
1232 const DominatorTree *DT,
1236 const DominatorTree *DT, AssumptionCache *AC,
12331237 const Instruction *CxtI) {
1234 return ::SimplifySRemInst(Op0, Op1, Query(DL, TLI, DT, CxtI),
1238 return ::SimplifySRemInst(Op0, Op1, Query(DL, TLI, DT, AC, CxtI),
12351239 RecursionLimit);
12361240 }
12371241
12471251
12481252 Value *llvm::SimplifyURemInst(Value *Op0, Value *Op1, const DataLayout &DL,
12491253 const TargetLibraryInfo *TLI,
1250 const DominatorTree *DT,
1254 const DominatorTree *DT, AssumptionCache *AC,
12511255 const Instruction *CxtI) {
1252 return ::SimplifyURemInst(Op0, Op1, Query(DL, TLI, DT, CxtI),
1256 return ::SimplifyURemInst(Op0, Op1, Query(DL, TLI, DT, AC, CxtI),
12531257 RecursionLimit);
12541258 }
12551259
12751279 Value *llvm::SimplifyFRemInst(Value *Op0, Value *Op1, FastMathFlags FMF,
12761280 const DataLayout &DL,
12771281 const TargetLibraryInfo *TLI,
1278 const DominatorTree *DT,
1282 const DominatorTree *DT, AssumptionCache *AC,
12791283 const Instruction *CxtI) {
1280 return ::SimplifyFRemInst(Op0, Op1, FMF, Query(DL, TLI, DT, CxtI),
1284 return ::SimplifyFRemInst(Op0, Op1, FMF, Query(DL, TLI, DT, AC, CxtI),
12811285 RecursionLimit);
12821286 }
12831287
13451349 unsigned BitWidth = Op1->getType()->getScalarSizeInBits();
13461350 APInt KnownZero(BitWidth, 0);
13471351 APInt KnownOne(BitWidth, 0);
1348 computeKnownBits(Op1, KnownZero, KnownOne, Q.DL, 0, Q.CxtI, Q.DT);
1352 computeKnownBits(Op1, KnownZero, KnownOne, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
13491353 if (KnownOne.getLimitedValue() >= BitWidth)
13501354 return UndefValue::get(Op0->getType());
13511355
13811385 unsigned BitWidth = Op0->getType()->getScalarSizeInBits();
13821386 APInt Op0KnownZero(BitWidth, 0);
13831387 APInt Op0KnownOne(BitWidth, 0);
1384 computeKnownBits(Op0, Op0KnownZero, Op0KnownOne, Q.DL, /*Depth=*/0, Q.CxtI,
1385 Q.DT);
1388 computeKnownBits(Op0, Op0KnownZero, Op0KnownOne, Q.DL, /*Depth=*/0, Q.AC,
1389 Q.CxtI, Q.DT);
13861390 if (Op0KnownOne[0])
13871391 return Op0;
13881392 }
14111415
14121416 Value *llvm::SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW,
14131417 const DataLayout &DL, const TargetLibraryInfo *TLI,
1414 const DominatorTree *DT,
1418 const DominatorTree *DT, AssumptionCache *AC,
14151419 const Instruction *CxtI) {
1416 return ::SimplifyShlInst(Op0, Op1, isNSW, isNUW, Query(DL, TLI, DT, CxtI),
1420 return ::SimplifyShlInst(Op0, Op1, isNSW, isNUW, Query(DL, TLI, DT, AC, CxtI),
14171421 RecursionLimit);
14181422 }
14191423
14361440 Value *llvm::SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact,
14371441 const DataLayout &DL,
14381442 const TargetLibraryInfo *TLI,
1439 const DominatorTree *DT,
1443 const DominatorTree *DT, AssumptionCache *AC,
14401444 const Instruction *CxtI) {
1441 return ::SimplifyLShrInst(Op0, Op1, isExact, Query(DL, TLI, DT, CxtI),
1445 return ::SimplifyLShrInst(Op0, Op1, isExact, Query(DL, TLI, DT, AC, CxtI),
14421446 RecursionLimit);
14431447 }
14441448
14601464 return X;
14611465
14621466 // Arithmetic shifting an all-sign-bit value is a no-op.
1463 unsigned NumSignBits = ComputeNumSignBits(Op0, Q.DL, 0, Q.CxtI, Q.DT);
1467 unsigned NumSignBits = ComputeNumSignBits(Op0, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
14641468 if (NumSignBits == Op0->getType()->getScalarSizeInBits())
14651469 return Op0;
14661470
14701474 Value *llvm::SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact,
14711475 const DataLayout &DL,
14721476 const TargetLibraryInfo *TLI,
1473 const DominatorTree *DT,
1477 const DominatorTree *DT, AssumptionCache *AC,
14741478 const Instruction *CxtI) {
1475 return ::SimplifyAShrInst(Op0, Op1, isExact, Query(DL, TLI, DT, CxtI),
1479 return ::SimplifyAShrInst(Op0, Op1, isExact, Query(DL, TLI, DT, AC, CxtI),
14761480 RecursionLimit);
14771481 }
14781482
16541658 // A & (-A) = A if A is a power of two or zero.
16551659 if (match(Op0, m_Neg(m_Specific(Op1))) ||
16561660 match(Op1, m_Neg(m_Specific(Op0)))) {
1657 if (isKnownToBeAPowerOfTwo(Op0, Q.DL, /*OrZero*/ true, 0, Q.CxtI, Q.DT))
1661 if (isKnownToBeAPowerOfTwo(Op0, Q.DL, /*OrZero*/ true, 0, Q.AC, Q.CxtI,
1662 Q.DT))
16581663 return Op0;
1659 if (isKnownToBeAPowerOfTwo(Op1, Q.DL, /*OrZero*/ true, 0, Q.CxtI, Q.DT))
1664 if (isKnownToBeAPowerOfTwo(Op1, Q.DL, /*OrZero*/ true, 0, Q.AC, Q.CxtI,
1665 Q.DT))
16601666 return Op1;
16611667 }
16621668
17211727
17221728 Value *llvm::SimplifyAndInst(Value *Op0, Value *Op1, const DataLayout &DL,
17231729 const TargetLibraryInfo *TLI,
1724 const DominatorTree *DT,
1730 const DominatorTree *DT, AssumptionCache *AC,
17251731 const Instruction *CxtI) {
1726 return ::SimplifyAndInst(Op0, Op1, Query(DL, TLI, DT, CxtI),
1732 return ::SimplifyAndInst(Op0, Op1, Query(DL, TLI, DT, AC, CxtI),
17271733 RecursionLimit);
17281734 }
17291735
19031909 match(A, m_Add(m_Value(V1), m_Value(V2)))) {
19041910 // Add commutes, try both ways.
19051911 if (V1 == B &&
1906 MaskedValueIsZero(V2, C2->getValue(), Q.DL, 0, Q.CxtI, Q.DT))
1912 MaskedValueIsZero(V2, C2->getValue(), Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
19071913 return A;
19081914 if (V2 == B &&
1909 MaskedValueIsZero(V1, C2->getValue(), Q.DL, 0, Q.CxtI, Q.DT))
1915 MaskedValueIsZero(V1, C2->getValue(), Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
19101916 return A;
19111917 }
19121918 // Or commutes, try both ways.
19141920 match(B, m_Add(m_Value(V1), m_Value(V2)))) {
19151921 // Add commutes, try both ways.
19161922 if (V1 == A &&
1917 MaskedValueIsZero(V2, C1->getValue(), Q.DL, 0, Q.CxtI, Q.DT))
1923 MaskedValueIsZero(V2, C1->getValue(), Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
19181924 return B;
19191925 if (V2 == A &&
1920 MaskedValueIsZero(V1, C1->getValue(), Q.DL, 0, Q.CxtI, Q.DT))
1926 MaskedValueIsZero(V1, C1->getValue(), Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
19211927 return B;
19221928 }
19231929 }
19341940
19351941 Value *llvm::SimplifyOrInst(Value *Op0, Value *Op1, const DataLayout &DL,
19361942 const TargetLibraryInfo *TLI,
1937 const DominatorTree *DT,
1943 const DominatorTree *DT, AssumptionCache *AC,
19381944 const Instruction *CxtI) {
1939 return ::SimplifyOrInst(Op0, Op1, Query(DL, TLI, DT, CxtI),
1945 return ::SimplifyOrInst(Op0, Op1, Query(DL, TLI, DT, AC, CxtI),
19401946 RecursionLimit);
19411947 }
19421948
19881994
19891995 Value *llvm::SimplifyXorInst(Value *Op0, Value *Op1, const DataLayout &DL,
19901996 const TargetLibraryInfo *TLI,
1991 const DominatorTree *DT,
1997 const DominatorTree *DT, AssumptionCache *AC,
19921998 const Instruction *CxtI) {
1993 return ::SimplifyXorInst(Op0, Op1, Query(DL, TLI, DT, CxtI),
1999 return ::SimplifyXorInst(Op0, Op1, Query(DL, TLI, DT, AC, CxtI),
19942000 RecursionLimit);
19952001 }
19962002
23052311 return getTrue(ITy);
23062312 case ICmpInst::ICMP_EQ:
23072313 case ICmpInst::ICMP_ULE:
2308 if (isKnownNonZero(LHS, Q.DL, 0, Q.CxtI, Q.DT))
2314 if (isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
23092315 return getFalse(ITy);
23102316 break;
23112317 case ICmpInst::ICMP_NE:
23122318 case ICmpInst::ICMP_UGT:
2313 if (isKnownNonZero(LHS, Q.DL, 0, Q.CxtI, Q.DT))
2319 if (isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
23142320 return getTrue(ITy);
23152321 break;
23162322 case ICmpInst::ICMP_SLT:
2317 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.CxtI,
2318 Q.DT);
2323 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC,
2324 Q.CxtI, Q.DT);
23192325 if (LHSKnownNegative)
23202326 return getTrue(ITy);
23212327 if (LHSKnownNonNegative)
23222328 return getFalse(ITy);
23232329 break;
23242330 case ICmpInst::ICMP_SLE:
2325 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.CxtI,
2326 Q.DT);
2331 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC,
2332 Q.CxtI, Q.DT);
23272333 if (LHSKnownNegative)
23282334 return getTrue(ITy);
2329 if (LHSKnownNonNegative && isKnownNonZero(LHS, Q.DL, 0, Q.CxtI, Q.DT))
2335 if (LHSKnownNonNegative && isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
23302336 return getFalse(ITy);
23312337 break;
23322338 case ICmpInst::ICMP_SGE:
2333 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.CxtI,
2334 Q.DT);
2339 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC,
2340 Q.CxtI, Q.DT);
23352341 if (LHSKnownNegative)
23362342 return getFalse(ITy);
23372343 if (LHSKnownNonNegative)
23382344 return getTrue(ITy);
23392345 break;
23402346 case ICmpInst::ICMP_SGT:
2341 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.CxtI,
2342 Q.DT);
2347 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC,
2348 Q.CxtI, Q.DT);
23432349 if (LHSKnownNegative)
23442350 return getFalse(ITy);
2345 if (LHSKnownNonNegative && isKnownNonZero(LHS, Q.DL, 0, Q.CxtI, Q.DT))
2351 if (LHSKnownNonNegative && isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT))
23462352 return getTrue(ITy);
23472353 break;
23482354 }
25732579 bool RHSKnownNonNegative, RHSKnownNegative;
25742580 bool YKnownNonNegative, YKnownNegative;
25752581 ComputeSignBit(RHS, RHSKnownNonNegative, RHSKnownNegative, Q.DL, 0,
2582 Q.AC, Q.CxtI, Q.DT);
2583 ComputeSignBit(Y, YKnownNonNegative, YKnownNegative, Q.DL, 0, Q.AC,
25762584 Q.CxtI, Q.DT);
2577 ComputeSignBit(Y, YKnownNonNegative, YKnownNegative, Q.DL, 0, Q.CxtI,
2578 Q.DT);
25792585 if (RHSKnownNonNegative && YKnownNegative)
25802586 return Pred == ICmpInst::ICMP_SLT ? getTrue(ITy) : getFalse(ITy);
25812587 if (RHSKnownNegative || YKnownNonNegative)
25932599 bool LHSKnownNonNegative, LHSKnownNegative;
25942600 bool YKnownNonNegative, YKnownNegative;
25952601 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0,
2602 Q.AC, Q.CxtI, Q.DT);
2603 ComputeSignBit(Y, YKnownNonNegative, YKnownNegative, Q.DL, 0, Q.AC,
25962604 Q.CxtI, Q.DT);
2597 ComputeSignBit(Y, YKnownNonNegative, YKnownNegative, Q.DL, 0, Q.CxtI,
2598 Q.DT);
25992605 if (LHSKnownNonNegative && YKnownNegative)
26002606 return Pred == ICmpInst::ICMP_SGT ? getTrue(ITy) : getFalse(ITy);
26012607 if (LHSKnownNegative || YKnownNonNegative)
26512657 break;
26522658 case ICmpInst::ICMP_SGT:
26532659 case ICmpInst::ICMP_SGE:
2654 ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.CxtI,
2655 Q.DT);
2660 ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC,
2661 Q.CxtI, Q.DT);
26562662 if (!KnownNonNegative)
26572663 break;
26582664 LLVM_FALLTHROUGH;
26622668 return getFalse(ITy);
26632669 case ICmpInst::ICMP_SLT:
26642670 case ICmpInst::ICMP_SLE:
2665 ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.CxtI,
2666 Q.DT);
2671 ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC,
2672 Q.CxtI, Q.DT);
26672673 if (!KnownNonNegative)
26682674 break;
26692675 LLVM_FALLTHROUGH;
26822688 break;
26832689 case ICmpInst::ICMP_SGT:
26842690 case ICmpInst::ICMP_SGE:
2685 ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.CxtI,
2686 Q.DT);
2691 ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC,
2692 Q.CxtI, Q.DT);
26872693 if (!KnownNonNegative)
26882694 break;
26892695 LLVM_FALLTHROUGH;
26932699 return getTrue(ITy);
26942700 case ICmpInst::ICMP_SLT:
26952701 case ICmpInst::ICMP_SLE:
2696 ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.CxtI,
2697 Q.DT);
2702 ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC,
2703 Q.CxtI, Q.DT);
26982704 if (!KnownNonNegative)
26992705 break;
27002706 LLVM_FALLTHROUGH;
32193225
32203226 // icmp eq|ne X, Y -> false|true if X != Y
32213227 if ((Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE) &&
3222 isKnownNonEqual(LHS, RHS, Q.DL, Q.CxtI, Q.DT)) {
3228 isKnownNonEqual(LHS, RHS, Q.DL, Q.AC, Q.CxtI, Q.DT)) {
32233229 LLVMContext &Ctx = LHS->getType()->getContext();
32243230 return Pred == ICmpInst::ICMP_NE ?
32253231 ConstantInt::getTrue(Ctx) : ConstantInt::getFalse(Ctx);
32783284 unsigned BitWidth = RHSVal->getBitWidth();
32793285 APInt LHSKnownZero(BitWidth, 0);
32803286 APInt LHSKnownOne(BitWidth, 0);
3281 computeKnownBits(LHS, LHSKnownZero, LHSKnownOne, Q.DL, /*Depth=*/0,
3287 computeKnownBits(LHS, LHSKnownZero, LHSKnownOne, Q.DL, /*Depth=*/0, Q.AC,
32823288 Q.CxtI, Q.DT);
32833289 if (((LHSKnownZero & *RHSVal) != 0) || ((LHSKnownOne & ~(*RHSVal)) != 0))
32843290 return Pred == ICmpInst::ICMP_EQ ? ConstantInt::getFalse(ITy)
33043310 Value *llvm::SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
33053311 const DataLayout &DL,
33063312 const TargetLibraryInfo *TLI,
3307 const DominatorTree *DT,
3313 const DominatorTree *DT, AssumptionCache *AC,
33083314 const Instruction *CxtI) {
3309 return ::SimplifyICmpInst(Predicate, LHS, RHS, Query(DL, TLI, DT, CxtI),
3315 return ::SimplifyICmpInst(Predicate, LHS, RHS, Query(DL, TLI, DT, AC, CxtI),
33103316 RecursionLimit);
33113317 }
33123318
34373443 Value *llvm::SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
34383444 FastMathFlags FMF, const DataLayout &DL,
34393445 const TargetLibraryInfo *TLI,
3440 const DominatorTree *DT,
3446 const DominatorTree *DT, AssumptionCache *AC,
34413447 const Instruction *CxtI) {
34423448 return ::SimplifyFCmpInst(Predicate, LHS, RHS, FMF,
3443 Query(DL, TLI, DT, CxtI), RecursionLimit);
3449 Query(DL, TLI, DT, AC, CxtI), RecursionLimit);
34443450 }
34453451
34463452 /// See if V simplifies when its operand Op is replaced with RepOp.
37073713 Value *llvm::SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
37083714 const DataLayout &DL,
37093715 const TargetLibraryInfo *TLI,
3710 const DominatorTree *DT,
3716 const DominatorTree *DT, AssumptionCache *AC,
37113717 const Instruction *CxtI) {
37123718 return ::SimplifySelectInst(Cond, TrueVal, FalseVal,
3713 Query(DL, TLI, DT, CxtI), RecursionLimit);
3719 Query(DL, TLI, DT, AC, CxtI), RecursionLimit);
37143720 }
37153721
37163722 /// Given operands for an GetElementPtrInst, see if we can fold the result.
38263832 Value *llvm::SimplifyGEPInst(Type *SrcTy, ArrayRef Ops,
38273833 const DataLayout &DL,
38283834 const TargetLibraryInfo *TLI,
3829 const DominatorTree *DT,
3835 const DominatorTree *DT, AssumptionCache *AC,
38303836 const Instruction *CxtI) {
38313837 return ::SimplifyGEPInst(SrcTy, Ops,
3832 Query(DL, TLI, DT, CxtI), RecursionLimit);
3838 Query(DL, TLI, DT, AC, CxtI), RecursionLimit);
38333839 }
38343840
38353841 /// Given operands for an InsertValueInst, see if we can fold the result.
38633869
38643870 Value *llvm::SimplifyInsertValueInst(
38653871 Value *Agg, Value *Val, ArrayRef Idxs, const DataLayout &DL,
3866 const TargetLibraryInfo *TLI, const DominatorTree *DT,
3872 const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionCache *AC,
38673873 const Instruction *CxtI) {
3868 return ::SimplifyInsertValueInst(Agg, Val, Idxs, Query(DL, TLI, DT, CxtI),
3874 return ::SimplifyInsertValueInst(Agg, Val, Idxs, Query(DL, TLI, DT, AC, CxtI),
38693875 RecursionLimit);
38703876 }
38713877
38983904 const DataLayout &DL,
38993905 const TargetLibraryInfo *TLI,
39003906 const DominatorTree *DT,
3907 AssumptionCache *AC,
39013908 const Instruction *CxtI) {
3902 return ::SimplifyExtractValueInst(Agg, Idxs, Query(DL, TLI, DT, CxtI),
3909 return ::SimplifyExtractValueInst(Agg, Idxs, Query(DL, TLI, DT, AC, CxtI),
39033910 RecursionLimit);
39043911 }
39053912
39303937
39313938 Value *llvm::SimplifyExtractElementInst(
39323939 Value *Vec, Value *Idx, const DataLayout &DL, const TargetLibraryInfo *TLI,
3933 const DominatorTree *DT, const Instruction *CxtI) {
3934 return ::SimplifyExtractElementInst(Vec, Idx, Query(DL, TLI, DT, CxtI),
3940 const DominatorTree *DT, AssumptionCache *AC, const Instruction *CxtI) {
3941 return ::SimplifyExtractElementInst(Vec, Idx, Query(DL, TLI, DT, AC, CxtI),
39353942 RecursionLimit);
39363943 }
39373944
40054012 Value *llvm::SimplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty,
40064013 const DataLayout &DL,
40074014 const TargetLibraryInfo *TLI,
4008 const DominatorTree *DT,
4015 const DominatorTree *DT, AssumptionCache *AC,
40094016 const Instruction *CxtI) {
4010 return ::SimplifyCastInst(CastOpc, Op, Ty, Query(DL, TLI, DT, CxtI),
4017 return ::SimplifyCastInst(CastOpc, Op, Ty, Query(DL, TLI, DT, AC, CxtI),
40114018 RecursionLimit);
40124019 }
40134020
41004107
41014108 Value *llvm::SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
41024109 const DataLayout &DL, const TargetLibraryInfo *TLI,
4103 const DominatorTree *DT,
4110 const DominatorTree *DT, AssumptionCache *AC,
41044111 const Instruction *CxtI) {
4105 return ::SimplifyBinOp(Opcode, LHS, RHS, Query(DL, TLI, DT, CxtI),
4112 return ::SimplifyBinOp(Opcode, LHS, RHS, Query(DL, TLI, DT, AC, CxtI),
41064113 RecursionLimit);
41074114 }
41084115
41094116 Value *llvm::SimplifyFPBinOp(unsigned Opcode, Value *LHS, Value *RHS,
41104117 const FastMathFlags &FMF, const DataLayout &DL,
41114118 const TargetLibraryInfo *TLI,
4112 const DominatorTree *DT,
4119 const DominatorTree *DT, AssumptionCache *AC,
41134120 const Instruction *CxtI) {
4114 return ::SimplifyFPBinOp(Opcode, LHS, RHS, FMF, Query(DL, TLI, DT, CxtI),
4121 return ::SimplifyFPBinOp(Opcode, LHS, RHS, FMF, Query(DL, TLI, DT, AC, CxtI),
41154122 RecursionLimit);
41164123 }
41174124
41254132
41264133 Value *llvm::SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
41274134 const DataLayout &DL, const TargetLibraryInfo *TLI,
4128 const DominatorTree *DT,
4135 const DominatorTree *DT, AssumptionCache *AC,
41294136 const Instruction *CxtI) {
4130 return ::SimplifyCmpInst(Predicate, LHS, RHS, Query(DL, TLI, DT, CxtI),
4137 return ::SimplifyCmpInst(Predicate, LHS, RHS, Query(DL, TLI, DT, AC, CxtI),
41314138 RecursionLimit);
41324139 }
41334140
43274334 Value *llvm::SimplifyCall(Value *V, User::op_iterator ArgBegin,
43284335 User::op_iterator ArgEnd, const DataLayout &DL,
43294336 const TargetLibraryInfo *TLI, const DominatorTree *DT,
4330 const Instruction *CxtI) {
4331 return ::SimplifyCall(V, ArgBegin, ArgEnd, Query(DL, TLI, DT, CxtI),
4337 AssumptionCache *AC, const Instruction *CxtI) {
4338 return ::SimplifyCall(V, ArgBegin, ArgEnd, Query(DL, TLI, DT, AC, CxtI),
43324339 RecursionLimit);
43334340 }
43344341
43354342 Value *llvm::SimplifyCall(Value *V, ArrayRef Args,
43364343 const DataLayout &DL, const TargetLibraryInfo *TLI,
4337 const DominatorTree *DT,
4344 const DominatorTree *DT, AssumptionCache *AC,
43384345 const Instruction *CxtI) {
43394346 return ::SimplifyCall(V, Args.begin(), Args.end(),
4340 Query(DL, TLI, DT, CxtI), RecursionLimit);
4347 Query(DL, TLI, DT, AC, CxtI), RecursionLimit);
43414348 }
43424349
43434350 /// See if we can compute a simplified version of this instruction.
43444351 /// If not, this returns null.
43454352 Value *llvm::SimplifyInstruction(Instruction *I, const DataLayout &DL,
43464353 const TargetLibraryInfo *TLI,
4347 const DominatorTree *DT) {
4354 const DominatorTree *DT, AssumptionCache *AC) {
43484355 Value *Result;
43494356
43504357 switch (I->getOpcode()) {
43534360 break;
43544361 case Instruction::FAdd:
43554362 Result = SimplifyFAddInst(I->getOperand(0), I->getOperand(1),
4356 I->getFastMathFlags(), DL, TLI, DT, I);
4363 I->getFastMathFlags(), DL, TLI, DT, AC, I);
43574364 break;
43584365 case Instruction::Add:
43594366 Result = SimplifyAddInst(I->getOperand(0), I->getOperand(1),
43604367 cast(I)->hasNoSignedWrap(),
43614368 cast(I)->hasNoUnsignedWrap(), DL,
4362 TLI, DT, I);
4369 TLI, DT, AC, I);
43634370 break;
43644371 case Instruction::FSub:
43654372 Result = SimplifyFSubInst(I->getOperand(0), I->getOperand(1),
4366 I->getFastMathFlags(), DL, TLI, DT, I);
4373 I->getFastMathFlags(), DL, TLI, DT, AC, I);
43674374 break;
43684375 case Instruction::Sub:
43694376 Result = SimplifySubInst(I->getOperand(0), I->getOperand(1),
43704377 cast(I)->hasNoSignedWrap(),
43714378 cast(I)->hasNoUnsignedWrap(), DL,
4372 TLI, DT, I);
4379 TLI, DT, AC, I);
43734380 break;
43744381 case Instruction::FMul:
43754382 Result = SimplifyFMulInst(I->getOperand(0), I->getOperand(1),
4376 I->getFastMathFlags(), DL, TLI, DT, I);
4383 I->getFastMathFlags(), DL, TLI, DT, AC, I);
43774384 break;
43784385 case Instruction::Mul:
43794386 Result =
4380 SimplifyMulInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT, I);
4387 SimplifyMulInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT, AC, I);
43814388 break;
43824389 case Instruction::SDiv:
43834390 Result = SimplifySDivInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT,
4384 I);
4391 AC, I);
43854392 break;
43864393 case Instruction::UDiv:
43874394 Result = SimplifyUDivInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT,
4388 I);
4395 AC, I);
43894396 break;
43904397 case Instruction::FDiv:
43914398 Result = SimplifyFDivInst(I->getOperand(0), I->getOperand(1),
4392 I->getFastMathFlags(), DL, TLI, DT, I);
4399 I->getFastMathFlags(), DL, TLI, DT, AC, I);
43934400 break;
43944401 case Instruction::SRem:
43954402 Result = SimplifySRemInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT,
4396 I);
4403 AC, I);
43974404 break;
43984405 case Instruction::URem:
43994406 Result = SimplifyURemInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT,
4400 I);
4407 AC, I);
44014408 break;
44024409 case Instruction::FRem:
44034410 Result = SimplifyFRemInst(I->getOperand(0), I->getOperand(1),
4404 I->getFastMathFlags(), DL, TLI, DT, I);
4411 I->getFastMathFlags(), DL, TLI, DT, AC, I);
44054412 break;
44064413 case Instruction::Shl:
44074414 Result = SimplifyShlInst(I->getOperand(0), I->getOperand(1),
44084415 cast(I)->hasNoSignedWrap(),
44094416 cast(I)->hasNoUnsignedWrap(), DL,
4410 TLI, DT, I);
4417 TLI, DT, AC, I);
44114418 break;
44124419 case Instruction::LShr:
44134420 Result = SimplifyLShrInst(I->getOperand(0), I->getOperand(1),
44144421 cast(I)->isExact(), DL, TLI, DT,
4415 I);
4422 AC, I);
44164423 break;
44174424 case Instruction::AShr:
44184425 Result = SimplifyAShrInst(I->getOperand(0), I->getOperand(1),
44194426 cast(I)->isExact(), DL, TLI, DT,
4420 I);
4427 AC, I);
44214428 break;
44224429 case Instruction::And:
44234430 Result =
4424 SimplifyAndInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT, I);
4431 SimplifyAndInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT, AC, I);
44254432 break;
44264433 case Instruction::Or:
44274434 Result =
4428 SimplifyOrInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT, I);
4435 SimplifyOrInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT, AC, I);
44294436 break;
44304437 case Instruction::Xor:
44314438 Result =
4432 SimplifyXorInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT, I);
4439 SimplifyXorInst(I->getOperand(0), I->getOperand(1), DL, TLI, DT, AC, I);
44334440 break;
44344441 case Instruction::ICmp:
44354442 Result =
44364443 SimplifyICmpInst(cast(I)->getPredicate(), I->getOperand(0),
4437 I->getOperand(1), DL, TLI, DT, I);
4444 I->getOperand(1), DL, TLI, DT, AC, I);
44384445 break;
44394446 case Instruction::FCmp:
44404447 Result = SimplifyFCmpInst(cast(I)->getPredicate(),
44414448 I->getOperand(0), I->getOperand(1),
4442 I->getFastMathFlags(), DL, TLI, DT, I);
4449 I->getFastMathFlags(), DL, TLI, DT, AC, I);
44434450 break;
44444451 case Instruction::Select:
44454452 Result = SimplifySelectInst(I->getOperand(0), I->getOperand(1),
4446 I->getOperand(2), DL, TLI, DT, I);
4453 I->getOperand(2), DL, TLI, DT, AC, I);
44474454 break;
44484455 case Instruction::GetElementPtr: {
44494456 SmallVector Ops(I->op_begin(), I->op_end());
44504457 Result = SimplifyGEPInst(cast(I)->getSourceElementType(),
4451 Ops, DL, TLI, DT, I);
4458 Ops, DL, TLI, DT, AC, I);
44524459 break;
44534460 }
44544461 case Instruction::InsertValue: {
44554462 InsertValueInst *IV = cast(I);
44564463 Result = SimplifyInsertValueInst(IV->getAggregateOperand(),
44574464 IV->getInsertedValueOperand(),
4458 IV->getIndices(), DL, TLI, DT, I);
4465 IV->getIndices(), DL, TLI, DT, AC, I);
44594466 break;
44604467 }
44614468 case Instruction::ExtractValue: {
44624469 auto *EVI = cast(I);
44634470 Result = SimplifyExtractValueInst(EVI->getAggregateOperand(),
4464 EVI->getIndices(), DL, TLI, DT, I);
4471 EVI->getIndices(), DL, TLI, DT, AC, I);
44654472 break;
44664473 }
44674474 case Instruction::ExtractElement: {
44684475 auto *EEI = cast(I);
44694476 Result = SimplifyExtractElementInst(
4470 EEI->getVectorOperand(), EEI->getIndexOperand(), DL, TLI, DT, I);
4477 EEI->getVectorOperand(), EEI->getIndexOperand(), DL, TLI, DT, AC, I);
44714478 break;
44724479 }
44734480 case Instruction::PHI:
4474 Result = SimplifyPHINode(cast(I), Query(DL, TLI, DT, I));
4481 Result = SimplifyPHINode(cast(I), Query(DL, TLI, DT, AC, I));
44754482 break;
44764483 case Instruction::Call: {
44774484 CallSite CS(cast(I));
44784485 Result = SimplifyCall(CS.getCalledValue(), CS.arg_begin(), CS.arg_end(), DL,
4479 TLI, DT, I);
4486 TLI, DT, AC, I);
44804487 break;
44814488 }
44824489 #define HANDLE_CAST_INST(num, opc, clas) case Instruction::opc:
44834490 #include "llvm/IR/Instruction.def"
44844491 #undef HANDLE_CAST_INST
44854492 Result = SimplifyCastInst(I->getOpcode(), I->getOperand(0), I->getType(),
4486 DL, TLI, DT, I);
4493 DL, TLI, DT, AC, I);
44874494 break;
44884495 }
44894496
44934500 unsigned BitWidth = I->getType()->getScalarSizeInBits();
44944501 APInt KnownZero(BitWidth, 0);
44954502 APInt KnownOne(BitWidth, 0);
4496 computeKnownBits(I, KnownZero, KnownOne, DL, /*Depth*/0, I, DT);
4503 computeKnownBits(I, KnownZero, KnownOne, DL, /*Depth*/0, AC, I, DT);
44974504 if ((KnownZero | KnownOne).isAllOnesValue())
44984505 Result = ConstantInt::get(I->getType(), KnownOne);
44994506 }
45174524 /// in simplified value does not count toward this.
45184525 static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV,
45194526 const TargetLibraryInfo *TLI,
4520 const DominatorTree *DT) {
4527 const DominatorTree *DT,
4528 AssumptionCache *AC) {
45214529 bool Simplified = false;
45224530 SmallSetVector Worklist;
45234531 const DataLayout &DL = I->getModule()->getDataLayout();
45464554 I = Worklist[Idx];
45474555
45484556 // See if this instruction simplifies.
4549 SimpleV = SimplifyInstruction(I, DL, TLI, DT);
4557 SimpleV = SimplifyInstruction(I, DL, TLI, DT, AC);
45504558 if (!SimpleV)
45514559 continue;
45524560
45724580
45734581 bool llvm::recursivelySimplifyInstruction(Instruction *I,
45744582 const TargetLibraryInfo *TLI,
4575 const DominatorTree *DT) {
4576 return replaceAndRecursivelySimplifyImpl(I, nullptr, TLI, DT);
4583 const DominatorTree *DT,
4584 AssumptionCache *AC) {
4585 return replaceAndRecursivelySimplifyImpl(I, nullptr, TLI, DT, AC);
45774586 }
45784587
45794588 bool llvm::replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
45804589 const TargetLibraryInfo *TLI,
4581 const DominatorTree *DT) {
4590 const DominatorTree *DT,
4591 AssumptionCache *AC) {
45824592 assert(I != SimpleV && "replaceAndRecursivelySimplify(X,X) is not valid!");
45834593 assert(SimpleV && "Must provide a simplified value.");
4584 return replaceAndRecursivelySimplifyImpl(I, SimpleV, TLI, DT);
4585 }
4594 return replaceAndRecursivelySimplifyImpl(I, SimpleV, TLI, DT, AC);
4595 }
1414 #include "llvm/Analysis/LazyValueInfo.h"
1515 #include "llvm/ADT/DenseSet.h"
1616 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/Analysis/AssumptionCache.h"
1718 #include "llvm/Analysis/ConstantFolding.h"
1819 #include "llvm/Analysis/TargetLibraryInfo.h"
1920 #include "llvm/Analysis/ValueTracking.h"
4041 char LazyValueInfoWrapperPass::ID = 0;
4142 INITIALIZE_PASS_BEGIN(LazyValueInfoWrapperPass, "lazy-value-info",
4243 "Lazy Value Information Analysis", false, true)
44 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
4345 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
4446 INITIALIZE_PASS_END(LazyValueInfoWrapperPass, "lazy-value-info",
4547 "Lazy Value Information Analysis", false, true)
576578 return true;
577579 }
578580
581 AssumptionCache *AC; ///< A pointer to the cache of @llvm.assume calls.
579582 const DataLayout &DL; ///< A mandatory DataLayout
580583 DominatorTree *DT; ///< An optional DT pointer.
581584
634637 /// PredBB to OldSucc has been threaded to be from PredBB to NewSucc.
635638 void threadEdge(BasicBlock *PredBB,BasicBlock *OldSucc,BasicBlock *NewSucc);
636639
637 LazyValueInfoImpl(const DataLayout &DL, DominatorTree *DT = nullptr)
638 : DL(DL), DT(DT) {}
640 LazyValueInfoImpl(AssumptionCache *AC, const DataLayout &DL,
641 DominatorTree *DT = nullptr)
642 : AC(AC), DL(DL), DT(DT) {}
639643 };
640644 } // end anonymous namespace
641645
919923 if (!BBI)
920924 return;
921925
922 for (auto *U : Val->users()) {
923 auto *II = dyn_cast(U);
924 if (!II)
926 for (auto &AssumeVH : AC->assumptions()) {
927 if (!AssumeVH)
925928 continue;
926 if (II->getIntrinsicID() != Intrinsic::assume)
929 auto *I = cast(AssumeVH);
930 if (!isValidAssumeForContext(I, BBI, DT))
927931 continue;
928 if (!isValidAssumeForContext(II, BBI, DT))
929 continue;
930
931 BBLV = intersect(BBLV, getValueFromCondition(Val, II->getArgOperand(0)));
932
933 BBLV = intersect(BBLV, getValueFromCondition(Val, I->getArgOperand(0)));
932934 }
933935
934936 // If guards are not used in the module, don't spend time looking for them
14551457 //===----------------------------------------------------------------------===//
14561458
14571459 /// This lazily constructs the LazyValueInfoImpl.
1458 static LazyValueInfoImpl &getImpl(void *&PImpl, const DataLayout *DL,
1460 static LazyValueInfoImpl &getImpl(void *&PImpl, AssumptionCache *AC,
1461 const DataLayout *DL,
14591462 DominatorTree *DT = nullptr) {
14601463 if (!PImpl) {
14611464 assert(DL && "getCache() called with a null DataLayout");
1462 PImpl = new LazyValueInfoImpl(*DL, DT);
1465 PImpl = new LazyValueInfoImpl(AC, *DL, DT);
14631466 }
14641467 return *static_cast(PImpl);
14651468 }
14661469
14671470 bool LazyValueInfoWrapperPass::runOnFunction(Function &F) {
1471 Info.AC = &getAnalysis().getAssumptionCache(F);
14681472 const DataLayout &DL = F.getParent()->getDataLayout();
14691473
14701474 DominatorTreeWrapperPass *DTWP =
14731477 Info.TLI = &getAnalysis().getTLI();
14741478
14751479 if (Info.PImpl)
1476 getImpl(Info.PImpl, &DL, Info.DT).clear();
1480 getImpl(Info.PImpl, Info.AC, &DL, Info.DT).clear();
14771481
14781482 // Fully lazy.
14791483 return false;
14811485
14821486 void LazyValueInfoWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
14831487 AU.setPreservesAll();
1488 AU.addRequired();
14841489 AU.addRequired();
14851490 }
14861491
14911496 void LazyValueInfo::releaseMemory() {
14921497 // If the cache was allocated, free it.
14931498 if (PImpl) {
1494 delete &getImpl(PImpl, nullptr);
1499 delete &getImpl(PImpl, AC, nullptr);
14951500 PImpl = nullptr;
14961501 }
14971502 }
14991504 void LazyValueInfoWrapperPass::releaseMemory() { Info.releaseMemory(); }
15001505
15011506 LazyValueInfo LazyValueAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
1507 auto &AC = FAM.getResult(F);
15021508 auto &TLI = FAM.getResult(F);
15031509 auto *DT = FAM.getCachedResult(F);
15041510
1505 return LazyValueInfo(&TLI, DT);
1511 return LazyValueInfo(&AC, &TLI, DT);
15061512 }
15071513
15081514 /// Returns true if we can statically tell that this value will never be a
15271533
15281534 const DataLayout &DL = BB->getModule()->getDataLayout();
15291535 LVILatticeVal Result =
1530 getImpl(PImpl, &DL, DT).getValueInBlock(V, BB, CxtI);
1536 getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
15311537
15321538 if (Result.isConstant())
15331539 return Result.getConstant();
15451551 unsigned Width = V->getType()->getIntegerBitWidth();
15461552 const DataLayout &DL = BB->getModule()->getDataLayout();
15471553 LVILatticeVal Result =
1548 getImpl(PImpl, &DL, DT).getValueInBlock(V, BB, CxtI);
1554 getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
15491555 if (Result.isUndefined())
15501556 return ConstantRange(Width, /*isFullSet=*/false);
15511557 if (Result.isConstantRange())
15641570 Instruction *CxtI) {
15651571 const DataLayout &DL = FromBB->getModule()->getDataLayout();
15661572 LVILatticeVal Result =
1567 getImpl(PImpl, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1573 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
15681574
15691575 if (Result.isConstant())
15701576 return Result.getConstant();
16521658 Instruction *CxtI) {
16531659 const DataLayout &DL = FromBB->getModule()->getDataLayout();
16541660 LVILatticeVal Result =
1655 getImpl(PImpl, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1661 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
16561662
16571663 return getPredicateResult(Pred, C, Result, DL, TLI);
16581664 }
16721678 return LazyValueInfo::True;
16731679 }
16741680 const DataLayout &DL = CxtI->getModule()->getDataLayout();
1675 LVILatticeVal Result = getImpl(PImpl, &DL, DT).getValueAt(V, CxtI);
1681 LVILatticeVal Result = getImpl(PImpl, AC, &DL, DT).getValueAt(V, CxtI);
16761682 Tristate Ret = getPredicateResult(Pred, C, Result, DL, TLI);
16771683 if (Ret != Unknown)
16781684 return Ret;
17621768 BasicBlock *NewSucc) {
17631769 if (PImpl) {
17641770 const DataLayout &DL = PredBB->getModule()->getDataLayout();
1765 getImpl(PImpl, &DL, DT).threadEdge(PredBB, OldSucc, NewSucc);
1771 getImpl(PImpl, AC, &DL, DT).threadEdge(PredBB, OldSucc, NewSucc);
17661772 }
17671773 }
17681774
17691775 void LazyValueInfo::eraseBlock(BasicBlock *BB) {
17701776 if (PImpl) {
17711777 const DataLayout &DL = BB->getModule()->getDataLayout();
1772 getImpl(PImpl, &DL, DT).eraseBlock(BB);
1773 }
1774 }
1778 getImpl(PImpl, AC, &DL, DT).eraseBlock(BB);
1779 }
1780 }
3939 #include "llvm/ADT/SmallPtrSet.h"
4040 #include "llvm/ADT/Twine.h"
4141 #include "llvm/Analysis/AliasAnalysis.h"
42 #include "llvm/Analysis/AssumptionCache.h"
4243 #include "llvm/Analysis/ConstantFolding.h"
4344 #include "llvm/Analysis/InstructionSimplify.h"
4445 #include "llvm/Analysis/Loads.h"
126127 Module *Mod;
127128 const DataLayout *DL;
128129 AliasAnalysis *AA;
130 AssumptionCache *AC;
129131 DominatorTree *DT;
130132 TargetLibraryInfo *TLI;
131133
142144 void getAnalysisUsage(AnalysisUsage &AU) const override {
143145 AU.setPreservesAll();
144146 AU.addRequired();
147 AU.addRequired();
145148 AU.addRequired();
146149 AU.addRequired();
147150 }
181184 char Lint::ID = 0;
182185 INITIALIZE_PASS_BEGIN(Lint, "lint", "Statically lint-checks LLVM IR",
183186 false, true)
187 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
184188 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
185189 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
186190 INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
198202 Mod = F.getParent();
199203 DL = &F.getParent()->getDataLayout();
200204 AA = &getAnalysis().getAAResults();
205 AC = &getAnalysis().getAssumptionCache(F);
201206 DT = &getAnalysis().getDomTree();
202207 TLI = &getAnalysis().getTLI();
203208 visit(F);
519524 "Undefined result: Shift count out of range", &I);
520525 }
521526
522 static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT) {
527 static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT,
528 AssumptionCache *AC) {
523529 // Assume undef could be zero.
524530 if (isa(V))
525531 return true;
528534 if (!VecTy) {
529535 unsigned BitWidth = V->getType()->getIntegerBitWidth();
530536 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
531 computeKnownBits(V, KnownZero, KnownOne, DL, 0,
537 computeKnownBits(V, KnownZero, KnownOne, DL, 0, AC,
532538 dyn_cast(V), DT);
533539 return KnownZero.isAllOnesValue();
534540 }
559565 }
560566
561567 void Lint::visitSDiv(BinaryOperator &I) {
562 Assert(!isZero(I.getOperand(1), I.getModule()->getDataLayout(), DT),
568 Assert(!isZero(I.getOperand(1), I.getModule()->getDataLayout(), DT, AC),
563569 "Undefined behavior: Division by zero", &I);
564570 }
565571
566572 void Lint::visitUDiv(BinaryOperator &I) {
567 Assert(!isZero(I.getOperand(1), I.getModule()->getDataLayout(), DT),
573 Assert(!isZero(I.getOperand(1), I.getModule()->getDataLayout(), DT, AC),
568574 "Undefined behavior: Division by zero", &I);
569575 }
570576
571577 void Lint::visitSRem(BinaryOperator &I) {
572 Assert(!isZero(I.getOperand(1), I.getModule()->getDataLayout(), DT),
578 Assert(!isZero(I.getOperand(1), I.getModule()->getDataLayout(), DT, AC),
573579 "Undefined behavior: Division by zero", &I);
574580 }
575581
576582 void Lint::visitURem(BinaryOperator &I) {
577 Assert(!isZero(I.getOperand(1), I.getModule()->getDataLayout(), DT),
583 Assert(!isZero(I.getOperand(1), I.getModule()->getDataLayout(), DT, AC),
578584 "Undefined behavior: Division by zero", &I);
579585 }
580586
692698
693699 // As a last resort, try SimplifyInstruction or constant folding.
694700 if (Instruction *Inst = dyn_cast(V)) {
695 if (Value *W = SimplifyInstruction(Inst, *DL, TLI, DT))
701 if (Value *W = SimplifyInstruction(Inst, *DL, TLI, DT, AC))
696702 return findValueImpl(W, OffsetOk, Visited);
697703 } else if (auto *C = dyn_cast(V)) {
698704 if (Value *W = ConstantFoldConstant(C, *DL, TLI))
1919 #include "llvm/ADT/STLExtras.h"
2020 #include "llvm/ADT/Statistic.h"
2121 #include "llvm/Analysis/AliasAnalysis.h"
22 #include "llvm/Analysis/AssumptionCache.h"
2223 #include "llvm/Analysis/MemoryBuiltins.h"
2324 #include "llvm/Analysis/PHITransAddr.h"
2425 #include "llvm/Analysis/OrderedBasicBlock.h"
889890 return;
890891 }
891892 const DataLayout &DL = FromBB->getModule()->getDataLayout();
892 PHITransAddr Address(const_cast(Loc.Ptr), DL);
893 PHITransAddr Address(const_cast(Loc.Ptr), DL, &AC);
893894
894895 // This is the set of blocks we've inspected, and the pointer we consider in
895896 // each block. Because of critical edges, we currently bail out if querying
16461647 MemoryDependenceResults
16471648 MemoryDependenceAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
16481649 auto &AA = AM.getResult(F);
1650 auto &AC = AM.getResult(F);
16491651 auto &TLI = AM.getResult(F);
16501652 auto &DT = AM.getResult(F);
1651 return MemoryDependenceResults(AA, TLI, DT);
1653 return MemoryDependenceResults(AA, AC, TLI, DT);
16521654 }
16531655
16541656 char MemoryDependenceWrapperPass::ID = 0;
16551657
16561658 INITIALIZE_PASS_BEGIN(MemoryDependenceWrapperPass, "memdep",
16571659 "Memory Dependence Analysis", false, true)
1660 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
16581661 INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
16591662 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
16601663 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
16731676
16741677 void MemoryDependenceWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
16751678 AU.setPreservesAll();
1679 AU.addRequired();
16761680 AU.addRequired();
16771681 AU.addRequiredTransitive();
16781682 AU.addRequiredTransitive();
16841688
16851689 bool MemoryDependenceWrapperPass::runOnFunction(Function &F) {
16861690 auto &AA = getAnalysis().getAAResults();
1691 auto &AC = getAnalysis().getAssumptionCache(F);
16871692 auto &TLI = getAnalysis().getTLI();
16881693 auto &DT = getAnalysis().getDomTree();
1689 MemDep.emplace(AA, TLI, DT);
1694 MemDep.emplace(AA, AC, TLI, DT);
16901695 return false;
16911696 }
226226
227227 // Simplify the GEP to handle 'gep x, 0' -> x etc.
228228 if (Value *V = SimplifyGEPInst(GEP->getSourceElementType(),
229 GEPOps, DL, TLI, DT)) {
229 GEPOps, DL, TLI, DT, AC)) {
230230 for (unsigned i = 0, e = GEPOps.size(); i != e; ++i)
231231 RemoveInstInputs(GEPOps[i], InstInputs);
232232
275275 }
276276
277277 // See if the add simplifies away.
278 if (Value *Res = SimplifyAddInst(LHS, RHS, isNSW, isNUW, DL, TLI, DT)) {
278 if (Value *Res = SimplifyAddInst(LHS, RHS, isNSW, isNUW, DL, TLI, DT, AC)) {
279279 // If we simplified the operands, the LHS is no longer an input, but Res
280280 // is.
281281 RemoveInstInputs(LHS, InstInputs);
366366 SmallVectorImpl &NewInsts) {
367367 // See if we have a version of this value already available and dominating
368368 // PredBB. If so, there is no need to insert a new instance of it.
369 PHITransAddr Tmp(InVal, DL);
369 PHITransAddr Tmp(InVal, DL, AC);
370370 if (!Tmp.PHITranslateValue(CurBB, PredBB, &DT, /*MustDominate=*/true))
371371 return Tmp.getAddr();
372372
6363 #include "llvm/ADT/ScopeExit.h"
6464 #include "llvm/ADT/Sequence.h"
6565 #include "llvm/ADT/SmallPtrSet.h"
66 #include "llvm/ADT/SmallSet.h"
6766 #include "llvm/ADT/Statistic.h"
67 #include "llvm/Analysis/AssumptionCache.h"
6868 #include "llvm/Analysis/ConstantFolding.h"
6969 #include "llvm/Analysis/InstructionSimplify.h"
7070 #include "llvm/Analysis/LoopInfo.h"
12111211 SCEV *S = new (SCEVAllocator) SCEVTruncateExpr(ID.Intern(SCEVAllocator),
12121212 Op, Ty);
12131213 UniqueSCEVs.InsertNode(S, IP);
1214 addAffectedFromOperands(S);
12151214 return S;
12161215 }
12171216
15981597 // these to prove lack of overflow. Use this fact to avoid
15991598 // doing extra work that may not pay off.
16001599 if (!isa(MaxBECount) || HasGuards ||
1601 !AffectedMap.empty()) {
1600 !AC.assumptions().empty()) {
16021601 // If the backedge is guarded by a comparison with the pre-inc
16031602 // value the addrec is safe. Also, if the entry is guarded by
16041603 // a comparison with the start value and the backedge is
16641663 SCEV *S = new (SCEVAllocator) SCEVZeroExtendExpr(ID.Intern(SCEVAllocator),
16651664 Op, Ty);
16661665 UniqueSCEVs.InsertNode(S, IP);
1667 addAffectedFromOperands(S);
16681666 return S;
16691667 }
16701668
18341832 // doing extra work that may not pay off.
18351833
18361834 if (!isa(MaxBECount) || HasGuards ||
1837 !AffectedMap.empty()) {
1835 !AC.assumptions().empty()) {
18381836 // If the backedge is guarded by a comparison with the pre-inc
18391837 // value the addrec is safe. Also, if the entry is guarded by
18401838 // a comparison with the start value and the backedge is
18921890 SCEV *S = new (SCEVAllocator) SCEVSignExtendExpr(ID.Intern(SCEVAllocator),
18931891 Op, Ty);
18941892 UniqueSCEVs.InsertNode(S, IP);
1895 addAffectedFromOperands(S);
18961893 return S;
18971894 }
18981895
24462443 S = new (SCEVAllocator) SCEVAddExpr(ID.Intern(SCEVAllocator),
24472444 O, Ops.size());
24482445 UniqueSCEVs.InsertNode(S, IP);
2449 addAffectedFromOperands(S);
24502446 }
24512447 S->setNoWrapFlags(Flags);
24522448 return S;
27392735 S = new (SCEVAllocator) SCEVMulExpr(ID.Intern(SCEVAllocator),
27402736 O, Ops.size());
27412737 UniqueSCEVs.InsertNode(S, IP);
2742 addAffectedFromOperands(S);
27432738 }
27442739 S->setNoWrapFlags(Flags);
27452740 return S;
28602855 SCEV *S = new (SCEVAllocator) SCEVUDivExpr(ID.Intern(SCEVAllocator),
28612856 LHS, RHS);
28622857 UniqueSCEVs.InsertNode(S, IP);
2863 addAffectedFromOperands(S);
28642858 return S;
28652859 }
28662860
30413035 S = new (SCEVAllocator) SCEVAddRecExpr(ID.Intern(SCEVAllocator),
30423036 O, Operands.size(), L);
30433037 UniqueSCEVs.InsertNode(S, IP);
3044 addAffectedFromOperands(S);
30453038 }
30463039 S->setNoWrapFlags(Flags);
30473040 return S;
31973190 SCEV *S = new (SCEVAllocator) SCEVSMaxExpr(ID.Intern(SCEVAllocator),
31983191 O, Ops.size());
31993192 UniqueSCEVs.InsertNode(S, IP);
3200 addAffectedFromOperands(S);
32013193 return S;
32023194 }
32033195
32993291 SCEV *S = new (SCEVAllocator) SCEVUMaxExpr(ID.Intern(SCEVAllocator),
33003292 O, Ops.size());
33013293 UniqueSCEVs.InsertNode(S, IP);
3302 addAffectedFromOperands(S);
33033294 return S;
33043295 }
33053296
35003491 ExprValueMap[Stripped].insert({V, Offset});
35013492 }
35023493 }
3503
3504 // If this value is an instruction or an argument, and might be affected by
3505 // an assumption, and its SCEV to the AffectedMap.
3506 if (isa(V) || isa(V)) {
3507 for (auto *U : V->users()) {
3508 auto *II = dyn_cast(U);
3509 if (!II)
3510 continue;
3511 if (II->getIntrinsicID() != Intrinsic::assume)
3512 continue;
3513
3514 AffectedMap[S].insert(II);
3515 }
3516 }
3517
35183494 return S;
3519 }
3520
3521 // If one of this SCEV's operands is in the AffectedMap (meaning that it might
3522 // be affected by an assumption), then this SCEV might be affected by the same
3523 // assumption.
3524 void ScalarEvolution::addAffectedFromOperands(const SCEV *S) {
3525 if (auto *NS = dyn_cast(S))
3526 for (auto *Op : NS->operands()) {
3527 auto AMI = AffectedMap.find(Op);
3528 if (AMI == AffectedMap.end())
3529 continue;
3530
3531 auto &ISet = AffectedMap[S];
3532 AMI = AffectedMap.find(Op);
3533 ISet.insert(AMI->second.begin(), AMI->second.end());
3534 }
35353495 }
35363496
35373497 const SCEV *ScalarEvolution::getExistingSCEV(Value *V) {
43234283 // PHI's incoming blocks are in a different loop, in which case doing so
43244284 // risks breaking LCSSA form. Instcombine would normally zap these, but
43254285 // it doesn't have DominatorTree information, so it may miss cases.
4326 if (Value *V = SimplifyInstruction(PN, getDataLayout(), &TLI, &DT))
4286 if (Value *V = SimplifyInstruction(PN, getDataLayout(), &TLI, &DT, &AC))
43274287 if (LI.replacementPreservesLCSSAForm(PN, V))
43284288 return getSCEV(V);
43294289
45114471 // For a SCEVUnknown, ask ValueTracking.
45124472 unsigned BitWidth = getTypeSizeInBits(U->getType());
45134473 APInt Zeros(BitWidth, 0), Ones(BitWidth, 0);
4514 computeKnownBits(U->getValue(), Zeros, Ones, getDataLayout(), 0,
4474 computeKnownBits(U->getValue(), Zeros, Ones, getDataLayout(), 0, &AC,
45154475 nullptr, &DT);
45164476 return Zeros.countTrailingOnes();
45174477 }
46824642 if (SignHint == ScalarEvolution::HINT_RANGE_UNSIGNED) {
46834643 // For a SCEVUnknown, ask ValueTracking.
46844644 APInt Zeros(BitWidth, 0), Ones(BitWidth, 0);
4685 computeKnownBits(U->getValue(), Zeros, Ones, DL, 0, nullptr, &DT);
4645 computeKnownBits(U->getValue(), Zeros, Ones, DL, 0, &AC, nullptr, &DT);
46864646 if (Ones != ~Zeros + 1)
46874647 ConservativeResult =
46884648 ConservativeResult.intersectWith(ConstantRange(Ones, ~Zeros + 1));
46894649 } else {
46904650 assert(SignHint == ScalarEvolution::HINT_RANGE_SIGNED &&
46914651 "generalize as needed!");
4692 unsigned NS = ComputeNumSignBits(U->getValue(), DL, 0, nullptr, &DT);
4652 unsigned NS = ComputeNumSignBits(U->getValue(), DL, 0, &AC, nullptr, &DT);
46934653 if (NS > 1)
46944654 ConservativeResult = ConservativeResult.intersectWith(
46954655 ConstantRange(APInt::getSignedMinValue(BitWidth).ashr(NS - 1),
51785138 unsigned BitWidth = A.getBitWidth();
51795139 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
51805140 computeKnownBits(BO->LHS, KnownZero, KnownOne, getDataLayout(),
5181 0, nullptr, &DT);
5141 0, &AC, nullptr, &DT);
51825142
51835143 APInt EffectiveMask =
51845144 APInt::getLowBitsSet(BitWidth, BitWidth - LZ - TZ).shl(TZ);
63736333 // bitwidth(K) iterations.
63746334 Value *FirstValue = PN->getIncomingValueForBlock(Predecessor);
63756335 bool KnownZero, KnownOne;
6376 ComputeSignBit(FirstValue, KnownZero, KnownOne, DL, 0,
6336 ComputeSignBit(FirstValue, KnownZero, KnownOne, DL, 0, nullptr,
63776337 Predecessor->getTerminator(), &DT);
63786338 auto *Ty = cast(RHS->getType());
63796339 if (KnownZero)
79657925 }
79667926
79677927 // Check conditions due to any @llvm.assume intrinsics.
7968 auto CheckAssumptions = [&](const SCEV *S) {
7969 auto AMI = AffectedMap.find(S);
7970 if (AMI != AffectedMap.end())
7971 for (auto *Assume : AMI->second) {
7972 auto *CI = cast(Assume);
7973 if (!DT.dominates(CI, Latch->getTerminator()))
7974 continue;
7975
7976 if (isImpliedCond(Pred, LHS, RHS, CI->getArgOperand(0), false))
7977 return true;
7978 }
7979
7980 return false;
7981 };
7982
7983 if (CheckAssumptions(LHS) || CheckAssumptions(RHS))
7984 return true;
7928 for (auto &AssumeVH : AC.assumptions()) {
7929 if (!AssumeVH)
7930 continue;
7931 auto *CI = cast(AssumeVH);
7932 if (!DT.dominates(CI, Latch->getTerminator()))
7933 continue;
7934
7935 if (isImpliedCond(Pred, LHS, RHS, CI->getArgOperand(0), false))
7936 return true;
7937 }
79857938
79867939 // If the loop is not reachable from the entry block, we risk running into an
79877940 // infinite loop as we walk up into the dom tree. These loops do not matter
80668019 }
80678020
80688021 // Check conditions due to any @llvm.assume intrinsics.
8069 auto CheckAssumptions = [&](const SCEV *S) {
8070 auto AMI = AffectedMap.find(S);
8071 if (AMI != AffectedMap.end())
8072 for (auto *Assume : AMI->second) {
8073 auto *CI = cast(Assume);
8074 if (!DT.dominates(CI, L->getHeader()))
8075 continue;
8076
8077 if (isImpliedCond(Pred, LHS, RHS, CI->getArgOperand(0), false))
8078 return true;
8079 }
8080
8081 return false;
8082 };
8083
8084 if (CheckAssumptions(LHS) || CheckAssumptions(RHS))
8085 return true;
8022 for (auto &AssumeVH : AC.assumptions()) {
8023 if (!AssumeVH)
8024 continue;
8025 auto *CI = cast(AssumeVH);
8026 if (!DT.dominates(CI, L->getHeader()))
8027 continue;
8028
8029 if (isImpliedCond(Pred, LHS, RHS, CI->getArgOperand(0), false))
8030 return true;
8031 }
80868032
80878033 return false;
80888034 }
95359481 //===----------------------------------------------------------------------===//
95369482
95379483 ScalarEvolution::ScalarEvolution(Function &F, TargetLibraryInfo &TLI,
9538 DominatorTree &DT, LoopInfo &LI)
9539 : F(F), TLI(TLI), DT(DT), LI(LI),
9484 AssumptionCache &AC, DominatorTree &DT,
9485 LoopInfo &LI)
9486 : F(F), TLI(TLI), AC(AC), DT(DT), LI(LI),
95409487 CouldNotCompute(new SCEVCouldNotCompute()),
95419488 WalkingBEDominatingConds(false), ProvingSplitPredicate(false),
95429489 ValuesAtScopes(64), LoopDispositions(64), BlockDispositions(64),
95589505 }
95599506
95609507 ScalarEvolution::ScalarEvolution(ScalarEvolution &&Arg)
9561 : F(Arg.F), HasGuards(Arg.HasGuards), TLI(Arg.TLI), DT(Arg.DT),
9508 : F(Arg.F), HasGuards(Arg.HasGuards), TLI(Arg.TLI), AC(Arg.AC), DT(Arg.DT),
95629509 LI(Arg.LI), CouldNotCompute(std::move(Arg.CouldNotCompute)),
95639510 ValueExprMap(std::move(Arg.ValueExprMap)),
95649511 PendingLoopPredicates(std::move(Arg.PendingLoopPredicates)),
100299976
100309977 // Gather stringified backedge taken counts for all loops using a fresh
100319978 // ScalarEvolution object.
10032 ScalarEvolution SE2(F, TLI, DT, LI);
9979 ScalarEvolution SE2(F, TLI, AC, DT, LI);
100339980 for (LoopInfo::reverse_iterator I = LI.rbegin(), E = LI.rend(); I != E; ++I)
100349981 getLoopBackedgeTakenCounts(*I, BackedgeDumpsNew, SE2);
100359982
1007010017 ScalarEvolution ScalarEvolutionAnalysis::run(Function &F,
1007110018 FunctionAnalysisManager &AM) {
1007210019 return ScalarEvolution(F, AM.getResult(F),
10020 AM.getResult(F),
1007310021 AM.getResult(F),
1007410022 AM.getResult(F));
1007510023 }
1008210030
1008310031 INITIALIZE_PASS_BEGIN(ScalarEvolutionWrapperPass, "scalar-evolution",
1008410032 "Scalar Evolution Analysis", false, true)
10033 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
1008510034 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
1008610035 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
1008710036 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
1009610045 bool ScalarEvolutionWrapperPass::runOnFunction(Function &F) {
1009710046 SE.reset(new ScalarEvolution(
1009810047 F, getAnalysis().getTLI(),
10048 getAnalysis().getAssumptionCache(F),
1009910049 getAnalysis().getDomTree(),
1010010050 getAnalysis().getLoopInfo()));
1010110051 return false;
1011610066
1011710067 void ScalarEvolutionWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
1011810068 AU.setPreservesAll();
10069 AU.addRequiredTransitive();
1011910070 AU.addRequiredTransitive();
1012010071 AU.addRequiredTransitive();
1012110072 AU.addRequiredTransitive();
17991799 // so narrow phis can reuse them.
18001800 for (PHINode *Phi : Phis) {
18011801 auto SimplifyPHINode = [&](PHINode *PN) -> Value * {
1802 if (Value *V = SimplifyInstruction(PN, DL, &SE.TLI, &SE.DT))
1802 if (Value *V = SimplifyInstruction(PN, DL, &SE.TLI, &SE.DT, &SE.AC))
18031803 return V;
18041804 if (!SE.isSCEVable(PN->getType()))
18051805 return nullptr;
1414 #include "llvm/Analysis/ValueTracking.h"
1515 #include "llvm/ADT/Optional.h"
1616 #include "llvm/ADT/SmallPtrSet.h"
17 #include "llvm/ADT/SmallSet.h"
17 #include "llvm/Analysis/AssumptionCache.h"
1818 #include "llvm/Analysis/InstructionSimplify.h"
1919 #include "llvm/Analysis/MemoryBuiltins.h"
2020 #include "llvm/Analysis/Loads.h"
7272 // figuring out if we can use it.
7373 struct Query {
7474 const DataLayout &DL;
75 AssumptionCache *AC;
7576 const Instruction *CxtI;
7677 const DominatorTree *DT;
7778
8788 std::array Excluded;
8889 unsigned NumExcluded;
8990
90 Query(const DataLayout &DL, const Instruction *CxtI, const DominatorTree *DT)
91 : DL(DL), CxtI(CxtI), DT(DT), NumExcluded(0) {}
91 Query(const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI,
92 const DominatorTree *DT)
93 : DL(DL), AC(AC), CxtI(CxtI), DT(DT), NumExcluded(0) {}
9294
9395 Query(const Query &Q, const Value *NewExcl)
94 : DL(Q.DL), CxtI(Q.CxtI), DT(Q.DT), NumExcluded(Q.NumExcluded) {
96 : DL(Q.DL), AC(Q.AC), CxtI(Q.CxtI), DT(Q.DT), NumExcluded(Q.NumExcluded) {
9597 Excluded = Q.Excluded;
9698 Excluded[NumExcluded++] = NewExcl;
9799 assert(NumExcluded <= Excluded.size());
127129
128130 void llvm::computeKnownBits(const Value *V, APInt &KnownZero, APInt &KnownOne,
129131 const DataLayout &DL, unsigned Depth,
130 const Instruction *CxtI,
132 AssumptionCache *AC, const Instruction *CxtI,
131133 const DominatorTree *DT) {
132134 ::computeKnownBits(V, KnownZero, KnownOne, Depth,
133 Query(DL, safeCxtI(V, CxtI), DT));
135 Query(DL, AC, safeCxtI(V, CxtI), DT));
134136 }
135137
136138 bool llvm::haveNoCommonBitsSet(const Value *LHS, const Value *RHS,
137139 const DataLayout &DL,
138 const Instruction *CxtI,
140 AssumptionCache *AC, const Instruction *CxtI,
139141 const DominatorTree *DT) {
140142 assert(LHS->getType() == RHS->getType() &&
141143 "LHS and RHS should have the same type");
144146 IntegerType *IT = cast(LHS->getType()->getScalarType());
145147 APInt LHSKnownZero(IT->getBitWidth(), 0), LHSKnownOne(IT->getBitWidth(), 0);
146148 APInt RHSKnownZero(IT->getBitWidth(), 0), RHSKnownOne(IT->getBitWidth(), 0);
147 computeKnownBits(LHS, LHSKnownZero, LHSKnownOne, DL, 0, CxtI, DT);
148 computeKnownBits(RHS, RHSKnownZero, RHSKnownOne, DL, 0, CxtI, DT);
149 computeKnownBits(LHS, LHSKnownZero, LHSKnownOne, DL, 0, AC, CxtI, DT);
150 computeKnownBits(RHS, RHSKnownZero, RHSKnownOne, DL, 0, AC, CxtI, DT);
149151 return (LHSKnownZero | RHSKnownZero).isAllOnesValue();
150152 }
151153
154156
155157 void llvm::ComputeSignBit(const Value *V, bool &KnownZero, bool &KnownOne,
156158 const DataLayout &DL, unsigned Depth,
157 const Instruction *CxtI,
159 AssumptionCache *AC, const Instruction *CxtI,
158160 const DominatorTree *DT) {
159161 ::ComputeSignBit(V, KnownZero, KnownOne, Depth,
160 Query(DL, safeCxtI(V, CxtI), DT));
162 Query(DL, AC, safeCxtI(V, CxtI), DT));
161163 }
162164
163165 static bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth,
165167
166168 bool llvm::isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL,
167169 bool OrZero,
168 unsigned Depth, const Instruction *CxtI,
170 unsigned Depth, AssumptionCache *AC,
171 const Instruction *CxtI,
169172 const DominatorTree *DT) {
170173 return ::isKnownToBeAPowerOfTwo(V, OrZero, Depth,
171 Query(DL, safeCxtI(V, CxtI), DT));
174 Query(DL, AC, safeCxtI(V, CxtI), DT));
172175 }
173176
174177 static bool isKnownNonZero(const Value *V, unsigned Depth, const Query &Q);
175178
176179 bool llvm::isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth,
177 const Instruction *CxtI, const DominatorTree *DT) {
178 return ::isKnownNonZero(V, Depth, Query(DL, safeCxtI(V, CxtI), DT));
180 AssumptionCache *AC, const Instruction *CxtI,
181 const DominatorTree *DT) {
182 return ::isKnownNonZero(V, Depth, Query(DL, AC, safeCxtI(V, CxtI), DT));
179183 }
180184
181185 bool llvm::isKnownNonNegative(const Value *V, const DataLayout &DL,
182 unsigned Depth, const Instruction *CxtI,
186 unsigned Depth,
187 AssumptionCache *AC, const Instruction *CxtI,
183188 const DominatorTree *DT) {
184189 bool NonNegative, Negative;
185 ComputeSignBit(V, NonNegative, Negative, DL, Depth, CxtI, DT);
190 ComputeSignBit(V, NonNegative, Negative, DL, Depth, AC, CxtI, DT);
186191 return NonNegative;
187192 }
188193
189194 bool llvm::isKnownPositive(const Value *V, const DataLayout &DL, unsigned Depth,
190 const Instruction *CxtI, const DominatorTree *DT) {
195 AssumptionCache *AC, const Instruction *CxtI,
196 const DominatorTree *DT) {
191197 if (auto *CI = dyn_cast(V))
192198 return CI->getValue().isStrictlyPositive();
193199
194200 // TODO: We'd doing two recursive queries here. We should factor this such
195201 // that only a single query is needed.
196 return isKnownNonNegative(V, DL, Depth, CxtI, DT) &&
197 isKnownNonZero(V, DL, Depth, CxtI, DT);
202 return isKnownNonNegative(V, DL, Depth, AC, CxtI, DT) &&
203 isKnownNonZero(V, DL, Depth, AC, CxtI, DT);
198204 }
199205
200206 bool llvm::isKnownNegative(const Value *V, const DataLayout &DL, unsigned Depth,
201 const Instruction *CxtI, const DominatorTree *DT) {
207 AssumptionCache *AC, const Instruction *CxtI,
208 const DominatorTree *DT) {
202209 bool NonNegative, Negative;
203 ComputeSignBit(V, NonNegative, Negative, DL, Depth, CxtI, DT);
210 ComputeSignBit(V, NonNegative, Negative, DL, Depth, AC, CxtI, DT);
204211 return Negative;
205212 }
206213
207214 static bool isKnownNonEqual(const Value *V1, const Value *V2, const Query &Q);
208215
209216 bool llvm::isKnownNonEqual(const Value *V1, const Value *V2,
210 const DataLayout &DL, const Instruction *CxtI,
217 const DataLayout &DL,
218 AssumptionCache *AC, const Instruction *CxtI,
211219 const DominatorTree *DT) {
212 return ::isKnownNonEqual(V1, V2, Query(DL, safeCxtI(V1, safeCxtI(V2, CxtI)),
220 return ::isKnownNonEqual(V1, V2, Query(DL, AC,
221 safeCxtI(V1, safeCxtI(V2, CxtI)),
213222