ARM64: Range based for loop in ARM64PromoteConstant pass
[oota-llvm.git] / lib / Target / ARM64 / ARM64PromoteConstant.cpp
1
2 //===-- ARM64PromoteConstant.cpp --- Promote constant to global for ARM64 -===//
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 the ARM64PromoteConstant pass which promotes constants
12 // to global variables when this is likely to be more efficient. Currently only
13 // types related to constant vector (i.e., constant vector, array of constant
14 // vectors, constant structure with a constant vector field, etc.) are promoted
15 // to global variables. Constant vectors are likely to be lowered in target
16 // constant pool during instruction selection already; therefore, the access
17 // will remain the same (memory load), but the structure types are not split
18 // into different constant pool accesses for each field. A bonus side effect is
19 // that created globals may be merged by the global merge pass.
20 //
21 // FIXME: This pass may be useful for other targets too.
22 //===----------------------------------------------------------------------===//
23
24 #define DEBUG_TYPE "arm64-promote-const"
25 #include "ARM64.h"
26 #include "llvm/ADT/Statistic.h"
27 #include "llvm/ADT/DenseMap.h"
28 #include "llvm/ADT/SmallSet.h"
29 #include "llvm/ADT/SmallVector.h"
30 #include "llvm/IR/Constants.h"
31 #include "llvm/IR/Dominators.h"
32 #include "llvm/IR/Function.h"
33 #include "llvm/IR/GlobalVariable.h"
34 #include "llvm/IR/InlineAsm.h"
35 #include "llvm/IR/Instructions.h"
36 #include "llvm/IR/IntrinsicInst.h"
37 #include "llvm/IR/IRBuilder.h"
38 #include "llvm/IR/Module.h"
39 #include "llvm/Pass.h"
40 #include "llvm/Support/CommandLine.h"
41 #include "llvm/Support/Debug.h"
42
43 using namespace llvm;
44
45 // Stress testing mode - disable heuristics.
46 static cl::opt<bool> Stress("arm64-stress-promote-const", cl::Hidden,
47                             cl::desc("Promote all vector constants"));
48
49 STATISTIC(NumPromoted, "Number of promoted constants");
50 STATISTIC(NumPromotedUses, "Number of promoted constants uses");
51
52 //===----------------------------------------------------------------------===//
53 //                       ARM64PromoteConstant
54 //===----------------------------------------------------------------------===//
55
56 namespace {
57 /// Promotes interesting constant into global variables.
58 /// The motivating example is:
59 /// static const uint16_t TableA[32] = {
60 ///   41944, 40330, 38837, 37450, 36158, 34953, 33826, 32768,
61 ///   31776, 30841, 29960, 29128, 28340, 27595, 26887, 26215,
62 ///   25576, 24967, 24386, 23832, 23302, 22796, 22311, 21846,
63 ///   21400, 20972, 20561, 20165, 19785, 19419, 19066, 18725,
64 /// };
65 ///
66 /// uint8x16x4_t LoadStatic(void) {
67 ///   uint8x16x4_t ret;
68 ///   ret.val[0] = vld1q_u16(TableA +  0);
69 ///   ret.val[1] = vld1q_u16(TableA +  8);
70 ///   ret.val[2] = vld1q_u16(TableA + 16);
71 ///   ret.val[3] = vld1q_u16(TableA + 24);
72 ///   return ret;
73 /// }
74 ///
75 /// The constants in that example are folded into the uses. Thus, 4 different
76 /// constants are created.
77 /// As their type is vector the cheapest way to create them is to load them
78 /// for the memory.
79 /// Therefore the final assembly final has 4 different load.
80 /// With this pass enabled, only one load is issued for the constants.
81 class ARM64PromoteConstant : public ModulePass {
82
83 public:
84   static char ID;
85   ARM64PromoteConstant() : ModulePass(ID) {}
86
87   virtual const char *getPassName() const { return "ARM64 Promote Constant"; }
88
89   /// Iterate over the functions and promote the interesting constants into
90   /// global variables with module scope.
91   bool runOnModule(Module &M) {
92     DEBUG(dbgs() << getPassName() << '\n');
93     bool Changed = false;
94     for (auto &MF : M) {
95       Changed |= runOnFunction(MF);
96     }
97     return Changed;
98   }
99
100 private:
101   /// Look for interesting constants used within the given function.
102   /// Promote them into global variables, load these global variables within
103   /// the related function, so that the number of inserted load is minimal.
104   bool runOnFunction(Function &F);
105
106   // This transformation requires dominator info
107   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
108     AU.setPreservesCFG();
109     AU.addRequired<DominatorTreeWrapperPass>();
110     AU.addPreserved<DominatorTreeWrapperPass>();
111   }
112
113   /// Type to store a list of User
114   typedef SmallVector<Value::user_iterator, 4> Users;
115   /// Map an insertion point to all the uses it dominates.
116   typedef DenseMap<Instruction *, Users> InsertionPoints;
117   /// Map a function to the required insertion point of load for a
118   /// global variable
119   typedef DenseMap<Function *, InsertionPoints> InsertionPointsPerFunc;
120
121   /// Find the closest point that dominates the given Use.
122   Instruction *findInsertionPoint(Value::user_iterator &Use);
123
124   /// Check if the given insertion point is dominated by an existing
125   /// insertion point.
126   /// If true, the given use is added to the list of dominated uses for
127   /// the related existing point.
128   /// \param NewPt the insertion point to be checked
129   /// \param UseIt the use to be added into the list of dominated uses
130   /// \param InsertPts existing insertion points
131   /// \pre NewPt and all instruction in InsertPts belong to the same function
132   /// \return true if one of the insertion point in InsertPts dominates NewPt,
133   ///         false otherwise
134   bool isDominated(Instruction *NewPt, Value::user_iterator &UseIt,
135                    InsertionPoints &InsertPts);
136
137   /// Check if the given insertion point can be merged with an existing
138   /// insertion point in a common dominator.
139   /// If true, the given use is added to the list of the created insertion
140   /// point.
141   /// \param NewPt the insertion point to be checked
142   /// \param UseIt the use to be added into the list of dominated uses
143   /// \param InsertPts existing insertion points
144   /// \pre NewPt and all instruction in InsertPts belong to the same function
145   /// \pre isDominated returns false for the exact same parameters.
146   /// \return true if it exists an insertion point in InsertPts that could
147   ///         have been merged with NewPt in a common dominator,
148   ///         false otherwise
149   bool tryAndMerge(Instruction *NewPt, Value::user_iterator &UseIt,
150                    InsertionPoints &InsertPts);
151
152   /// Compute the minimal insertion points to dominates all the interesting
153   /// uses of value.
154   /// Insertion points are group per function and each insertion point
155   /// contains a list of all the uses it dominates within the related function
156   /// \param Val constant to be examined
157   /// \param[out] InsPtsPerFunc output storage of the analysis
158   void computeInsertionPoints(Constant *Val,
159                               InsertionPointsPerFunc &InsPtsPerFunc);
160
161   /// Insert a definition of a new global variable at each point contained in
162   /// InsPtsPerFunc and update the related uses (also contained in
163   /// InsPtsPerFunc).
164   bool insertDefinitions(Constant *Cst, InsertionPointsPerFunc &InsPtsPerFunc);
165
166   /// Compute the minimal insertion points to dominate all the interesting
167   /// uses of Val and insert a definition of a new global variable
168   /// at these points.
169   /// Also update the uses of Val accordingly.
170   /// Currently a use of Val is considered interesting if:
171   /// - Val is not UndefValue
172   /// - Val is not zeroinitialized
173   /// - Replacing Val per a load of a global variable is valid.
174   /// \see shouldConvert for more details
175   bool computeAndInsertDefinitions(Constant *Val);
176
177   /// Promote the given constant into a global variable if it is expected to
178   /// be profitable.
179   /// \return true if Cst has been promoted
180   bool promoteConstant(Constant *Cst);
181
182   /// Transfer the list of dominated uses of IPI to NewPt in InsertPts.
183   /// Append UseIt to this list and delete the entry of IPI in InsertPts.
184   static void appendAndTransferDominatedUses(Instruction *NewPt,
185                                              Value::user_iterator &UseIt,
186                                              InsertionPoints::iterator &IPI,
187                                              InsertionPoints &InsertPts) {
188     // Record the dominated use
189     IPI->second.push_back(UseIt);
190     // Transfer the dominated uses of IPI to NewPt
191     // Inserting into the DenseMap may invalidate existing iterator.
192     // Keep a copy of the key to find the iterator to erase.
193     Instruction *OldInstr = IPI->first;
194     InsertPts.insert(InsertionPoints::value_type(NewPt, IPI->second));
195     // Erase IPI
196     IPI = InsertPts.find(OldInstr);
197     InsertPts.erase(IPI);
198   }
199 };
200 } // end anonymous namespace
201
202 char ARM64PromoteConstant::ID = 0;
203
204 namespace llvm {
205 void initializeARM64PromoteConstantPass(PassRegistry &);
206 }
207
208 INITIALIZE_PASS_BEGIN(ARM64PromoteConstant, "arm64-promote-const",
209                       "ARM64 Promote Constant Pass", false, false)
210 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
211 INITIALIZE_PASS_END(ARM64PromoteConstant, "arm64-promote-const",
212                     "ARM64 Promote Constant Pass", false, false)
213
214 ModulePass *llvm::createARM64PromoteConstantPass() {
215   return new ARM64PromoteConstant();
216 }
217
218 /// Check if the given type uses a vector type.
219 static bool isConstantUsingVectorTy(const Type *CstTy) {
220   if (CstTy->isVectorTy())
221     return true;
222   if (CstTy->isStructTy()) {
223     for (unsigned EltIdx = 0, EndEltIdx = CstTy->getStructNumElements();
224          EltIdx < EndEltIdx; ++EltIdx)
225       if (isConstantUsingVectorTy(CstTy->getStructElementType(EltIdx)))
226         return true;
227   } else if (CstTy->isArrayTy())
228     return isConstantUsingVectorTy(CstTy->getArrayElementType());
229   return false;
230 }
231
232 /// Check if the given use (Instruction + OpIdx) of Cst should be converted into
233 /// a load of a global variable initialized with Cst.
234 /// A use should be converted if it is legal to do so.
235 /// For instance, it is not legal to turn the mask operand of a shuffle vector
236 /// into a load of a global variable.
237 static bool shouldConvertUse(const Constant *Cst, const Instruction *Instr,
238                              unsigned OpIdx) {
239   // shufflevector instruction expects a const for the mask argument, i.e., the
240   // third argument. Do not promote this use in that case.
241   if (isa<const ShuffleVectorInst>(Instr) && OpIdx == 2)
242     return false;
243
244   // extractvalue instruction expects a const idx
245   if (isa<const ExtractValueInst>(Instr) && OpIdx > 0)
246     return false;
247
248   // extractvalue instruction expects a const idx
249   if (isa<const InsertValueInst>(Instr) && OpIdx > 1)
250     return false;
251
252   if (isa<const AllocaInst>(Instr) && OpIdx > 0)
253     return false;
254
255   // Alignment argument must be constant
256   if (isa<const LoadInst>(Instr) && OpIdx > 0)
257     return false;
258
259   // Alignment argument must be constant
260   if (isa<const StoreInst>(Instr) && OpIdx > 1)
261     return false;
262
263   // Index must be constant
264   if (isa<const GetElementPtrInst>(Instr) && OpIdx > 0)
265     return false;
266
267   // Personality function and filters must be constant.
268   // Give up on that instruction.
269   if (isa<const LandingPadInst>(Instr))
270     return false;
271
272   // switch instruction expects constants to compare to
273   if (isa<const SwitchInst>(Instr))
274     return false;
275
276   // Expected address must be a constant
277   if (isa<const IndirectBrInst>(Instr))
278     return false;
279
280   // Do not mess with intrinsic
281   if (isa<const IntrinsicInst>(Instr))
282     return false;
283
284   // Do not mess with inline asm
285   const CallInst *CI = dyn_cast<const CallInst>(Instr);
286   if (CI && isa<const InlineAsm>(CI->getCalledValue()))
287     return false;
288
289   return true;
290 }
291
292 /// Check if the given Cst should be converted into
293 /// a load of a global variable initialized with Cst.
294 /// A constant should be converted if it is likely that the materialization of
295 /// the constant will be tricky. Thus, we give up on zero or undef values.
296 ///
297 /// \todo Currently, accept only vector related types.
298 /// Also we give up on all simple vector type to keep the existing
299 /// behavior. Otherwise, we should push here all the check of the lowering of
300 /// BUILD_VECTOR. By giving up, we lose the potential benefit of merging
301 /// constant via global merge and the fact that the same constant is stored
302 /// only once with this method (versus, as many function that uses the constant
303 /// for the regular approach, even for float).
304 /// Again, the simplest solution would be to promote every
305 /// constant and rematerialize them when they are actually cheap to create.
306 static bool shouldConvert(const Constant *Cst) {
307   if (isa<const UndefValue>(Cst))
308     return false;
309
310   // FIXME: In some cases, it may be interesting to promote in memory
311   // a zero initialized constant.
312   // E.g., when the type of Cst require more instructions than the
313   // adrp/add/load sequence or when this sequence can be shared by several
314   // instances of Cst.
315   // Ideally, we could promote this into a global and rematerialize the constant
316   // when it was a bad idea.
317   if (Cst->isZeroValue())
318     return false;
319
320   if (Stress)
321     return true;
322
323   // FIXME: see function \todo
324   if (Cst->getType()->isVectorTy())
325     return false;
326   return isConstantUsingVectorTy(Cst->getType());
327 }
328
329 Instruction *
330 ARM64PromoteConstant::findInsertionPoint(Value::user_iterator &Use) {
331   // If this user is a phi, the insertion point is in the related
332   // incoming basic block
333   PHINode *PhiInst = dyn_cast<PHINode>(*Use);
334   Instruction *InsertionPoint;
335   if (PhiInst)
336     InsertionPoint =
337         PhiInst->getIncomingBlock(Use.getOperandNo())->getTerminator();
338   else
339     InsertionPoint = dyn_cast<Instruction>(*Use);
340   assert(InsertionPoint && "User is not an instruction!");
341   return InsertionPoint;
342 }
343
344 bool ARM64PromoteConstant::isDominated(Instruction *NewPt,
345                                        Value::user_iterator &UseIt,
346                                        InsertionPoints &InsertPts) {
347
348   DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>(
349       *NewPt->getParent()->getParent()).getDomTree();
350
351   // Traverse all the existing insertion point and check if one is dominating
352   // NewPt
353   for (auto &IPI : InsertPts) {
354     if (NewPt == IPI.first || DT.dominates(IPI.first, NewPt) ||
355         // When IPI.first is a terminator instruction, DT may think that
356         // the result is defined on the edge.
357         // Here we are testing the insertion point, not the definition.
358         (IPI.first->getParent() != NewPt->getParent() &&
359          DT.dominates(IPI.first->getParent(), NewPt->getParent()))) {
360       // No need to insert this point
361       // Record the dominated use
362       DEBUG(dbgs() << "Insertion point dominated by:\n");
363       DEBUG(IPI.first->print(dbgs()));
364       DEBUG(dbgs() << '\n');
365       IPI.second.push_back(UseIt);
366       return true;
367     }
368   }
369   return false;
370 }
371
372 bool ARM64PromoteConstant::tryAndMerge(Instruction *NewPt,
373                                        Value::user_iterator &UseIt,
374                                        InsertionPoints &InsertPts) {
375   DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>(
376       *NewPt->getParent()->getParent()).getDomTree();
377   BasicBlock *NewBB = NewPt->getParent();
378
379   // Traverse all the existing insertion point and check if one is dominated by
380   // NewPt and thus useless or can be combined with NewPt into a common
381   // dominator
382   for (InsertionPoints::iterator IPI = InsertPts.begin(),
383                                  EndIPI = InsertPts.end();
384        IPI != EndIPI; ++IPI) {
385     BasicBlock *CurBB = IPI->first->getParent();
386     if (NewBB == CurBB) {
387       // Instructions are in the same block.
388       // By construction, NewPt is dominating the other.
389       // Indeed, isDominated returned false with the exact same arguments.
390       DEBUG(dbgs() << "Merge insertion point with:\n");
391       DEBUG(IPI->first->print(dbgs()));
392       DEBUG(dbgs() << "\nat considered insertion point.\n");
393       appendAndTransferDominatedUses(NewPt, UseIt, IPI, InsertPts);
394       return true;
395     }
396
397     // Look for a common dominator
398     BasicBlock *CommonDominator = DT.findNearestCommonDominator(NewBB, CurBB);
399     // If none exists, we cannot merge these two points
400     if (!CommonDominator)
401       continue;
402
403     if (CommonDominator != NewBB) {
404       // By construction, the CommonDominator cannot be CurBB
405       assert(CommonDominator != CurBB &&
406              "Instruction has not been rejected during isDominated check!");
407       // Take the last instruction of the CommonDominator as insertion point
408       NewPt = CommonDominator->getTerminator();
409     }
410     // else, CommonDominator is the block of NewBB, hence NewBB is the last
411     // possible insertion point in that block
412     DEBUG(dbgs() << "Merge insertion point with:\n");
413     DEBUG(IPI->first->print(dbgs()));
414     DEBUG(dbgs() << '\n');
415     DEBUG(NewPt->print(dbgs()));
416     DEBUG(dbgs() << '\n');
417     appendAndTransferDominatedUses(NewPt, UseIt, IPI, InsertPts);
418     return true;
419   }
420   return false;
421 }
422
423 void ARM64PromoteConstant::computeInsertionPoints(
424     Constant *Val, InsertionPointsPerFunc &InsPtsPerFunc) {
425   DEBUG(dbgs() << "** Compute insertion points **\n");
426   for (Value::user_iterator UseIt = Val->user_begin(),
427                             EndUseIt = Val->user_end();
428        UseIt != EndUseIt; ++UseIt) {
429     // If the user is not an Instruction, we cannot modify it
430     if (!isa<Instruction>(*UseIt))
431       continue;
432
433     // Filter out uses that should not be converted
434     if (!shouldConvertUse(Val, cast<Instruction>(*UseIt), UseIt.getOperandNo()))
435       continue;
436
437     DEBUG(dbgs() << "Considered use, opidx " << UseIt.getOperandNo() << ":\n");
438     DEBUG((*UseIt)->print(dbgs()));
439     DEBUG(dbgs() << '\n');
440
441     Instruction *InsertionPoint = findInsertionPoint(UseIt);
442
443     DEBUG(dbgs() << "Considered insertion point:\n");
444     DEBUG(InsertionPoint->print(dbgs()));
445     DEBUG(dbgs() << '\n');
446
447     // Check if the current insertion point is useless, i.e., it is dominated
448     // by another one.
449     InsertionPoints &InsertPts =
450         InsPtsPerFunc[InsertionPoint->getParent()->getParent()];
451     if (isDominated(InsertionPoint, UseIt, InsertPts))
452       continue;
453     // This insertion point is useful, check if we can merge some insertion
454     // point in a common dominator or if NewPt dominates an existing one.
455     if (tryAndMerge(InsertionPoint, UseIt, InsertPts))
456       continue;
457
458     DEBUG(dbgs() << "Keep considered insertion point\n");
459
460     // It is definitely useful by its own
461     InsertPts[InsertionPoint].push_back(UseIt);
462   }
463 }
464
465 bool
466 ARM64PromoteConstant::insertDefinitions(Constant *Cst,
467                                         InsertionPointsPerFunc &InsPtsPerFunc) {
468   // We will create one global variable per Module
469   DenseMap<Module *, GlobalVariable *> ModuleToMergedGV;
470   bool HasChanged = false;
471
472   // Traverse all insertion points in all the function
473   for (InsertionPointsPerFunc::iterator FctToInstPtsIt = InsPtsPerFunc.begin(),
474                                         EndIt = InsPtsPerFunc.end();
475        FctToInstPtsIt != EndIt; ++FctToInstPtsIt) {
476     InsertionPoints &InsertPts = FctToInstPtsIt->second;
477 // Do more check for debug purposes
478 #ifndef NDEBUG
479     DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>(
480         *FctToInstPtsIt->first).getDomTree();
481 #endif
482     GlobalVariable *PromotedGV;
483     assert(!InsertPts.empty() && "Empty uses does not need a definition");
484
485     Module *M = FctToInstPtsIt->first->getParent();
486     DenseMap<Module *, GlobalVariable *>::iterator MapIt =
487         ModuleToMergedGV.find(M);
488     if (MapIt == ModuleToMergedGV.end()) {
489       PromotedGV = new GlobalVariable(
490           *M, Cst->getType(), true, GlobalValue::InternalLinkage, 0,
491           "_PromotedConst", 0, GlobalVariable::NotThreadLocal);
492       PromotedGV->setInitializer(Cst);
493       ModuleToMergedGV[M] = PromotedGV;
494       DEBUG(dbgs() << "Global replacement: ");
495       DEBUG(PromotedGV->print(dbgs()));
496       DEBUG(dbgs() << '\n');
497       ++NumPromoted;
498       HasChanged = true;
499     } else {
500       PromotedGV = MapIt->second;
501     }
502
503     for (InsertionPoints::iterator IPI = InsertPts.begin(),
504                                    EndIPI = InsertPts.end();
505          IPI != EndIPI; ++IPI) {
506       // Create the load of the global variable
507       IRBuilder<> Builder(IPI->first->getParent(), IPI->first);
508       LoadInst *LoadedCst = Builder.CreateLoad(PromotedGV);
509       DEBUG(dbgs() << "**********\n");
510       DEBUG(dbgs() << "New def: ");
511       DEBUG(LoadedCst->print(dbgs()));
512       DEBUG(dbgs() << '\n');
513
514       // Update the dominated uses
515       Users &DominatedUsers = IPI->second;
516       for (Users::iterator UseIt = DominatedUsers.begin(),
517                            EndIt = DominatedUsers.end();
518            UseIt != EndIt; ++UseIt) {
519 #ifndef NDEBUG
520         assert((DT.dominates(LoadedCst, cast<Instruction>(**UseIt)) ||
521                 (isa<PHINode>(**UseIt) &&
522                  DT.dominates(LoadedCst, findInsertionPoint(*UseIt)))) &&
523                "Inserted definition does not dominate all its uses!");
524 #endif
525         DEBUG(dbgs() << "Use to update " << UseIt->getOperandNo() << ":");
526         DEBUG((*UseIt)->print(dbgs()));
527         DEBUG(dbgs() << '\n');
528         (*UseIt)->setOperand(UseIt->getOperandNo(), LoadedCst);
529         ++NumPromotedUses;
530       }
531     }
532   }
533   return HasChanged;
534 }
535
536 bool ARM64PromoteConstant::computeAndInsertDefinitions(Constant *Val) {
537   InsertionPointsPerFunc InsertPtsPerFunc;
538   computeInsertionPoints(Val, InsertPtsPerFunc);
539   return insertDefinitions(Val, InsertPtsPerFunc);
540 }
541
542 bool ARM64PromoteConstant::promoteConstant(Constant *Cst) {
543   assert(Cst && "Given variable is not a valid constant.");
544
545   if (!shouldConvert(Cst))
546     return false;
547
548   DEBUG(dbgs() << "******************************\n");
549   DEBUG(dbgs() << "Candidate constant: ");
550   DEBUG(Cst->print(dbgs()));
551   DEBUG(dbgs() << '\n');
552
553   return computeAndInsertDefinitions(Cst);
554 }
555
556 bool ARM64PromoteConstant::runOnFunction(Function &F) {
557   // Look for instructions using constant vector
558   // Promote that constant to a global variable.
559   // Create as few load of this variable as possible and update the uses
560   // accordingly
561   bool LocalChange = false;
562   SmallSet<Constant *, 8> AlreadyChecked;
563
564   for (auto &MBB : F) {
565     for (auto &MI : MBB) {
566       // Traverse the operand, looking for constant vectors
567       // Replace them by a load of a global variable of type constant vector
568       for (unsigned OpIdx = 0, EndOpIdx = MI.getNumOperands();
569            OpIdx != EndOpIdx; ++OpIdx) {
570         Constant *Cst = dyn_cast<Constant>(MI.getOperand(OpIdx));
571         // There is no point is promoting global value, they are already global.
572         // Do not promote constant expression, as they may require some code
573         // expansion.
574         if (Cst && !isa<GlobalValue>(Cst) && !isa<ConstantExpr>(Cst) &&
575             AlreadyChecked.insert(Cst))
576           LocalChange |= promoteConstant(Cst);
577       }
578     }
579   }
580   return LocalChange;
581 }