Skip to content

Commit

Permalink
Add an optimization that does CSE in a group of similar GEPs.
Browse files Browse the repository at this point in the history
This optimization merges the common part of a group of GEPs, so we can compute
each pointer address by adding a simple offset to the common part.

The optimization is currently only enabled for the NVPTX backend, where it has
a large payoff on some benchmarks.

Review: http://reviews.llvm.org/D3462

Patch by Jingyue Wu.




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207783 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
eliben committed May 1, 2014
1 parent 75bb54d commit 167a57c
Show file tree
Hide file tree
Showing 9 changed files with 774 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ void initializeSimpleInlinerPass(PassRegistry&);
void initializeRegisterCoalescerPass(PassRegistry&);
void initializeSingleLoopExtractorPass(PassRegistry&);
void initializeSinkingPass(PassRegistry&);
void initializeSeparateConstOffsetFromGEPPass(PassRegistry &);
void initializeSlotIndexesPass(PassRegistry&);
void initializeSpillPlacementPass(PassRegistry&);
void initializeStackProtectorPass(PassRegistry&);
Expand Down
1 change: 1 addition & 0 deletions include/llvm/LinkAllPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ namespace {
(void) llvm::createBBVectorizePass();
(void) llvm::createPartiallyInlineLibCallsPass();
(void) llvm::createScalarizerPass();
(void) llvm::createSeparateConstOffsetFromGEPPass();

(void)new llvm::IntervalPartition();
(void)new llvm::FindUsedTypes();
Expand Down
6 changes: 6 additions & 0 deletions include/llvm/Transforms/Scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ FunctionPass *createScalarizerPass();
// AddDiscriminators - Add DWARF path discriminators to the IR.
FunctionPass *createAddDiscriminatorsPass();

//===----------------------------------------------------------------------===//
//
// SeparateConstOffsetFromGEP - Split GEPs for better CSE
//
FunctionPass *createSeparateConstOffsetFromGEPPass();

} // End llvm namespace

#endif
21 changes: 17 additions & 4 deletions lib/Target/NVPTX/NVPTXTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,23 @@ void NVPTXPassConfig::addIRPasses() {
addPass(createNVPTXAssignValidGlobalNamesPass());
addPass(createGenericToNVVMPass());
addPass(createNVPTXFavorNonGenericAddrSpacesPass());
// The FavorNonGenericAddrSpaces pass may remove instructions and leave some
// values unused. Therefore, we run a DCE pass right afterwards. We could
// remove unused values in an ad-hoc manner, but it requires manual work and
// might be error-prone.
addPass(createSeparateConstOffsetFromGEPPass());
// The SeparateConstOffsetFromGEP pass creates variadic bases that can be used
// by multiple GEPs. Run GVN or EarlyCSE to really reuse them. GVN generates
// significantly better code than EarlyCSE for some of our benchmarks.
if (getOptLevel() == CodeGenOpt::Aggressive)
addPass(createGVNPass());
else
addPass(createEarlyCSEPass());
// Both FavorNonGenericAddrSpaces and SeparateConstOffsetFromGEP may leave
// some dead code. We could remove dead code in an ad-hoc manner, but that
// requires manual work and might be error-prone.
//
// The FavorNonGenericAddrSpaces pass shortcuts unnecessary addrspacecasts,
// and leave them unused.
//
// SeparateConstOffsetFromGEP rebuilds a new index from the old index, and the
// old index and some of its intermediate results may become unused.
addPass(createDeadCodeEliminationPass());
}

Expand Down
1 change: 1 addition & 0 deletions lib/Transforms/Scalar/Scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
initializeStructurizeCFGPass(Registry);
initializeSinkingPass(Registry);
initializeTailCallElimPass(Registry);
initializeSeparateConstOffsetFromGEPPass(Registry);
}

void LLVMInitializeScalarOpts(LLVMPassRegistryRef R) {
Expand Down
Loading

0 comments on commit 167a57c

Please sign in to comment.