Skip to content

Commit

Permalink
[GVNHoist] Enable aggressive hoisting when optimizing for code-size
Browse files Browse the repository at this point in the history
Enable scalar hoisting at -Oz as it is safe to hoist scalars to a place
where they are partially needed.

Differential Revision: https://reviews.llvm.org/D27111

llvm-svn: 288141
hiraditya committed Nov 29, 2016
1 parent 35c47c4 commit 07cb304
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions llvm/lib/Transforms/Scalar/GVNHoist.cpp
Original file line number Diff line number Diff line change
@@ -202,7 +202,12 @@ class GVNHoist {
GVNHoist(DominatorTree *DT, AliasAnalysis *AA, MemoryDependenceResults *MD,
MemorySSA *MSSA, bool OptForMinSize)
: DT(DT), AA(AA), MD(MD), MSSA(MSSA), OptForMinSize(OptForMinSize),
HoistingGeps(OptForMinSize), HoistedCtr(0) {}
HoistingGeps(OptForMinSize), HoistedCtr(0) {
// Hoist as far as possible when optimizing for code-size.
if (OptForMinSize)
MaxNumberOfBBSInPath = -1;
}

bool run(Function &F) {
VN.setDomTree(DT);
VN.setAliasAnalysis(AA);
@@ -500,10 +505,13 @@ class GVNHoist {
bool safeToHoistScalar(const BasicBlock *HoistBB,
SmallPtrSetImpl<const BasicBlock *> &WL,
int &NBBsOnAllPaths) {
// Check that the hoisted expression is needed on all paths. Enable scalar
// hoisting at -Oz as it is safe to hoist scalars to a place where they are
// partially needed.
if (!OptForMinSize && !hoistingFromAllPaths(HoistBB, WL))
// Enable scalar hoisting at -Oz as it is safe to hoist scalars to a place
// where they are partially needed.
if (OptForMinSize)
return true;

// Check that the hoisted expression is needed on all paths.
if (!hoistingFromAllPaths(HoistBB, WL))
return false;

for (const BasicBlock *BB : WL)

0 comments on commit 07cb304

Please sign in to comment.