Skip to content

Commit 9cf6266

Browse files
committed
[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 (cherry-picked from 78c6b14)
1 parent 58f1467 commit 9cf6266

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

llvm/lib/Analysis/CaptureTracking.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ STATISTIC(NumNotCapturedBefore, "Number of pointers not captured before");
4545
/// use it where possible. The caching version can use much higher limit or
4646
/// don't have this cap at all.
4747
static cl::opt<unsigned>
48-
DefaultMaxUsesToExplore("capture-tracking-max-uses-to-explore", cl::Hidden,
49-
cl::desc("Maximal number of uses to explore."),
50-
cl::init(20));
48+
DefaultMaxUsesToExplore("capture-tracking-max-uses-to-explore", cl::Hidden,
49+
cl::desc("Maximal number of uses to explore."),
50+
cl::init(100));
5151

5252
unsigned llvm::getDefaultMaxUsesToExploreForCaptureTracking() {
5353
return DefaultMaxUsesToExplore;
@@ -445,11 +445,10 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
445445
SmallSet<const Use *, 20> Visited;
446446

447447
auto AddUses = [&](const Value *V) {
448-
unsigned Count = 0;
449448
for (const Use &U : V->uses()) {
450449
// If there are lots of uses, conservatively say that the value
451450
// is captured to avoid taking too much compile time.
452-
if (Count++ >= MaxUsesToExplore) {
451+
if (Visited.size() >= MaxUsesToExplore) {
453452
Tracker->tooManyUses();
454453
return false;
455454
}

llvm/test/Transforms/GVN/capture-tracking-limit.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt -aa-pipeline=basic-aa -passes="gvn" -S %s | FileCheck --check-prefixes=CHECK,LIMIT-TOO-SMALL %s
2+
; RUN: opt -aa-pipeline=basic-aa -passes="gvn" -S %s | FileCheck --check-prefixes=CHECK,LIMIT %s
33
; 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
44
; RUN: opt -aa-pipeline=basic-aa -passes="gvn" -S -capture-tracking-max-uses-to-explore=21 %s | FileCheck --check-prefixes=CHECK,LIMIT %s
55

0 commit comments

Comments
 (0)