blob: 0830ff5dd0422dd4b0cf114994a1ecc3717788da [file] [log] [blame]
Hal Finkeld67e4632014-09-07 20:05:11 +00001//===----------------------- AlignmentFromAssumptions.cpp -----------------===//
2// Set Load/Store Alignments From Assumptions
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10//
11// This file implements a ScalarEvolution-based transformation to set
12// the alignments of load, stores and memory intrinsics based on the truth
13// expressions of assume intrinsics. The primary motivation is to handle
14// complex alignment assumptions that apply to vector loads and stores that
15// appear after vectorization and unrolling.
16//
17//===----------------------------------------------------------------------===//
18
19#define AA_NAME "alignment-from-assumptions"
20#define DEBUG_TYPE AA_NAME
Sean Silvaa4c2d152016-06-15 06:18:01 +000021#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
Hal Finkeld67e4632014-09-07 20:05:11 +000022#include "llvm/ADT/SmallPtrSet.h"
23#include "llvm/ADT/Statistic.h"
Hal Finkel494393b2015-12-11 17:46:01 +000024#include "llvm/Analysis/AliasAnalysis.h"
Daniel Jasperaec2fa32016-12-19 08:22:17 +000025#include "llvm/Analysis/AssumptionCache.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000026#include "llvm/Analysis/GlobalsModRef.h"
Hal Finkeld67e4632014-09-07 20:05:11 +000027#include "llvm/Analysis/LoopInfo.h"
Hal Finkeld67e4632014-09-07 20:05:11 +000028#include "llvm/Analysis/ScalarEvolutionExpressions.h"
Benjamin Kramer799003b2015-03-23 19:32:43 +000029#include "llvm/Analysis/ValueTracking.h"
Hal Finkeld67e4632014-09-07 20:05:11 +000030#include "llvm/IR/Constant.h"
31#include "llvm/IR/Dominators.h"
32#include "llvm/IR/Instruction.h"
Hal Finkeld67e4632014-09-07 20:05:11 +000033#include "llvm/IR/Intrinsics.h"
Mehdi Amini46a43552015-03-04 18:43:29 +000034#include "llvm/IR/Module.h"
Hal Finkeld67e4632014-09-07 20:05:11 +000035#include "llvm/Support/Debug.h"
36#include "llvm/Support/raw_ostream.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000037#include "llvm/Transforms/Scalar.h"
Hal Finkeld67e4632014-09-07 20:05:11 +000038using namespace llvm;
39
40STATISTIC(NumLoadAlignChanged,
41 "Number of loads changed by alignment assumptions");
42STATISTIC(NumStoreAlignChanged,
43 "Number of stores changed by alignment assumptions");
44STATISTIC(NumMemIntAlignChanged,
45 "Number of memory intrinsics changed by alignment assumptions");
46
47namespace {
48struct AlignmentFromAssumptions : public FunctionPass {
49 static char ID; // Pass identification, replacement for typeid
50 AlignmentFromAssumptions() : FunctionPass(ID) {
51 initializeAlignmentFromAssumptionsPass(*PassRegistry::getPassRegistry());
52 }
53
Alexander Kornienkof817c1c2015-04-11 02:11:45 +000054 bool runOnFunction(Function &F) override;
Hal Finkeld67e4632014-09-07 20:05:11 +000055
Alexander Kornienkof817c1c2015-04-11 02:11:45 +000056 void getAnalysisUsage(AnalysisUsage &AU) const override {
Daniel Jasperaec2fa32016-12-19 08:22:17 +000057 AU.addRequired<AssumptionCacheTracker>();
Chandler Carruth2f1fd162015-08-17 02:08:17 +000058 AU.addRequired<ScalarEvolutionWrapperPass>();
Hal Finkeld67e4632014-09-07 20:05:11 +000059 AU.addRequired<DominatorTreeWrapperPass>();
60
61 AU.setPreservesCFG();
Hal Finkel494393b2015-12-11 17:46:01 +000062 AU.addPreserved<AAResultsWrapperPass>();
63 AU.addPreserved<GlobalsAAWrapperPass>();
Chandler Carruth4f8f3072015-01-17 14:16:18 +000064 AU.addPreserved<LoopInfoWrapperPass>();
Hal Finkeld67e4632014-09-07 20:05:11 +000065 AU.addPreserved<DominatorTreeWrapperPass>();
Chandler Carruth2f1fd162015-08-17 02:08:17 +000066 AU.addPreserved<ScalarEvolutionWrapperPass>();
Hal Finkeld67e4632014-09-07 20:05:11 +000067 }
68
Sean Silvaa4c2d152016-06-15 06:18:01 +000069 AlignmentFromAssumptionsPass Impl;
Hal Finkeld67e4632014-09-07 20:05:11 +000070};
Alexander Kornienkof00654e2015-06-23 09:49:53 +000071}
Hal Finkeld67e4632014-09-07 20:05:11 +000072
73char AlignmentFromAssumptions::ID = 0;
74static const char aip_name[] = "Alignment from assumptions";
75INITIALIZE_PASS_BEGIN(AlignmentFromAssumptions, AA_NAME,
76 aip_name, false, false)
Daniel Jasperaec2fa32016-12-19 08:22:17 +000077INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
Hal Finkeld67e4632014-09-07 20:05:11 +000078INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
Chandler Carruth2f1fd162015-08-17 02:08:17 +000079INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
Hal Finkeld67e4632014-09-07 20:05:11 +000080INITIALIZE_PASS_END(AlignmentFromAssumptions, AA_NAME,
81 aip_name, false, false)
82
83FunctionPass *llvm::createAlignmentFromAssumptionsPass() {
84 return new AlignmentFromAssumptions();
85}
86
87// Given an expression for the (constant) alignment, AlignSCEV, and an
88// expression for the displacement between a pointer and the aligned address,
Andrew Trick8fc3c6c2014-09-07 23:16:24 +000089// DiffSCEV, compute the alignment of the displaced pointer if it can be reduced
90// to a constant. Using SCEV to compute alignment handles the case where
91// DiffSCEV is a recurrence with constant start such that the aligned offset
92// is constant. e.g. {16,+,32} % 32 -> 16.
Hal Finkeld67e4632014-09-07 20:05:11 +000093static unsigned getNewAlignmentDiff(const SCEV *DiffSCEV,
94 const SCEV *AlignSCEV,
95 ScalarEvolution *SE) {
96 // DiffUnits = Diff % int64_t(Alignment)
97 const SCEV *DiffAlignDiv = SE->getUDivExpr(DiffSCEV, AlignSCEV);
98 const SCEV *DiffAlign = SE->getMulExpr(DiffAlignDiv, AlignSCEV);
99 const SCEV *DiffUnitsSCEV = SE->getMinusSCEV(DiffAlign, DiffSCEV);
100
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000101 LLVM_DEBUG(dbgs() << "\talignment relative to " << *AlignSCEV << " is "
102 << *DiffUnitsSCEV << " (diff: " << *DiffSCEV << ")\n");
Hal Finkeld67e4632014-09-07 20:05:11 +0000103
104 if (const SCEVConstant *ConstDUSCEV =
105 dyn_cast<SCEVConstant>(DiffUnitsSCEV)) {
106 int64_t DiffUnits = ConstDUSCEV->getValue()->getSExtValue();
107
108 // If the displacement is an exact multiple of the alignment, then the
109 // displaced pointer has the same alignment as the aligned pointer, so
110 // return the alignment value.
111 if (!DiffUnits)
112 return (unsigned)
113 cast<SCEVConstant>(AlignSCEV)->getValue()->getSExtValue();
114
115 // If the displacement is not an exact multiple, but the remainder is a
116 // constant, then return this remainder (but only if it is a power of 2).
Benjamin Kramer7bd1f7c2015-03-09 20:20:16 +0000117 uint64_t DiffUnitsAbs = std::abs(DiffUnits);
Hal Finkeld67e4632014-09-07 20:05:11 +0000118 if (isPowerOf2_64(DiffUnitsAbs))
119 return (unsigned) DiffUnitsAbs;
120 }
121
122 return 0;
123}
124
125// There is an address given by an offset OffSCEV from AASCEV which has an
126// alignment AlignSCEV. Use that information, if possible, to compute a new
127// alignment for Ptr.
128static unsigned getNewAlignment(const SCEV *AASCEV, const SCEV *AlignSCEV,
129 const SCEV *OffSCEV, Value *Ptr,
130 ScalarEvolution *SE) {
131 const SCEV *PtrSCEV = SE->getSCEV(Ptr);
132 const SCEV *DiffSCEV = SE->getMinusSCEV(PtrSCEV, AASCEV);
133
Hal Finkelf83e1f72014-09-11 08:40:17 +0000134 // On 32-bit platforms, DiffSCEV might now have type i32 -- we've always
135 // sign-extended OffSCEV to i64, so make sure they agree again.
136 DiffSCEV = SE->getNoopOrSignExtend(DiffSCEV, OffSCEV->getType());
137
Hal Finkeld67e4632014-09-07 20:05:11 +0000138 // What we really want to know is the overall offset to the aligned
139 // address. This address is displaced by the provided offset.
140 DiffSCEV = SE->getMinusSCEV(DiffSCEV, OffSCEV);
141
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000142 LLVM_DEBUG(dbgs() << "AFI: alignment of " << *Ptr << " relative to "
143 << *AlignSCEV << " and offset " << *OffSCEV
144 << " using diff " << *DiffSCEV << "\n");
Hal Finkeld67e4632014-09-07 20:05:11 +0000145
146 unsigned NewAlignment = getNewAlignmentDiff(DiffSCEV, AlignSCEV, SE);
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000147 LLVM_DEBUG(dbgs() << "\tnew alignment: " << NewAlignment << "\n");
Hal Finkeld67e4632014-09-07 20:05:11 +0000148
149 if (NewAlignment) {
150 return NewAlignment;
151 } else if (const SCEVAddRecExpr *DiffARSCEV =
152 dyn_cast<SCEVAddRecExpr>(DiffSCEV)) {
153 // The relative offset to the alignment assumption did not yield a constant,
154 // but we should try harder: if we assume that a is 32-byte aligned, then in
155 // for (i = 0; i < 1024; i += 4) r += a[i]; not all of the loads from a are
156 // 32-byte aligned, but instead alternate between 32 and 16-byte alignment.
157 // As a result, the new alignment will not be a constant, but can still
158 // be improved over the default (of 4) to 16.
159
160 const SCEV *DiffStartSCEV = DiffARSCEV->getStart();
161 const SCEV *DiffIncSCEV = DiffARSCEV->getStepRecurrence(*SE);
162
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000163 LLVM_DEBUG(dbgs() << "\ttrying start/inc alignment using start "
164 << *DiffStartSCEV << " and inc " << *DiffIncSCEV << "\n");
Hal Finkeld67e4632014-09-07 20:05:11 +0000165
166 // Now compute the new alignment using the displacement to the value in the
167 // first iteration, and also the alignment using the per-iteration delta.
168 // If these are the same, then use that answer. Otherwise, use the smaller
169 // one, but only if it divides the larger one.
170 NewAlignment = getNewAlignmentDiff(DiffStartSCEV, AlignSCEV, SE);
171 unsigned NewIncAlignment = getNewAlignmentDiff(DiffIncSCEV, AlignSCEV, SE);
172
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000173 LLVM_DEBUG(dbgs() << "\tnew start alignment: " << NewAlignment << "\n");
174 LLVM_DEBUG(dbgs() << "\tnew inc alignment: " << NewIncAlignment << "\n");
Hal Finkeld67e4632014-09-07 20:05:11 +0000175
Hal Finkel71b70842014-09-10 21:05:52 +0000176 if (!NewAlignment || !NewIncAlignment) {
177 return 0;
178 } else if (NewAlignment > NewIncAlignment) {
Hal Finkeld67e4632014-09-07 20:05:11 +0000179 if (NewAlignment % NewIncAlignment == 0) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000180 LLVM_DEBUG(dbgs() << "\tnew start/inc alignment: " << NewIncAlignment
181 << "\n");
Hal Finkeld67e4632014-09-07 20:05:11 +0000182 return NewIncAlignment;
183 }
184 } else if (NewIncAlignment > NewAlignment) {
185 if (NewIncAlignment % NewAlignment == 0) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000186 LLVM_DEBUG(dbgs() << "\tnew start/inc alignment: " << NewAlignment
187 << "\n");
Hal Finkeld67e4632014-09-07 20:05:11 +0000188 return NewAlignment;
189 }
Hal Finkel71b70842014-09-10 21:05:52 +0000190 } else if (NewIncAlignment == NewAlignment) {
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000191 LLVM_DEBUG(dbgs() << "\tnew start/inc alignment: " << NewAlignment
192 << "\n");
Hal Finkeld67e4632014-09-07 20:05:11 +0000193 return NewAlignment;
194 }
195 }
196
197 return 0;
198}
199
Sean Silvaa4c2d152016-06-15 06:18:01 +0000200bool AlignmentFromAssumptionsPass::extractAlignmentInfo(CallInst *I,
201 Value *&AAPtr,
202 const SCEV *&AlignSCEV,
203 const SCEV *&OffSCEV) {
Hal Finkeld67e4632014-09-07 20:05:11 +0000204 // An alignment assume must be a statement about the least-significant
205 // bits of the pointer being zero, possibly with some offset.
206 ICmpInst *ICI = dyn_cast<ICmpInst>(I->getArgOperand(0));
207 if (!ICI)
208 return false;
209
210 // This must be an expression of the form: x & m == 0.
211 if (ICI->getPredicate() != ICmpInst::ICMP_EQ)
212 return false;
213
214 // Swap things around so that the RHS is 0.
215 Value *CmpLHS = ICI->getOperand(0);
216 Value *CmpRHS = ICI->getOperand(1);
217 const SCEV *CmpLHSSCEV = SE->getSCEV(CmpLHS);
218 const SCEV *CmpRHSSCEV = SE->getSCEV(CmpRHS);
219 if (CmpLHSSCEV->isZero())
220 std::swap(CmpLHS, CmpRHS);
221 else if (!CmpRHSSCEV->isZero())
222 return false;
223
224 BinaryOperator *CmpBO = dyn_cast<BinaryOperator>(CmpLHS);
225 if (!CmpBO || CmpBO->getOpcode() != Instruction::And)
226 return false;
227
228 // Swap things around so that the right operand of the and is a constant
229 // (the mask); we cannot deal with variable masks.
230 Value *AndLHS = CmpBO->getOperand(0);
231 Value *AndRHS = CmpBO->getOperand(1);
232 const SCEV *AndLHSSCEV = SE->getSCEV(AndLHS);
233 const SCEV *AndRHSSCEV = SE->getSCEV(AndRHS);
234 if (isa<SCEVConstant>(AndLHSSCEV)) {
235 std::swap(AndLHS, AndRHS);
236 std::swap(AndLHSSCEV, AndRHSSCEV);
237 }
238
239 const SCEVConstant *MaskSCEV = dyn_cast<SCEVConstant>(AndRHSSCEV);
240 if (!MaskSCEV)
241 return false;
242
243 // The mask must have some trailing ones (otherwise the condition is
244 // trivial and tells us nothing about the alignment of the left operand).
Sanjoy Das0de2fec2015-12-17 20:28:46 +0000245 unsigned TrailingOnes = MaskSCEV->getAPInt().countTrailingOnes();
Hal Finkeld67e4632014-09-07 20:05:11 +0000246 if (!TrailingOnes)
247 return false;
248
249 // Cap the alignment at the maximum with which LLVM can deal (and make sure
250 // we don't overflow the shift).
251 uint64_t Alignment;
252 TrailingOnes = std::min(TrailingOnes,
253 unsigned(sizeof(unsigned) * CHAR_BIT - 1));
254 Alignment = std::min(1u << TrailingOnes, +Value::MaximumAlignment);
255
256 Type *Int64Ty = Type::getInt64Ty(I->getParent()->getParent()->getContext());
257 AlignSCEV = SE->getConstant(Int64Ty, Alignment);
258
259 // The LHS might be a ptrtoint instruction, or it might be the pointer
260 // with an offset.
261 AAPtr = nullptr;
262 OffSCEV = nullptr;
263 if (PtrToIntInst *PToI = dyn_cast<PtrToIntInst>(AndLHS)) {
264 AAPtr = PToI->getPointerOperand();
Sanjoy Das2aacc0e2015-09-23 01:59:04 +0000265 OffSCEV = SE->getZero(Int64Ty);
Hal Finkeld67e4632014-09-07 20:05:11 +0000266 } else if (const SCEVAddExpr* AndLHSAddSCEV =
267 dyn_cast<SCEVAddExpr>(AndLHSSCEV)) {
268 // Try to find the ptrtoint; subtract it and the rest is the offset.
269 for (SCEVAddExpr::op_iterator J = AndLHSAddSCEV->op_begin(),
270 JE = AndLHSAddSCEV->op_end(); J != JE; ++J)
271 if (const SCEVUnknown *OpUnk = dyn_cast<SCEVUnknown>(*J))
272 if (PtrToIntInst *PToI = dyn_cast<PtrToIntInst>(OpUnk->getValue())) {
273 AAPtr = PToI->getPointerOperand();
274 OffSCEV = SE->getMinusSCEV(AndLHSAddSCEV, *J);
275 break;
276 }
277 }
278
279 if (!AAPtr)
280 return false;
281
282 // Sign extend the offset to 64 bits (so that it is like all of the other
Fangrui Songf78650a2018-07-30 19:41:25 +0000283 // expressions).
Hal Finkeld67e4632014-09-07 20:05:11 +0000284 unsigned OffSCEVBits = OffSCEV->getType()->getPrimitiveSizeInBits();
285 if (OffSCEVBits < 64)
286 OffSCEV = SE->getSignExtendExpr(OffSCEV, Int64Ty);
287 else if (OffSCEVBits > 64)
288 return false;
289
290 AAPtr = AAPtr->stripPointerCasts();
291 return true;
292}
293
Sean Silvaa4c2d152016-06-15 06:18:01 +0000294bool AlignmentFromAssumptionsPass::processAssumption(CallInst *ACall) {
Hal Finkeld67e4632014-09-07 20:05:11 +0000295 Value *AAPtr;
296 const SCEV *AlignSCEV, *OffSCEV;
297 if (!extractAlignmentInfo(ACall, AAPtr, AlignSCEV, OffSCEV))
298 return false;
299
Duncan P. N. Exon Smith4fd9b7e2016-09-24 20:00:38 +0000300 // Skip ConstantPointerNull and UndefValue. Assumptions on these shouldn't
301 // affect other users.
302 if (isa<ConstantData>(AAPtr))
303 return false;
304
Hal Finkeld67e4632014-09-07 20:05:11 +0000305 const SCEV *AASCEV = SE->getSCEV(AAPtr);
306
307 // Apply the assumption to all other users of the specified pointer.
308 SmallPtrSet<Instruction *, 32> Visited;
309 SmallVector<Instruction*, 16> WorkList;
310 for (User *J : AAPtr->users()) {
311 if (J == ACall)
312 continue;
313
314 if (Instruction *K = dyn_cast<Instruction>(J))
Mehdi Aminia28d91d2015-03-10 02:37:25 +0000315 if (isValidAssumeForContext(ACall, K, DT))
Hal Finkeld67e4632014-09-07 20:05:11 +0000316 WorkList.push_back(K);
317 }
318
319 while (!WorkList.empty()) {
320 Instruction *J = WorkList.pop_back_val();
321
322 if (LoadInst *LI = dyn_cast<LoadInst>(J)) {
323 unsigned NewAlignment = getNewAlignment(AASCEV, AlignSCEV, OffSCEV,
324 LI->getPointerOperand(), SE);
325
326 if (NewAlignment > LI->getAlignment()) {
327 LI->setAlignment(NewAlignment);
328 ++NumLoadAlignChanged;
329 }
330 } else if (StoreInst *SI = dyn_cast<StoreInst>(J)) {
331 unsigned NewAlignment = getNewAlignment(AASCEV, AlignSCEV, OffSCEV,
332 SI->getPointerOperand(), SE);
333
334 if (NewAlignment > SI->getAlignment()) {
335 SI->setAlignment(NewAlignment);
336 ++NumStoreAlignChanged;
337 }
338 } else if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(J)) {
339 unsigned NewDestAlignment = getNewAlignment(AASCEV, AlignSCEV, OffSCEV,
340 MI->getDest(), SE);
341
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000342 LLVM_DEBUG(dbgs() << "\tmem inst: " << NewDestAlignment << "\n";);
Daniel Neilson20c92072018-02-22 18:55:59 +0000343 if (NewDestAlignment > MI->getDestAlignment()) {
344 MI->setDestAlignment(NewDestAlignment);
345 ++NumMemIntAlignChanged;
346 }
347
348 // For memory transfers, there is also a source alignment that
349 // can be set.
Hal Finkeld67e4632014-09-07 20:05:11 +0000350 if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(MI)) {
351 unsigned NewSrcAlignment = getNewAlignment(AASCEV, AlignSCEV, OffSCEV,
352 MTI->getSource(), SE);
353
Nicola Zaghend34e60c2018-05-14 12:53:11 +0000354 LLVM_DEBUG(dbgs() << "\tmem trans: " << NewSrcAlignment << "\n";);
Hal Finkeld67e4632014-09-07 20:05:11 +0000355
Daniel Neilson20c92072018-02-22 18:55:59 +0000356 if (NewSrcAlignment > MTI->getSourceAlignment()) {
357 MTI->setSourceAlignment(NewSrcAlignment);
Hal Finkeld67e4632014-09-07 20:05:11 +0000358 ++NumMemIntAlignChanged;
359 }
Hal Finkeld67e4632014-09-07 20:05:11 +0000360 }
361 }
362
363 // Now that we've updated that use of the pointer, look for other uses of
364 // the pointer to update.
365 Visited.insert(J);
366 for (User *UJ : J->users()) {
367 Instruction *K = cast<Instruction>(UJ);
Mehdi Aminia28d91d2015-03-10 02:37:25 +0000368 if (!Visited.count(K) && isValidAssumeForContext(ACall, K, DT))
Hal Finkeld67e4632014-09-07 20:05:11 +0000369 WorkList.push_back(K);
370 }
371 }
372
373 return true;
374}
375
376bool AlignmentFromAssumptions::runOnFunction(Function &F) {
Andrew Kaylor50271f72016-05-03 22:32:30 +0000377 if (skipFunction(F))
378 return false;
379
Daniel Jasperaec2fa32016-12-19 08:22:17 +0000380 auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
Sean Silvaa4c2d152016-06-15 06:18:01 +0000381 ScalarEvolution *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
382 DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
383
Daniel Jasperaec2fa32016-12-19 08:22:17 +0000384 return Impl.runImpl(F, AC, SE, DT);
Sean Silvaa4c2d152016-06-15 06:18:01 +0000385}
386
Daniel Jasperaec2fa32016-12-19 08:22:17 +0000387bool AlignmentFromAssumptionsPass::runImpl(Function &F, AssumptionCache &AC,
388 ScalarEvolution *SE_,
Sean Silvaa4c2d152016-06-15 06:18:01 +0000389 DominatorTree *DT_) {
390 SE = SE_;
391 DT = DT_;
Hal Finkeld67e4632014-09-07 20:05:11 +0000392
Sean Silvaa4c2d152016-06-15 06:18:01 +0000393 bool Changed = false;
Daniel Jasperaec2fa32016-12-19 08:22:17 +0000394 for (auto &AssumeVH : AC.assumptions())
395 if (AssumeVH)
396 Changed |= processAssumption(cast<CallInst>(AssumeVH));
Hal Finkeld67e4632014-09-07 20:05:11 +0000397
398 return Changed;
399}
400
Sean Silvaa4c2d152016-06-15 06:18:01 +0000401PreservedAnalyses
402AlignmentFromAssumptionsPass::run(Function &F, FunctionAnalysisManager &AM) {
403
Daniel Jasperaec2fa32016-12-19 08:22:17 +0000404 AssumptionCache &AC = AM.getResult<AssumptionAnalysis>(F);
Sean Silvaa4c2d152016-06-15 06:18:01 +0000405 ScalarEvolution &SE = AM.getResult<ScalarEvolutionAnalysis>(F);
406 DominatorTree &DT = AM.getResult<DominatorTreeAnalysis>(F);
Chandler Carruth6acdca72017-01-24 12:55:57 +0000407 if (!runImpl(F, AC, &SE, &DT))
Sean Silvaa4c2d152016-06-15 06:18:01 +0000408 return PreservedAnalyses::all();
Chandler Carruthca68a3e2017-01-15 06:32:49 +0000409
Sean Silvaa4c2d152016-06-15 06:18:01 +0000410 PreservedAnalyses PA;
Chandler Carruthca68a3e2017-01-15 06:32:49 +0000411 PA.preserveSet<CFGAnalyses>();
Sean Silvaa4c2d152016-06-15 06:18:01 +0000412 PA.preserve<AAManager>();
413 PA.preserve<ScalarEvolutionAnalysis>();
414 PA.preserve<GlobalsAA>();
Sean Silvaa4c2d152016-06-15 06:18:01 +0000415 return PA;
416}