LoopVectorizationLegality.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. //===- LoopVectorizationLegality.cpp --------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file provides loop vectorization legality analysis. Original code
  11. // resided in LoopVectorize.cpp for a long time.
  12. //
  13. // At this point, it is implemented as a utility class, not as an analysis
  14. // pass. It should be easy to create an analysis pass around it if there
  15. // is a need (but D45420 needs to happen first).
  16. //
  17. #include "llvm/Transforms/Vectorize/LoopVectorizationLegality.h"
  18. #include "llvm/Analysis/VectorUtils.h"
  19. #include "llvm/IR/IntrinsicInst.h"
  20. using namespace llvm;
  21. #define LV_NAME "loop-vectorize"
  22. #define DEBUG_TYPE LV_NAME
  23. static cl::opt<bool>
  24. EnableIfConversion("enable-if-conversion", cl::init(true), cl::Hidden,
  25. cl::desc("Enable if-conversion during vectorization."));
  26. static cl::opt<unsigned> PragmaVectorizeMemoryCheckThreshold(
  27. "pragma-vectorize-memory-check-threshold", cl::init(128), cl::Hidden,
  28. cl::desc("The maximum allowed number of runtime memory checks with a "
  29. "vectorize(enable) pragma."));
  30. static cl::opt<unsigned> VectorizeSCEVCheckThreshold(
  31. "vectorize-scev-check-threshold", cl::init(16), cl::Hidden,
  32. cl::desc("The maximum number of SCEV checks allowed."));
  33. static cl::opt<unsigned> PragmaVectorizeSCEVCheckThreshold(
  34. "pragma-vectorize-scev-check-threshold", cl::init(128), cl::Hidden,
  35. cl::desc("The maximum number of SCEV checks allowed with a "
  36. "vectorize(enable) pragma"));
  37. /// Maximum vectorization interleave count.
  38. static const unsigned MaxInterleaveFactor = 16;
  39. namespace llvm {
  40. OptimizationRemarkAnalysis createLVMissedAnalysis(const char *PassName,
  41. StringRef RemarkName,
  42. Loop *TheLoop,
  43. Instruction *I) {
  44. Value *CodeRegion = TheLoop->getHeader();
  45. DebugLoc DL = TheLoop->getStartLoc();
  46. if (I) {
  47. CodeRegion = I->getParent();
  48. // If there is no debug location attached to the instruction, revert back to
  49. // using the loop's.
  50. if (I->getDebugLoc())
  51. DL = I->getDebugLoc();
  52. }
  53. OptimizationRemarkAnalysis R(PassName, RemarkName, DL, CodeRegion);
  54. R << "loop not vectorized: ";
  55. return R;
  56. }
  57. bool LoopVectorizeHints::Hint::validate(unsigned Val) {
  58. switch (Kind) {
  59. case HK_WIDTH:
  60. return isPowerOf2_32(Val) && Val <= VectorizerParams::MaxVectorWidth;
  61. case HK_UNROLL:
  62. return isPowerOf2_32(Val) && Val <= MaxInterleaveFactor;
  63. case HK_FORCE:
  64. return (Val <= 1);
  65. case HK_ISVECTORIZED:
  66. return (Val == 0 || Val == 1);
  67. }
  68. return false;
  69. }
  70. LoopVectorizeHints::LoopVectorizeHints(const Loop *L, bool DisableInterleaving,
  71. OptimizationRemarkEmitter &ORE)
  72. : Width("vectorize.width", VectorizerParams::VectorizationFactor, HK_WIDTH),
  73. Interleave("interleave.count", DisableInterleaving, HK_UNROLL),
  74. Force("vectorize.enable", FK_Undefined, HK_FORCE),
  75. IsVectorized("isvectorized", 0, HK_ISVECTORIZED), TheLoop(L), ORE(ORE) {
  76. // Populate values with existing loop metadata.
  77. getHintsFromMetadata();
  78. // force-vector-interleave overrides DisableInterleaving.
  79. if (VectorizerParams::isInterleaveForced())
  80. Interleave.Value = VectorizerParams::VectorizationInterleave;
  81. if (IsVectorized.Value != 1)
  82. // If the vectorization width and interleaving count are both 1 then
  83. // consider the loop to have been already vectorized because there's
  84. // nothing more that we can do.
  85. IsVectorized.Value = Width.Value == 1 && Interleave.Value == 1;
  86. LLVM_DEBUG(if (DisableInterleaving && Interleave.Value == 1) dbgs()
  87. << "LV: Interleaving disabled by the pass manager\n");
  88. }
  89. bool LoopVectorizeHints::allowVectorization(Function *F, Loop *L,
  90. bool AlwaysVectorize) const {
  91. if (getForce() == LoopVectorizeHints::FK_Disabled) {
  92. LLVM_DEBUG(dbgs() << "LV: Not vectorizing: #pragma vectorize disable.\n");
  93. emitRemarkWithHints();
  94. return false;
  95. }
  96. if (!AlwaysVectorize && getForce() != LoopVectorizeHints::FK_Enabled) {
  97. LLVM_DEBUG(dbgs() << "LV: Not vectorizing: No #pragma vectorize enable.\n");
  98. emitRemarkWithHints();
  99. return false;
  100. }
  101. if (getIsVectorized() == 1) {
  102. LLVM_DEBUG(dbgs() << "LV: Not vectorizing: Disabled/already vectorized.\n");
  103. // FIXME: Add interleave.disable metadata. This will allow
  104. // vectorize.disable to be used without disabling the pass and errors
  105. // to differentiate between disabled vectorization and a width of 1.
  106. ORE.emit([&]() {
  107. return OptimizationRemarkAnalysis(vectorizeAnalysisPassName(),
  108. "AllDisabled", L->getStartLoc(),
  109. L->getHeader())
  110. << "loop not vectorized: vectorization and interleaving are "
  111. "explicitly disabled, or the loop has already been "
  112. "vectorized";
  113. });
  114. return false;
  115. }
  116. return true;
  117. }
  118. void LoopVectorizeHints::emitRemarkWithHints() const {
  119. using namespace ore;
  120. ORE.emit([&]() {
  121. if (Force.Value == LoopVectorizeHints::FK_Disabled)
  122. return OptimizationRemarkMissed(LV_NAME, "MissedExplicitlyDisabled",
  123. TheLoop->getStartLoc(),
  124. TheLoop->getHeader())
  125. << "loop not vectorized: vectorization is explicitly disabled";
  126. else {
  127. OptimizationRemarkMissed R(LV_NAME, "MissedDetails",
  128. TheLoop->getStartLoc(), TheLoop->getHeader());
  129. R << "loop not vectorized";
  130. if (Force.Value == LoopVectorizeHints::FK_Enabled) {
  131. R << " (Force=" << NV("Force", true);
  132. if (Width.Value != 0)
  133. R << ", Vector Width=" << NV("VectorWidth", Width.Value);
  134. if (Interleave.Value != 0)
  135. R << ", Interleave Count=" << NV("InterleaveCount", Interleave.Value);
  136. R << ")";
  137. }
  138. return R;
  139. }
  140. });
  141. }
  142. const char *LoopVectorizeHints::vectorizeAnalysisPassName() const {
  143. if (getWidth() == 1)
  144. return LV_NAME;
  145. if (getForce() == LoopVectorizeHints::FK_Disabled)
  146. return LV_NAME;
  147. if (getForce() == LoopVectorizeHints::FK_Undefined && getWidth() == 0)
  148. return LV_NAME;
  149. return OptimizationRemarkAnalysis::AlwaysPrint;
  150. }
  151. void LoopVectorizeHints::getHintsFromMetadata() {
  152. MDNode *LoopID = TheLoop->getLoopID();
  153. if (!LoopID)
  154. return;
  155. // First operand should refer to the loop id itself.
  156. assert(LoopID->getNumOperands() > 0 && "requires at least one operand");
  157. assert(LoopID->getOperand(0) == LoopID && "invalid loop id");
  158. for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) {
  159. const MDString *S = nullptr;
  160. SmallVector<Metadata *, 4> Args;
  161. // The expected hint is either a MDString or a MDNode with the first
  162. // operand a MDString.
  163. if (const MDNode *MD = dyn_cast<MDNode>(LoopID->getOperand(i))) {
  164. if (!MD || MD->getNumOperands() == 0)
  165. continue;
  166. S = dyn_cast<MDString>(MD->getOperand(0));
  167. for (unsigned i = 1, ie = MD->getNumOperands(); i < ie; ++i)
  168. Args.push_back(MD->getOperand(i));
  169. } else {
  170. S = dyn_cast<MDString>(LoopID->getOperand(i));
  171. assert(Args.size() == 0 && "too many arguments for MDString");
  172. }
  173. if (!S)
  174. continue;
  175. // Check if the hint starts with the loop metadata prefix.
  176. StringRef Name = S->getString();
  177. if (Args.size() == 1)
  178. setHint(Name, Args[0]);
  179. }
  180. }
  181. void LoopVectorizeHints::setHint(StringRef Name, Metadata *Arg) {
  182. if (!Name.startswith(Prefix()))
  183. return;
  184. Name = Name.substr(Prefix().size(), StringRef::npos);
  185. const ConstantInt *C = mdconst::dyn_extract<ConstantInt>(Arg);
  186. if (!C)
  187. return;
  188. unsigned Val = C->getZExtValue();
  189. Hint *Hints[] = {&Width, &Interleave, &Force, &IsVectorized};
  190. for (auto H : Hints) {
  191. if (Name == H->Name) {
  192. if (H->validate(Val))
  193. H->Value = Val;
  194. else
  195. LLVM_DEBUG(dbgs() << "LV: ignoring invalid hint '" << Name << "'\n");
  196. break;
  197. }
  198. }
  199. }
  200. MDNode *LoopVectorizeHints::createHintMetadata(StringRef Name,
  201. unsigned V) const {
  202. LLVMContext &Context = TheLoop->getHeader()->getContext();
  203. Metadata *MDs[] = {
  204. MDString::get(Context, Name),
  205. ConstantAsMetadata::get(ConstantInt::get(Type::getInt32Ty(Context), V))};
  206. return MDNode::get(Context, MDs);
  207. }
  208. bool LoopVectorizeHints::matchesHintMetadataName(MDNode *Node,
  209. ArrayRef<Hint> HintTypes) {
  210. MDString *Name = dyn_cast<MDString>(Node->getOperand(0));
  211. if (!Name)
  212. return false;
  213. for (auto H : HintTypes)
  214. if (Name->getString().endswith(H.Name))
  215. return true;
  216. return false;
  217. }
  218. void LoopVectorizeHints::writeHintsToMetadata(ArrayRef<Hint> HintTypes) {
  219. if (HintTypes.empty())
  220. return;
  221. // Reserve the first element to LoopID (see below).
  222. SmallVector<Metadata *, 4> MDs(1);
  223. // If the loop already has metadata, then ignore the existing operands.
  224. MDNode *LoopID = TheLoop->getLoopID();
  225. if (LoopID) {
  226. for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) {
  227. MDNode *Node = cast<MDNode>(LoopID->getOperand(i));
  228. // If node in update list, ignore old value.
  229. if (!matchesHintMetadataName(Node, HintTypes))
  230. MDs.push_back(Node);
  231. }
  232. }
  233. // Now, add the missing hints.
  234. for (auto H : HintTypes)
  235. MDs.push_back(createHintMetadata(Twine(Prefix(), H.Name).str(), H.Value));
  236. // Replace current metadata node with new one.
  237. LLVMContext &Context = TheLoop->getHeader()->getContext();
  238. MDNode *NewLoopID = MDNode::get(Context, MDs);
  239. // Set operand 0 to refer to the loop id itself.
  240. NewLoopID->replaceOperandWith(0, NewLoopID);
  241. TheLoop->setLoopID(NewLoopID);
  242. }
  243. bool LoopVectorizationRequirements::doesNotMeet(
  244. Function *F, Loop *L, const LoopVectorizeHints &Hints) {
  245. const char *PassName = Hints.vectorizeAnalysisPassName();
  246. bool Failed = false;
  247. if (UnsafeAlgebraInst && !Hints.allowReordering()) {
  248. ORE.emit([&]() {
  249. return OptimizationRemarkAnalysisFPCommute(
  250. PassName, "CantReorderFPOps", UnsafeAlgebraInst->getDebugLoc(),
  251. UnsafeAlgebraInst->getParent())
  252. << "loop not vectorized: cannot prove it is safe to reorder "
  253. "floating-point operations";
  254. });
  255. Failed = true;
  256. }
  257. // Test if runtime memcheck thresholds are exceeded.
  258. bool PragmaThresholdReached =
  259. NumRuntimePointerChecks > PragmaVectorizeMemoryCheckThreshold;
  260. bool ThresholdReached =
  261. NumRuntimePointerChecks > VectorizerParams::RuntimeMemoryCheckThreshold;
  262. if ((ThresholdReached && !Hints.allowReordering()) ||
  263. PragmaThresholdReached) {
  264. ORE.emit([&]() {
  265. return OptimizationRemarkAnalysisAliasing(PassName, "CantReorderMemOps",
  266. L->getStartLoc(),
  267. L->getHeader())
  268. << "loop not vectorized: cannot prove it is safe to reorder "
  269. "memory operations";
  270. });
  271. LLVM_DEBUG(dbgs() << "LV: Too many memory checks needed.\n");
  272. Failed = true;
  273. }
  274. return Failed;
  275. }
  276. // Return true if the inner loop \p Lp is uniform with regard to the outer loop
  277. // \p OuterLp (i.e., if the outer loop is vectorized, all the vector lanes
  278. // executing the inner loop will execute the same iterations). This check is
  279. // very constrained for now but it will be relaxed in the future. \p Lp is
  280. // considered uniform if it meets all the following conditions:
  281. // 1) it has a canonical IV (starting from 0 and with stride 1),
  282. // 2) its latch terminator is a conditional branch and,
  283. // 3) its latch condition is a compare instruction whose operands are the
  284. // canonical IV and an OuterLp invariant.
  285. // This check doesn't take into account the uniformity of other conditions not
  286. // related to the loop latch because they don't affect the loop uniformity.
  287. //
  288. // NOTE: We decided to keep all these checks and its associated documentation
  289. // together so that we can easily have a picture of the current supported loop
  290. // nests. However, some of the current checks don't depend on \p OuterLp and
  291. // would be redundantly executed for each \p Lp if we invoked this function for
  292. // different candidate outer loops. This is not the case for now because we
  293. // don't currently have the infrastructure to evaluate multiple candidate outer
  294. // loops and \p OuterLp will be a fixed parameter while we only support explicit
  295. // outer loop vectorization. It's also very likely that these checks go away
  296. // before introducing the aforementioned infrastructure. However, if this is not
  297. // the case, we should move the \p OuterLp independent checks to a separate
  298. // function that is only executed once for each \p Lp.
  299. static bool isUniformLoop(Loop *Lp, Loop *OuterLp) {
  300. assert(Lp->getLoopLatch() && "Expected loop with a single latch.");
  301. // If Lp is the outer loop, it's uniform by definition.
  302. if (Lp == OuterLp)
  303. return true;
  304. assert(OuterLp->contains(Lp) && "OuterLp must contain Lp.");
  305. // 1.
  306. PHINode *IV = Lp->getCanonicalInductionVariable();
  307. if (!IV) {
  308. LLVM_DEBUG(dbgs() << "LV: Canonical IV not found.\n");
  309. return false;
  310. }
  311. // 2.
  312. BasicBlock *Latch = Lp->getLoopLatch();
  313. auto *LatchBr = dyn_cast<BranchInst>(Latch->getTerminator());
  314. if (!LatchBr || LatchBr->isUnconditional()) {
  315. LLVM_DEBUG(dbgs() << "LV: Unsupported loop latch branch.\n");
  316. return false;
  317. }
  318. // 3.
  319. auto *LatchCmp = dyn_cast<CmpInst>(LatchBr->getCondition());
  320. if (!LatchCmp) {
  321. LLVM_DEBUG(
  322. dbgs() << "LV: Loop latch condition is not a compare instruction.\n");
  323. return false;
  324. }
  325. Value *CondOp0 = LatchCmp->getOperand(0);
  326. Value *CondOp1 = LatchCmp->getOperand(1);
  327. Value *IVUpdate = IV->getIncomingValueForBlock(Latch);
  328. if (!(CondOp0 == IVUpdate && OuterLp->isLoopInvariant(CondOp1)) &&
  329. !(CondOp1 == IVUpdate && OuterLp->isLoopInvariant(CondOp0))) {
  330. LLVM_DEBUG(dbgs() << "LV: Loop latch condition is not uniform.\n");
  331. return false;
  332. }
  333. return true;
  334. }
  335. // Return true if \p Lp and all its nested loops are uniform with regard to \p
  336. // OuterLp.
  337. static bool isUniformLoopNest(Loop *Lp, Loop *OuterLp) {
  338. if (!isUniformLoop(Lp, OuterLp))
  339. return false;
  340. // Check if nested loops are uniform.
  341. for (Loop *SubLp : *Lp)
  342. if (!isUniformLoopNest(SubLp, OuterLp))
  343. return false;
  344. return true;
  345. }
  346. /// Check whether it is safe to if-convert this phi node.
  347. ///
  348. /// Phi nodes with constant expressions that can trap are not safe to if
  349. /// convert.
  350. static bool canIfConvertPHINodes(BasicBlock *BB) {
  351. for (PHINode &Phi : BB->phis()) {
  352. for (Value *V : Phi.incoming_values())
  353. if (auto *C = dyn_cast<Constant>(V))
  354. if (C->canTrap())
  355. return false;
  356. }
  357. return true;
  358. }
  359. static Type *convertPointerToIntegerType(const DataLayout &DL, Type *Ty) {
  360. if (Ty->isPointerTy())
  361. return DL.getIntPtrType(Ty);
  362. // It is possible that char's or short's overflow when we ask for the loop's
  363. // trip count, work around this by changing the type size.
  364. if (Ty->getScalarSizeInBits() < 32)
  365. return Type::getInt32Ty(Ty->getContext());
  366. return Ty;
  367. }
  368. static Type *getWiderType(const DataLayout &DL, Type *Ty0, Type *Ty1) {
  369. Ty0 = convertPointerToIntegerType(DL, Ty0);
  370. Ty1 = convertPointerToIntegerType(DL, Ty1);
  371. if (Ty0->getScalarSizeInBits() > Ty1->getScalarSizeInBits())
  372. return Ty0;
  373. return Ty1;
  374. }
  375. /// Check that the instruction has outside loop users and is not an
  376. /// identified reduction variable.
  377. static bool hasOutsideLoopUser(const Loop *TheLoop, Instruction *Inst,
  378. SmallPtrSetImpl<Value *> &AllowedExit) {
  379. // Reductions, Inductions and non-header phis are allowed to have exit users. All
  380. // other instructions must not have external users.
  381. if (!AllowedExit.count(Inst))
  382. // Check that all of the users of the loop are inside the BB.
  383. for (User *U : Inst->users()) {
  384. Instruction *UI = cast<Instruction>(U);
  385. // This user may be a reduction exit value.
  386. if (!TheLoop->contains(UI)) {
  387. LLVM_DEBUG(dbgs() << "LV: Found an outside user for : " << *UI << '\n');
  388. return true;
  389. }
  390. }
  391. return false;
  392. }
  393. int LoopVectorizationLegality::isConsecutivePtr(Value *Ptr) {
  394. const ValueToValueMap &Strides =
  395. getSymbolicStrides() ? *getSymbolicStrides() : ValueToValueMap();
  396. int Stride = getPtrStride(PSE, Ptr, TheLoop, Strides, true, false);
  397. if (Stride == 1 || Stride == -1)
  398. return Stride;
  399. return 0;
  400. }
  401. bool LoopVectorizationLegality::isUniform(Value *V) {
  402. return LAI->isUniform(V);
  403. }
  404. bool LoopVectorizationLegality::canVectorizeOuterLoop() {
  405. assert(!TheLoop->empty() && "We are not vectorizing an outer loop.");
  406. // Store the result and return it at the end instead of exiting early, in case
  407. // allowExtraAnalysis is used to report multiple reasons for not vectorizing.
  408. bool Result = true;
  409. bool DoExtraAnalysis = ORE->allowExtraAnalysis(DEBUG_TYPE);
  410. for (BasicBlock *BB : TheLoop->blocks()) {
  411. // Check whether the BB terminator is a BranchInst. Any other terminator is
  412. // not supported yet.
  413. auto *Br = dyn_cast<BranchInst>(BB->getTerminator());
  414. if (!Br) {
  415. LLVM_DEBUG(dbgs() << "LV: Unsupported basic block terminator.\n");
  416. ORE->emit(createMissedAnalysis("CFGNotUnderstood")
  417. << "loop control flow is not understood by vectorizer");
  418. if (DoExtraAnalysis)
  419. Result = false;
  420. else
  421. return false;
  422. }
  423. // Check whether the BranchInst is a supported one. Only unconditional
  424. // branches, conditional branches with an outer loop invariant condition or
  425. // backedges are supported.
  426. if (Br && Br->isConditional() &&
  427. !TheLoop->isLoopInvariant(Br->getCondition()) &&
  428. !LI->isLoopHeader(Br->getSuccessor(0)) &&
  429. !LI->isLoopHeader(Br->getSuccessor(1))) {
  430. LLVM_DEBUG(dbgs() << "LV: Unsupported conditional branch.\n");
  431. ORE->emit(createMissedAnalysis("CFGNotUnderstood")
  432. << "loop control flow is not understood by vectorizer");
  433. if (DoExtraAnalysis)
  434. Result = false;
  435. else
  436. return false;
  437. }
  438. }
  439. // Check whether inner loops are uniform. At this point, we only support
  440. // simple outer loops scenarios with uniform nested loops.
  441. if (!isUniformLoopNest(TheLoop /*loop nest*/,
  442. TheLoop /*context outer loop*/)) {
  443. LLVM_DEBUG(
  444. dbgs()
  445. << "LV: Not vectorizing: Outer loop contains divergent loops.\n");
  446. ORE->emit(createMissedAnalysis("CFGNotUnderstood")
  447. << "loop control flow is not understood by vectorizer");
  448. if (DoExtraAnalysis)
  449. Result = false;
  450. else
  451. return false;
  452. }
  453. return Result;
  454. }
  455. void LoopVectorizationLegality::addInductionPhi(
  456. PHINode *Phi, const InductionDescriptor &ID,
  457. SmallPtrSetImpl<Value *> &AllowedExit) {
  458. Inductions[Phi] = ID;
  459. // In case this induction also comes with casts that we know we can ignore
  460. // in the vectorized loop body, record them here. All casts could be recorded
  461. // here for ignoring, but suffices to record only the first (as it is the
  462. // only one that may bw used outside the cast sequence).
  463. const SmallVectorImpl<Instruction *> &Casts = ID.getCastInsts();
  464. if (!Casts.empty())
  465. InductionCastsToIgnore.insert(*Casts.begin());
  466. Type *PhiTy = Phi->getType();
  467. const DataLayout &DL = Phi->getModule()->getDataLayout();
  468. // Get the widest type.
  469. if (!PhiTy->isFloatingPointTy()) {
  470. if (!WidestIndTy)
  471. WidestIndTy = convertPointerToIntegerType(DL, PhiTy);
  472. else
  473. WidestIndTy = getWiderType(DL, PhiTy, WidestIndTy);
  474. }
  475. // Int inductions are special because we only allow one IV.
  476. if (ID.getKind() == InductionDescriptor::IK_IntInduction &&
  477. ID.getConstIntStepValue() && ID.getConstIntStepValue()->isOne() &&
  478. isa<Constant>(ID.getStartValue()) &&
  479. cast<Constant>(ID.getStartValue())->isNullValue()) {
  480. // Use the phi node with the widest type as induction. Use the last
  481. // one if there are multiple (no good reason for doing this other
  482. // than it is expedient). We've checked that it begins at zero and
  483. // steps by one, so this is a canonical induction variable.
  484. if (!PrimaryInduction || PhiTy == WidestIndTy)
  485. PrimaryInduction = Phi;
  486. }
  487. // Both the PHI node itself, and the "post-increment" value feeding
  488. // back into the PHI node may have external users.
  489. // We can allow those uses, except if the SCEVs we have for them rely
  490. // on predicates that only hold within the loop, since allowing the exit
  491. // currently means re-using this SCEV outside the loop (see PR33706 for more
  492. // details).
  493. if (PSE.getUnionPredicate().isAlwaysTrue()) {
  494. AllowedExit.insert(Phi);
  495. AllowedExit.insert(Phi->getIncomingValueForBlock(TheLoop->getLoopLatch()));
  496. }
  497. LLVM_DEBUG(dbgs() << "LV: Found an induction variable.\n");
  498. }
  499. bool LoopVectorizationLegality::canVectorizeInstrs() {
  500. BasicBlock *Header = TheLoop->getHeader();
  501. // Look for the attribute signaling the absence of NaNs.
  502. Function &F = *Header->getParent();
  503. HasFunNoNaNAttr =
  504. F.getFnAttribute("no-nans-fp-math").getValueAsString() == "true";
  505. // For each block in the loop.
  506. for (BasicBlock *BB : TheLoop->blocks()) {
  507. // Scan the instructions in the block and look for hazards.
  508. for (Instruction &I : *BB) {
  509. if (auto *Phi = dyn_cast<PHINode>(&I)) {
  510. Type *PhiTy = Phi->getType();
  511. // Check that this PHI type is allowed.
  512. if (!PhiTy->isIntegerTy() && !PhiTy->isFloatingPointTy() &&
  513. !PhiTy->isPointerTy()) {
  514. ORE->emit(createMissedAnalysis("CFGNotUnderstood", Phi)
  515. << "loop control flow is not understood by vectorizer");
  516. LLVM_DEBUG(dbgs() << "LV: Found an non-int non-pointer PHI.\n");
  517. return false;
  518. }
  519. // If this PHINode is not in the header block, then we know that we
  520. // can convert it to select during if-conversion. No need to check if
  521. // the PHIs in this block are induction or reduction variables.
  522. if (BB != Header) {
  523. // Non-header phi nodes that have outside uses can be vectorized. Add
  524. // them to the list of allowed exits.
  525. // Unsafe cyclic dependencies with header phis are identified during
  526. // legalization for reduction, induction and first order
  527. // recurrences.
  528. continue;
  529. }
  530. // We only allow if-converted PHIs with exactly two incoming values.
  531. if (Phi->getNumIncomingValues() != 2) {
  532. ORE->emit(createMissedAnalysis("CFGNotUnderstood", Phi)
  533. << "control flow not understood by vectorizer");
  534. LLVM_DEBUG(dbgs() << "LV: Found an invalid PHI.\n");
  535. return false;
  536. }
  537. RecurrenceDescriptor RedDes;
  538. if (RecurrenceDescriptor::isReductionPHI(Phi, TheLoop, RedDes, DB, AC,
  539. DT)) {
  540. if (RedDes.hasUnsafeAlgebra())
  541. Requirements->addUnsafeAlgebraInst(RedDes.getUnsafeAlgebraInst());
  542. AllowedExit.insert(RedDes.getLoopExitInstr());
  543. Reductions[Phi] = RedDes;
  544. continue;
  545. }
  546. // TODO: Instead of recording the AllowedExit, it would be good to record the
  547. // complementary set: NotAllowedExit. These include (but may not be
  548. // limited to):
  549. // 1. Reduction phis as they represent the one-before-last value, which
  550. // is not available when vectorized
  551. // 2. Induction phis and increment when SCEV predicates cannot be used
  552. // outside the loop - see addInductionPhi
  553. // 3. Non-Phis with outside uses when SCEV predicates cannot be used
  554. // outside the loop - see call to hasOutsideLoopUser in the non-phi
  555. // handling below
  556. // 4. FirstOrderRecurrence phis that can possibly be handled by
  557. // extraction.
  558. // By recording these, we can then reason about ways to vectorize each
  559. // of these NotAllowedExit.
  560. InductionDescriptor ID;
  561. if (InductionDescriptor::isInductionPHI(Phi, TheLoop, PSE, ID)) {
  562. addInductionPhi(Phi, ID, AllowedExit);
  563. if (ID.hasUnsafeAlgebra() && !HasFunNoNaNAttr)
  564. Requirements->addUnsafeAlgebraInst(ID.getUnsafeAlgebraInst());
  565. continue;
  566. }
  567. if (RecurrenceDescriptor::isFirstOrderRecurrence(Phi, TheLoop,
  568. SinkAfter, DT)) {
  569. FirstOrderRecurrences.insert(Phi);
  570. continue;
  571. }
  572. // As a last resort, coerce the PHI to a AddRec expression
  573. // and re-try classifying it a an induction PHI.
  574. if (InductionDescriptor::isInductionPHI(Phi, TheLoop, PSE, ID, true)) {
  575. addInductionPhi(Phi, ID, AllowedExit);
  576. continue;
  577. }
  578. ORE->emit(createMissedAnalysis("NonReductionValueUsedOutsideLoop", Phi)
  579. << "value that could not be identified as "
  580. "reduction is used outside the loop");
  581. LLVM_DEBUG(dbgs() << "LV: Found an unidentified PHI." << *Phi << "\n");
  582. return false;
  583. } // end of PHI handling
  584. // We handle calls that:
  585. // * Are debug info intrinsics.
  586. // * Have a mapping to an IR intrinsic.
  587. // * Have a vector version available.
  588. auto *CI = dyn_cast<CallInst>(&I);
  589. if (CI && !getVectorIntrinsicIDForCall(CI, TLI) &&
  590. !isa<DbgInfoIntrinsic>(CI) &&
  591. !(CI->getCalledFunction() && TLI &&
  592. TLI->isFunctionVectorizable(CI->getCalledFunction()->getName()))) {
  593. ORE->emit(createMissedAnalysis("CantVectorizeCall", CI)
  594. << "call instruction cannot be vectorized");
  595. LLVM_DEBUG(
  596. dbgs() << "LV: Found a non-intrinsic, non-libfunc callsite.\n");
  597. return false;
  598. }
  599. // Intrinsics such as powi,cttz and ctlz are legal to vectorize if the
  600. // second argument is the same (i.e. loop invariant)
  601. if (CI && hasVectorInstrinsicScalarOpd(
  602. getVectorIntrinsicIDForCall(CI, TLI), 1)) {
  603. auto *SE = PSE.getSE();
  604. if (!SE->isLoopInvariant(PSE.getSCEV(CI->getOperand(1)), TheLoop)) {
  605. ORE->emit(createMissedAnalysis("CantVectorizeIntrinsic", CI)
  606. << "intrinsic instruction cannot be vectorized");
  607. LLVM_DEBUG(dbgs()
  608. << "LV: Found unvectorizable intrinsic " << *CI << "\n");
  609. return false;
  610. }
  611. }
  612. // Check that the instruction return type is vectorizable.
  613. // Also, we can't vectorize extractelement instructions.
  614. if ((!VectorType::isValidElementType(I.getType()) &&
  615. !I.getType()->isVoidTy()) ||
  616. isa<ExtractElementInst>(I)) {
  617. ORE->emit(createMissedAnalysis("CantVectorizeInstructionReturnType", &I)
  618. << "instruction return type cannot be vectorized");
  619. LLVM_DEBUG(dbgs() << "LV: Found unvectorizable type.\n");
  620. return false;
  621. }
  622. // Check that the stored type is vectorizable.
  623. if (auto *ST = dyn_cast<StoreInst>(&I)) {
  624. Type *T = ST->getValueOperand()->getType();
  625. if (!VectorType::isValidElementType(T)) {
  626. ORE->emit(createMissedAnalysis("CantVectorizeStore", ST)
  627. << "store instruction cannot be vectorized");
  628. return false;
  629. }
  630. // FP instructions can allow unsafe algebra, thus vectorizable by
  631. // non-IEEE-754 compliant SIMD units.
  632. // This applies to floating-point math operations and calls, not memory
  633. // operations, shuffles, or casts, as they don't change precision or
  634. // semantics.
  635. } else if (I.getType()->isFloatingPointTy() && (CI || I.isBinaryOp()) &&
  636. !I.isFast()) {
  637. LLVM_DEBUG(dbgs() << "LV: Found FP op with unsafe algebra.\n");
  638. Hints->setPotentiallyUnsafe();
  639. }
  640. // Reduction instructions are allowed to have exit users.
  641. // All other instructions must not have external users.
  642. if (hasOutsideLoopUser(TheLoop, &I, AllowedExit)) {
  643. // We can safely vectorize loops where instructions within the loop are
  644. // used outside the loop only if the SCEV predicates within the loop is
  645. // same as outside the loop. Allowing the exit means reusing the SCEV
  646. // outside the loop.
  647. if (PSE.getUnionPredicate().isAlwaysTrue()) {
  648. AllowedExit.insert(&I);
  649. continue;
  650. }
  651. ORE->emit(createMissedAnalysis("ValueUsedOutsideLoop", &I)
  652. << "value cannot be used outside the loop");
  653. return false;
  654. }
  655. } // next instr.
  656. }
  657. if (!PrimaryInduction) {
  658. LLVM_DEBUG(dbgs() << "LV: Did not find one integer induction var.\n");
  659. if (Inductions.empty()) {
  660. ORE->emit(createMissedAnalysis("NoInductionVariable")
  661. << "loop induction variable could not be identified");
  662. return false;
  663. }
  664. }
  665. // Now we know the widest induction type, check if our found induction
  666. // is the same size. If it's not, unset it here and InnerLoopVectorizer
  667. // will create another.
  668. if (PrimaryInduction && WidestIndTy != PrimaryInduction->getType())
  669. PrimaryInduction = nullptr;
  670. return true;
  671. }
  672. bool LoopVectorizationLegality::canVectorizeMemory() {
  673. LAI = &(*GetLAA)(*TheLoop);
  674. const OptimizationRemarkAnalysis *LAR = LAI->getReport();
  675. if (LAR) {
  676. ORE->emit([&]() {
  677. return OptimizationRemarkAnalysis(Hints->vectorizeAnalysisPassName(),
  678. "loop not vectorized: ", *LAR);
  679. });
  680. }
  681. if (!LAI->canVectorizeMemory())
  682. return false;
  683. if (LAI->hasStoreToLoopInvariantAddress()) {
  684. ORE->emit(createMissedAnalysis("CantVectorizeStoreToLoopInvariantAddress")
  685. << "write to a loop invariant address could not be vectorized");
  686. LLVM_DEBUG(dbgs() << "LV: We don't allow storing to uniform addresses\n");
  687. return false;
  688. }
  689. Requirements->addRuntimePointerChecks(LAI->getNumRuntimePointerChecks());
  690. PSE.addPredicate(LAI->getPSE().getUnionPredicate());
  691. return true;
  692. }
  693. bool LoopVectorizationLegality::isInductionPhi(const Value *V) {
  694. Value *In0 = const_cast<Value *>(V);
  695. PHINode *PN = dyn_cast_or_null<PHINode>(In0);
  696. if (!PN)
  697. return false;
  698. return Inductions.count(PN);
  699. }
  700. bool LoopVectorizationLegality::isCastedInductionVariable(const Value *V) {
  701. auto *Inst = dyn_cast<Instruction>(V);
  702. return (Inst && InductionCastsToIgnore.count(Inst));
  703. }
  704. bool LoopVectorizationLegality::isInductionVariable(const Value *V) {
  705. return isInductionPhi(V) || isCastedInductionVariable(V);
  706. }
  707. bool LoopVectorizationLegality::isFirstOrderRecurrence(const PHINode *Phi) {
  708. return FirstOrderRecurrences.count(Phi);
  709. }
  710. bool LoopVectorizationLegality::blockNeedsPredication(BasicBlock *BB) {
  711. return LoopAccessInfo::blockNeedsPredication(BB, TheLoop, DT);
  712. }
  713. bool LoopVectorizationLegality::blockCanBePredicated(
  714. BasicBlock *BB, SmallPtrSetImpl<Value *> &SafePtrs) {
  715. const bool IsAnnotatedParallel = TheLoop->isAnnotatedParallel();
  716. for (Instruction &I : *BB) {
  717. // Check that we don't have a constant expression that can trap as operand.
  718. for (Value *Operand : I.operands()) {
  719. if (auto *C = dyn_cast<Constant>(Operand))
  720. if (C->canTrap())
  721. return false;
  722. }
  723. // We might be able to hoist the load.
  724. if (I.mayReadFromMemory()) {
  725. auto *LI = dyn_cast<LoadInst>(&I);
  726. if (!LI)
  727. return false;
  728. if (!SafePtrs.count(LI->getPointerOperand())) {
  729. // !llvm.mem.parallel_loop_access implies if-conversion safety.
  730. // Otherwise, record that the load needs (real or emulated) masking
  731. // and let the cost model decide.
  732. if (!IsAnnotatedParallel)
  733. MaskedOp.insert(LI);
  734. continue;
  735. }
  736. }
  737. if (I.mayWriteToMemory()) {
  738. auto *SI = dyn_cast<StoreInst>(&I);
  739. if (!SI)
  740. return false;
  741. // Predicated store requires some form of masking:
  742. // 1) masked store HW instruction,
  743. // 2) emulation via load-blend-store (only if safe and legal to do so,
  744. // be aware on the race conditions), or
  745. // 3) element-by-element predicate check and scalar store.
  746. MaskedOp.insert(SI);
  747. continue;
  748. }
  749. if (I.mayThrow())
  750. return false;
  751. }
  752. return true;
  753. }
  754. bool LoopVectorizationLegality::canVectorizeWithIfConvert() {
  755. if (!EnableIfConversion) {
  756. ORE->emit(createMissedAnalysis("IfConversionDisabled")
  757. << "if-conversion is disabled");
  758. return false;
  759. }
  760. assert(TheLoop->getNumBlocks() > 1 && "Single block loops are vectorizable");
  761. // A list of pointers that we can safely read and write to.
  762. SmallPtrSet<Value *, 8> SafePointes;
  763. // Collect safe addresses.
  764. for (BasicBlock *BB : TheLoop->blocks()) {
  765. if (blockNeedsPredication(BB))
  766. continue;
  767. for (Instruction &I : *BB)
  768. if (auto *Ptr = getLoadStorePointerOperand(&I))
  769. SafePointes.insert(Ptr);
  770. }
  771. // Collect the blocks that need predication.
  772. BasicBlock *Header = TheLoop->getHeader();
  773. for (BasicBlock *BB : TheLoop->blocks()) {
  774. // We don't support switch statements inside loops.
  775. if (!isa<BranchInst>(BB->getTerminator())) {
  776. ORE->emit(createMissedAnalysis("LoopContainsSwitch", BB->getTerminator())
  777. << "loop contains a switch statement");
  778. return false;
  779. }
  780. // We must be able to predicate all blocks that need to be predicated.
  781. if (blockNeedsPredication(BB)) {
  782. if (!blockCanBePredicated(BB, SafePointes)) {
  783. ORE->emit(createMissedAnalysis("NoCFGForSelect", BB->getTerminator())
  784. << "control flow cannot be substituted for a select");
  785. return false;
  786. }
  787. } else if (BB != Header && !canIfConvertPHINodes(BB)) {
  788. ORE->emit(createMissedAnalysis("NoCFGForSelect", BB->getTerminator())
  789. << "control flow cannot be substituted for a select");
  790. return false;
  791. }
  792. }
  793. // We can if-convert this loop.
  794. return true;
  795. }
  796. // Helper function to canVectorizeLoopNestCFG.
  797. bool LoopVectorizationLegality::canVectorizeLoopCFG(Loop *Lp,
  798. bool UseVPlanNativePath) {
  799. assert((UseVPlanNativePath || Lp->empty()) &&
  800. "VPlan-native path is not enabled.");
  801. // TODO: ORE should be improved to show more accurate information when an
  802. // outer loop can't be vectorized because a nested loop is not understood or
  803. // legal. Something like: "outer_loop_location: loop not vectorized:
  804. // (inner_loop_location) loop control flow is not understood by vectorizer".
  805. // Store the result and return it at the end instead of exiting early, in case
  806. // allowExtraAnalysis is used to report multiple reasons for not vectorizing.
  807. bool Result = true;
  808. bool DoExtraAnalysis = ORE->allowExtraAnalysis(DEBUG_TYPE);
  809. // We must have a loop in canonical form. Loops with indirectbr in them cannot
  810. // be canonicalized.
  811. if (!Lp->getLoopPreheader()) {
  812. LLVM_DEBUG(dbgs() << "LV: Loop doesn't have a legal pre-header.\n");
  813. ORE->emit(createMissedAnalysis("CFGNotUnderstood")
  814. << "loop control flow is not understood by vectorizer");
  815. if (DoExtraAnalysis)
  816. Result = false;
  817. else
  818. return false;
  819. }
  820. // We must have a single backedge.
  821. if (Lp->getNumBackEdges() != 1) {
  822. ORE->emit(createMissedAnalysis("CFGNotUnderstood")
  823. << "loop control flow is not understood by vectorizer");
  824. if (DoExtraAnalysis)
  825. Result = false;
  826. else
  827. return false;
  828. }
  829. // We must have a single exiting block.
  830. if (!Lp->getExitingBlock()) {
  831. ORE->emit(createMissedAnalysis("CFGNotUnderstood")
  832. << "loop control flow is not understood by vectorizer");
  833. if (DoExtraAnalysis)
  834. Result = false;
  835. else
  836. return false;
  837. }
  838. // We only handle bottom-tested loops, i.e. loop in which the condition is
  839. // checked at the end of each iteration. With that we can assume that all
  840. // instructions in the loop are executed the same number of times.
  841. if (Lp->getExitingBlock() != Lp->getLoopLatch()) {
  842. ORE->emit(createMissedAnalysis("CFGNotUnderstood")
  843. << "loop control flow is not understood by vectorizer");
  844. if (DoExtraAnalysis)
  845. Result = false;
  846. else
  847. return false;
  848. }
  849. return Result;
  850. }
  851. bool LoopVectorizationLegality::canVectorizeLoopNestCFG(
  852. Loop *Lp, bool UseVPlanNativePath) {
  853. // Store the result and return it at the end instead of exiting early, in case
  854. // allowExtraAnalysis is used to report multiple reasons for not vectorizing.
  855. bool Result = true;
  856. bool DoExtraAnalysis = ORE->allowExtraAnalysis(DEBUG_TYPE);
  857. if (!canVectorizeLoopCFG(Lp, UseVPlanNativePath)) {
  858. if (DoExtraAnalysis)
  859. Result = false;
  860. else
  861. return false;
  862. }
  863. // Recursively check whether the loop control flow of nested loops is
  864. // understood.
  865. for (Loop *SubLp : *Lp)
  866. if (!canVectorizeLoopNestCFG(SubLp, UseVPlanNativePath)) {
  867. if (DoExtraAnalysis)
  868. Result = false;
  869. else
  870. return false;
  871. }
  872. return Result;
  873. }
  874. bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
  875. // Store the result and return it at the end instead of exiting early, in case
  876. // allowExtraAnalysis is used to report multiple reasons for not vectorizing.
  877. bool Result = true;
  878. bool DoExtraAnalysis = ORE->allowExtraAnalysis(DEBUG_TYPE);
  879. // Check whether the loop-related control flow in the loop nest is expected by
  880. // vectorizer.
  881. if (!canVectorizeLoopNestCFG(TheLoop, UseVPlanNativePath)) {
  882. if (DoExtraAnalysis)
  883. Result = false;
  884. else
  885. return false;
  886. }
  887. // We need to have a loop header.
  888. LLVM_DEBUG(dbgs() << "LV: Found a loop: " << TheLoop->getHeader()->getName()
  889. << '\n');
  890. // Specific checks for outer loops. We skip the remaining legal checks at this
  891. // point because they don't support outer loops.
  892. if (!TheLoop->empty()) {
  893. assert(UseVPlanNativePath && "VPlan-native path is not enabled.");
  894. if (!canVectorizeOuterLoop()) {
  895. LLVM_DEBUG(dbgs() << "LV: Not vectorizing: Unsupported outer loop.\n");
  896. // TODO: Implement DoExtraAnalysis when subsequent legal checks support
  897. // outer loops.
  898. return false;
  899. }
  900. LLVM_DEBUG(dbgs() << "LV: We can vectorize this outer loop!\n");
  901. return Result;
  902. }
  903. assert(TheLoop->empty() && "Inner loop expected.");
  904. // Check if we can if-convert non-single-bb loops.
  905. unsigned NumBlocks = TheLoop->getNumBlocks();
  906. if (NumBlocks != 1 && !canVectorizeWithIfConvert()) {
  907. LLVM_DEBUG(dbgs() << "LV: Can't if-convert the loop.\n");
  908. if (DoExtraAnalysis)
  909. Result = false;
  910. else
  911. return false;
  912. }
  913. // Check if we can vectorize the instructions and CFG in this loop.
  914. if (!canVectorizeInstrs()) {
  915. LLVM_DEBUG(dbgs() << "LV: Can't vectorize the instructions or CFG\n");
  916. if (DoExtraAnalysis)
  917. Result = false;
  918. else
  919. return false;
  920. }
  921. // Go over each instruction and look at memory deps.
  922. if (!canVectorizeMemory()) {
  923. LLVM_DEBUG(dbgs() << "LV: Can't vectorize due to memory conflicts\n");
  924. if (DoExtraAnalysis)
  925. Result = false;
  926. else
  927. return false;
  928. }
  929. LLVM_DEBUG(dbgs() << "LV: We can vectorize this loop"
  930. << (LAI->getRuntimePointerChecking()->Need
  931. ? " (with a runtime bound check)"
  932. : "")
  933. << "!\n");
  934. unsigned SCEVThreshold = VectorizeSCEVCheckThreshold;
  935. if (Hints->getForce() == LoopVectorizeHints::FK_Enabled)
  936. SCEVThreshold = PragmaVectorizeSCEVCheckThreshold;
  937. if (PSE.getUnionPredicate().getComplexity() > SCEVThreshold) {
  938. ORE->emit(createMissedAnalysis("TooManySCEVRunTimeChecks")
  939. << "Too many SCEV assumptions need to be made and checked "
  940. << "at runtime");
  941. LLVM_DEBUG(dbgs() << "LV: Too many SCEV checks needed.\n");
  942. if (DoExtraAnalysis)
  943. Result = false;
  944. else
  945. return false;
  946. }
  947. // Okay! We've done all the tests. If any have failed, return false. Otherwise
  948. // we can vectorize, and at this point we don't have any other mem analysis
  949. // which may limit our maximum vectorization factor, so just return true with
  950. // no restrictions.
  951. return Result;
  952. }
  953. } // namespace llvm