[CaptureTracking] Increase limit and use it for all visited uses.
Currently the MaxUsesToExplore limit only applies to the number of users per value, not the total number of users to explore. The current limit of 20 pessimizes IR with opaque pointers in some cases. Without opaque pointers, we have deeper pointer def-use chains in general due to extra bitcasts and geps for structs with index 0. With opaque pointers the def-use chain is not as deep but wider, due to bitcasts & 0-geps missing. To improve the situation for opaque pointers, this patch does 2 things: 1. Apply the limit to the total number of uses visited. From the wording in the description of the option it seems like this may be the original intention. With the current implementation we could still end up walking a lot of uses. 2. Increase the limit to 100. This is quite arbitrary, but enables a good number of additional optimizations. Those adjustments have a noticeable compile-time impact though. In part that is likely due to additional transformations (and conversely the current baseline misses optimizations after switching to opaque pointers). This recovers some regressions that showed up after enabling opaque pointers. Limit=100: * NewPM-O3: +0.21% * NewPM-ReleaseThinLTO: +0.87% * NewPM-ReleaseLTO-g: +0.46% https://llvm-compile-time-tracker.com/compare.php?from=2e50ecb2ef4e1da1aeab05bcf66380068e680991&to=7e6fbe519d958d09f32f01d5d44a622f551e2031&stat=instructions Limit=60: * NewPM-O3: +0.14% * NewPM-ReleaseThinLTO: +0.41% * NewPM-ReleaseLTO-g: +0.21% https://llvm-compile-time-tracker.com/compare.php?from=aeb19817d66f1a15754163c7f48e01e9ebdd6d45&to=520563fdc146319aae90d06f88d87f2e9e1247b7&stat=instructions Limit=40: * NewPM-O3: +0.11% * NewPM-ReleaseThinLTO: +0.12% * NewPM-ReleaseLTO-g: +0.09% https://llvm-compile-time-tracker.com/compare.php?from=aeb19817d66f1a15754163c7f48e01e9ebdd6d45&to=c9182576e9fe3f1c84a71479665aef91a416318c&stat=instructions Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D126236
This commit is contained in:
parent
e09f77d394
commit
78c6b1488f
|
@ -45,9 +45,9 @@ STATISTIC(NumNotCapturedBefore, "Number of pointers not captured before");
|
|||
/// use it where possible. The caching version can use much higher limit or
|
||||
/// don't have this cap at all.
|
||||
static cl::opt<unsigned>
|
||||
DefaultMaxUsesToExplore("capture-tracking-max-uses-to-explore", cl::Hidden,
|
||||
cl::desc("Maximal number of uses to explore."),
|
||||
cl::init(20));
|
||||
DefaultMaxUsesToExplore("capture-tracking-max-uses-to-explore", cl::Hidden,
|
||||
cl::desc("Maximal number of uses to explore."),
|
||||
cl::init(100));
|
||||
|
||||
unsigned llvm::getDefaultMaxUsesToExploreForCaptureTracking() {
|
||||
return DefaultMaxUsesToExplore;
|
||||
|
@ -445,11 +445,10 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
|
|||
SmallSet<const Use *, 20> Visited;
|
||||
|
||||
auto AddUses = [&](const Value *V) {
|
||||
unsigned Count = 0;
|
||||
for (const Use &U : V->uses()) {
|
||||
// If there are lots of uses, conservatively say that the value
|
||||
// is captured to avoid taking too much compile time.
|
||||
if (Count++ >= MaxUsesToExplore) {
|
||||
if (Visited.size() >= MaxUsesToExplore) {
|
||||
Tracker->tooManyUses();
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt -aa-pipeline=basic-aa -passes="gvn" -S %s | FileCheck --check-prefixes=CHECK,LIMIT-TOO-SMALL %s
|
||||
; RUN: opt -aa-pipeline=basic-aa -passes="gvn" -S %s | FileCheck --check-prefixes=CHECK,LIMIT %s
|
||||
; RUN: opt -aa-pipeline=basic-aa -passes="gvn" -S -capture-tracking-max-uses-to-explore=20 %s | FileCheck --check-prefixes=CHECK,LIMIT-TOO-SMALL %s
|
||||
; RUN: opt -aa-pipeline=basic-aa -passes="gvn" -S -capture-tracking-max-uses-to-explore=21 %s | FileCheck --check-prefixes=CHECK,LIMIT %s
|
||||
|
||||
|
|
Loading…
Reference in New Issue