Skip to content

Commit 53dacb7

Browse files
committed
[LV] Generate RT checks up-front and remove them if required.
This patch updates LV to generate the runtime checks just after cost modeling, to allow a more precise estimate of the actual cost of the checks. This information will be used in future patches to generate larger runtime checks in cases where the checks only make up a small fraction of the expected scalar loop execution time. The runtime checks are created up-front in a temporary block to allow better estimating the cost and un-linked from the existing IR. After deciding to vectorize, the checks are moved backed. If deciding not to vectorize, the temporary block is completely removed. This patch is similar in spirit to D71053, but explores a different direction: instead of delaying the decision on whether to vectorize in the presence of runtime checks it instead optimistically creates the runtime checks early and discards them later if decided to not vectorize. This has the advantage that the cost-modeling decisions can be kept together and can be done up-front and thus preserving the general code structure. I think delaying (part) of the decision to vectorize would also make the VPlan migration a bit harder. One potential drawback of this patch is that we speculatively generate IR which we might have to clean up later. However it seems like the code required to do so is quite manageable. Reviewed By: lebedev.ri, ebrevnov Differential Revision: https://reviews.llvm.org/D75980
1 parent 9dd83f5 commit 53dacb7

File tree

7 files changed

+403
-200
lines changed

7 files changed

+403
-200
lines changed

llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/DenseMap.h"
1717
#include "llvm/ADT/DenseSet.h"
1818
#include "llvm/ADT/Optional.h"
19+
#include "llvm/ADT/SetVector.h"
1920
#include "llvm/ADT/SmallVector.h"
2021
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
2122
#include "llvm/Analysis/ScalarEvolutionNormalization.h"
@@ -506,10 +507,12 @@ class SCEVExpanderCleaner {
506507
SCEVExpanderCleaner(SCEVExpander &Expander, DominatorTree &DT)
507508
: Expander(Expander), DT(DT), ResultUsed(false) {}
508509

509-
~SCEVExpanderCleaner();
510+
~SCEVExpanderCleaner() { cleanup(); }
510511

511512
/// Indicate that the result of the expansion is used.
512513
void markResultUsed() { ResultUsed = true; }
514+
515+
void cleanup();
513516
};
514517
} // namespace llvm
515518

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2678,7 +2678,7 @@ bool isSafeToExpandAt(const SCEV *S, const Instruction *InsertionPoint,
26782678
return false;
26792679
}
26802680

2681-
SCEVExpanderCleaner::~SCEVExpanderCleaner() {
2681+
void SCEVExpanderCleaner::cleanup() {
26822682
// Result is used, nothing to remove.
26832683
if (ResultUsed)
26842684
return;

0 commit comments

Comments
 (0)