summaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/LoopCacheAnalysis.cpp
AgeCommit message (Collapse)Author
2023-04-10[SCEV] When computing trip count, only zext if necessaryJoshua Cao
This patch improves on https://reviews.llvm.org/D110587. To summarize the patch, given backedge-taken count BC, trip count TC is `BC + 1`. However, we don't know if BC we might overflow. So the patch modifies TC computation to `1 + zext(BC)`. This patch only adds the zext if necessary by looking at the constant range. If we can determine that BC cannot be the max value for its bitwidth, then we know adding 1 will not overflow, and the zext is not needed. We apply loop guards before computing TC to get more data. The primary motivation is to support my work on more precise trip multiples in https://reviews.llvm.org/D141823. For example: ``` void test(unsigned n) __builtin_assume(n % 6 == 0); for (unsigned i = 0; i < n; ++i) foo(); ``` Prior to this patch, we had `TC = 1 + zext(-1 + 6 * ((6 umax %n) /u 6))<nuw>`. SCEV range computation is able to determine that the BC cannot be the max value, so the zext is not needed. The result is `TC -> (6 * ((6 umax %n) /u 6))<nuw>`. From here, we would be able to determine that %n is a multiple of 6. There was one change in LoopCacheAnalysis/LoopInterchange required. Before this patch, if a loop has BC = false, it would compute `TC -> 1 + zext(false) -> 1`, which was fine. After this patch, it computes `TC -> 1 + false = true`. CacheAnalysis would then sign extend the `true`, which was not the intended the behavior. I modified CacheAnalysis such that it would only zero extend trip counts. This patch is not NFC, but also does not change any SCEV outputs. I would like to get this patch out first to make work with trip multiples easier. Differential Revision: https://reviews.llvm.org/D147117
2022-12-14[Analysis] llvm::Optional => std::optionalFangrui Song
2022-12-02[Analysis] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-19[Analysis] Use llvm::Optional::value_or (NFC)Kazu Hirata
2022-08-28Revert "[llvm] Use llvm::is_contained (NFC)"Kazu Hirata
This reverts commit ebf574f59a80ca00e234eee0b047e5f0df99587d. This patch seems to cause build failures on Windows.
2022-08-28[llvm] Use llvm::is_contained (NFC)Kazu Hirata
2022-07-21[LoopCacheAnalysis] Fix a type mismatch problem in cost calculationCongzhe Cao
There is a problem in loop cache analysis that the types of SCEV variables `Coeff` and `ElemSize` in function `isConsecutive()` may not match. The mismatch would cause SCEV failures when `Coeff` is multiplied with `ElemSize`. The fix in this patch is to extend the type of both `Coeff` and `ElemSize` to whichever is wider in those two variables. As a clean-up, duplicate calculations of `Stride` in `computeRefCost()` is then removed. Reviewed By: Meinersbur, #loopoptwg Differential Revision: https://reviews.llvm.org/D128877
2022-06-25[llvm] Don't use Optional::hasValue (NFC)Kazu Hirata
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata
2022-06-16[Delinearization] Refactoring of fixed-size array delinearizationCongzhe Cao
This is a follow-up patch to D122857 where we added delinearization of fixed-size arrays to loop cache analysis, which resulted in some duplicate code, i.e., "tryDelinearizeFixedSize()", in LoopCacheCost.cpp and DependenceAnalysis.cpp. Refactoring is done in this patch. This patch refactors out the main logic of "tryDelinearizeFixedSize()" as "tryDelinearizeFixedSizeImpl()" and moves it to Delinearization.cpp, such that clients can reuse "llvm::tryDelinearizeFixedSizeImpl()" wherever they would like to delinearize fixed-size arrays. Currently it has two users, i.e., DependenceAnalysis.cpp and LoopCacheCost.cpp. Reviewed By: Meinersbur, #loopoptwg Differential Revision: https://reviews.llvm.org/D124745
2022-05-02fix warning caused by ef4ecc3ceffcf3ef129640c813f823c974f9ba22Bardia Mahjour
2022-05-02[LoopCacheAnalysis] Consider dimension depth of the subscript reference when ↵Bardia Mahjour
calculating cost Reviewed By: congzhe, etiotto Differential Revision: https://reviews.llvm.org/D123400
2022-04-29[LoopCacheAnalysis] Enable delinearization of fixed sized arraysCongzhe Cao
Currently loop cache cost (LCC) cannot analyze fix-sized arrays since it cannot delinearize them. This patch adds the capability to delinearize fix-sized arrays to LCC. Most of the code is ported from DependenceAnalysis.cpp and some refactoring will be done in a next patch. Reviewed By: #loopoptwg, Meinersbur Differential Revision: https://reviews.llvm.org/D122857
2022-03-20[Analysis] Apply clang-tidy fixes for readability-redundant-smartptr-get (NFC)Kazu Hirata
2022-01-07[llvm] Remove redundant member initialization (NFC)Kazu Hirata
Identified with readability-redundant-member-init.
2022-01-03Revert "[llvm] Remove redundant member initialization (NFC)"Kazu Hirata
This reverts commit fd4808887ee47f3ec8a030e9211169ef4fb094c3. This patch causes gcc to issue a lot of warnings like: warning: base class ‘class llvm::MCParsedAsmOperand’ should be explicitly initialized in the copy constructor [-Wextra]
2022-01-01[llvm] Remove redundant member initialization (NFC)Kazu Hirata
Identified with readability-redundant-member-init.
2021-10-24Use llvm::any_of and llvm::none_of (NFC)Kazu Hirata
2021-10-16[Analysis] Replace assert(isa)/dyn_cast with cast. NFC.Simon Pilgrim
cast<> will perform the assertion for us. Removes a static analysis null dereference warning.
2021-09-08Move delinearization logic out of SCEV [NFC]Philip Reames
None of this logic has anything to do with SCEV's internals, it just uses the existing public APIs. As a result, we can move the code from ScalarEvolution.cpp/hpp to Delinearization.cpp/hpp with only minor changes. This was discussed in advance on today's loop opt call. It turned out to be easy as hoped.
2021-08-06[LoopCacheAnalysis]: handle mismatch type for Numerator and CacheLineSizeZheng Chen
fix an assertion due to mismatch type for Numerator and CacheLineSize in loop cache analysis pass. Reviewed By: bmahjour Differential Revision: https://reviews.llvm.org/D107618
2021-05-26[SCEV] Add a utility for converting from "exit count" to "trip count"Philip Reames
(Mostly as a logical place to put a comment since this is a reoccuring confusion.)
2021-01-22[Analysis] Use llvm::append_range (NFC)Kazu Hirata
2020-09-22[LoopInfo] empty() -> isInnermost(), add isOutermost()Stefanos Baziotis
Differential Revision: https://reviews.llvm.org/D82895
2020-09-15LoopCacheAnalysis.h - remove unnecessary includes. NFCI.Simon Pilgrim
More remaining dependencies down to LoopCacheAnalysis.cpp
2020-06-06LoopAnalysisManager.h - reduce includes to forward declarations. NFC.Simon Pilgrim
Move implicit include dependencies down to header/source files.
2020-04-14[ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers.Georgii Rymar
It can be used to avoid passing the begin and end of a range. This makes the code shorter and it is consistent with another wrappers we already have. Differential revision: https://reviews.llvm.org/D78016
2020-02-10[LoopCacheAnalysis]: Add support for negative strideRachel Craik
LoopCacheAnalysis currently assumes the loop will be iterated over in a forward direction. This patch addresses the issue by using the absolute value of the stride when iterating backwards. Note: this patch will treat negative and positive array access the same, resulting in the same cost being calculated for single and bi-directional access patterns. This should be improved in a subsequent patch. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D73064
2019-11-15[LoopCacheAnalysis]: Fix assertion failure during cost computationRachel Craik
Ensure the stride and trip count have the same type before multiplying them during reference cost calculation Reviewed By: jdoefert Differential Revision: https://reviews.llvm.org/D70192
2019-11-14Add missing includes needed to prune LLVMContext.h include, NFCReid Kleckner
These are a pre-requisite to removing #include "llvm/Support/Options.h" from LLVMContext.h: https://reviews.llvm.org/D70280
2019-11-10[NFC]: Fix PVS Studio warning in LoopNestAnalysisTsang Whitney W.H
Summary:This patch fixes the following warnings uncovered by PVS Studio: /home/xbolva00/LLVM/llvm-project/llvm/lib/Analysis/LoopCacheAnalysis.cpp 353 warn V612 An unconditional 'return' within a loop. /home/xbolva00/LLVM/llvm-project/llvm/lib/Analysis/LoopCacheAnalysis.cpp 456 err V502 Perhaps the '?:' operator works in a different way than it was expected. The '?:' operator has a lower priority than the '==' operator. Authored By:etiotto Reviewer:Meinersbur, kbarton, bmahjour, Whitney, xbolva00 Reviewed By:xbolva00 Subscribers:hiraditya, llvm-commits Tag:LLVM Differential Revision:https://reviews.llvm.org/D69821
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
2019-08-09Title: Loop Cache AnalysisWhitney Tsang
Summary: Implement a new analysis to estimate the number of cache lines required by a loop nest. The analysis is largely based on the following paper: Compiler Optimizations for Improving Data Locality By: Steve Carr, Katherine S. McKinley, Chau-Wen Tseng http://www.cs.utexas.edu/users/mckinley/papers/asplos-1994.pdf The analysis considers temporal reuse (accesses to the same memory location) and spatial reuse (accesses to memory locations within a cache line). For simplicity the analysis considers memory accesses in the innermost loop in a loop nest, and thus determines the number of cache lines used when the loop L in loop nest LN is placed in the innermost position. The result of the analysis can be used to drive several transformations. As an example, loop interchange could use it determine which loops in a perfect loop nest should be interchanged to maximize cache reuse. Similarly, loop distribution could be enhanced to take into consideration cache reuse between arrays when distributing a loop to eliminate vectorization inhibiting dependencies. The general approach taken to estimate the number of cache lines used by the memory references in the inner loop of a loop nest is: Partition memory references that exhibit temporal or spatial reuse into reference groups. For each loop L in the a loop nest LN: a. Compute the cost of the reference group b. Compute the 'cache cost' of the loop nest by summing up the reference groups costs For further details of the algorithm please refer to the paper. Authored By: etiotto Reviewers: hfinkel, Meinersbur, jdoerfert, kbarton, bmahjour, anemet, fhahn Reviewed By: Meinersbur Subscribers: reames, nemanjai, MaskRay, wuzish, Hahnfeld, xusx595, venkataramanan.kumar.llvm, greened, dmgreen, steleman, fhahn, xblvaOO, Whitney, mgorny, hiraditya, mgrang, jsji, llvm-commits Tag: LLVM Differential Revision: https://reviews.llvm.org/D63459 llvm-svn: 368439