-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LV] Add initial legality checks for loops with unbound loads. #152422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 24 commits
dc5b7c1
78f05df
f5315f8
d3246bd
eb316ee
faa6112
b206c9f
72383dd
0c1d007
e22c486
2a37216
abb0120
6b920f4
22dee5b
e88d5d4
12e6dc9
3284452
10156ca
16b5376
357ff34
ead7a78
9e98d12
f18dae7
9dc5a7a
380e064
93db706
43976f7
51a8329
7a99472
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -445,6 +445,11 @@ class LoopVectorizationLegality { | |
/// Returns a list of all known histogram operations in the loop. | ||
bool hasHistograms() const { return !Histograms.empty(); } | ||
|
||
/// Returns the loads that need to be fault-only-first. | ||
const SmallPtrSetImpl<const Instruction *> &getFaultOnlyFirstLoads() const { | ||
return FaultOnlyFirstLoads; | ||
} | ||
|
||
|
||
PredicatedScalarEvolution *getPredicatedScalarEvolution() const { | ||
return &PSE; | ||
} | ||
|
@@ -630,6 +635,9 @@ class LoopVectorizationLegality { | |
/// may work on the same memory location. | ||
SmallVector<HistogramInfo, 1> Histograms; | ||
|
||
/// Hold all loads that need to be fault-only-first. | ||
SmallPtrSet<const Instruction *, 4> FaultOnlyFirstLoads; | ||
|
||
|
||
/// BFI and PSI are used to check for profile guided size optimizations. | ||
BlockFrequencyInfo *BFI; | ||
ProfileSummaryInfo *PSI; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1760,16 +1760,30 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() { | |
assert(LatchBB->getUniquePredecessor() == SingleUncountableExitingBlock && | ||
"Expected latch predecessor to be the early exiting block"); | ||
|
||
// TODO: Handle loops that may fault. | ||
Predicates.clear(); | ||
if (!isDereferenceableReadOnlyLoop(TheLoop, PSE.getSE(), DT, AC, | ||
&Predicates)) { | ||
reportVectorizationFailure( | ||
"Loop may fault", | ||
"Cannot vectorize potentially faulting early exit loop", | ||
"PotentiallyFaultingEarlyExitLoop", ORE, TheLoop); | ||
SmallVector<LoadInst *, 4> NonDerefLoads; | ||
if (!isReadOnlyLoop(TheLoop, PSE.getSE(), DT, AC, &NonDerefLoads, | ||
&Predicates)) { | ||
reportVectorizationFailure("Loop may fault", | ||
"Cannot vectorize non-read-only early exit loop", | ||
"NonReadOnlyEarlyExitLoop", ORE, TheLoop); | ||
return false; | ||
} | ||
// Check non-dereferenceable loads if any. | ||
for (LoadInst *LI : NonDerefLoads) { | ||
// Only support unit-stride access for now. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a question about potential AArch64 support, SVE has first-fault gathers IIUC which could be used for strided accesses. I presume we don't need to check for alignment there? From quickly scanning the docs it looks like an unaligned access non-first-fault will be handled the same as any other non-first-fault. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, SVE's first faulting gathers have the same alignment rules as normal gathers, so no extra checks required. |
||
int Stride = isConsecutivePtr(LI->getType(), LI->getPointerOperand()); | ||
arcbbb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (Stride != 1) { | ||
reportVectorizationFailure( | ||
"Loop contains potentially faulting strided load", | ||
"Cannot vectorize early exit loop with " | ||
"strided fault-only-first load", | ||
"EarlyExitLoopWithStridedFaultOnlyFirstLoad", ORE, TheLoop); | ||
return false; | ||
} | ||
FaultOnlyFirstLoads.insert(LI); | ||
LLVM_DEBUG(dbgs() << "LV: Found fault-only-first load: " << *LI << "\n"); | ||
} | ||
|
||
[[maybe_unused]] const SCEV *SymbolicMaxBTC = | ||
PSE.getSymbolicMaxBackedgeTakenCount(); | ||
|
arcbbb marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.