diff options
author | Hongtao Yu <hoy@fb.com> | 2021-04-06 18:32:23 -0700 |
---|---|---|
committer | Hongtao Yu <hoy@fb.com> | 2021-04-07 22:45:35 -0700 |
commit | 2a2720a2dec4ad4fdc7ae58939448e51824a12c4 (patch) | |
tree | 46d9c5e67434b2343dc6f2daf56c8330d7128e7a /llvm/lib/CodeGen/CodeGenPrepare.cpp | |
parent | eb7f5eaf3500fd0502a8ee56cc227432430c382b (diff) | |
download | llvm-2a2720a2dec4ad4fdc7ae58939448e51824a12c4.zip llvm-2a2720a2dec4ad4fdc7ae58939448e51824a12c4.tar.gz llvm-2a2720a2dec4ad4fdc7ae58939448e51824a12c4.tar.bz2 |
[CSSPGO] Move pseudo probes to the beginning of a block to unblock SelectionDAG combine.
Pseudo probes, when scattered in a block, can be chained dependencies of other regular DAG nodes and block DAG combine optimizations. To fix this, scattered probes in a block are grouped and placed at the beginning of the block. This shouldn't affect the profile quality.
Test Plan:
Reviewed By: wenlei, wmi
Differential Revision: https://reviews.llvm.org/D100002
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index d4702820..156250a 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -405,6 +405,7 @@ class TypePromotionTransaction; bool dupRetToEnableTailCallOpts(BasicBlock *BB, bool &ModifiedDT); bool fixupDbgValue(Instruction *I); bool placeDbgValues(Function &F); + bool placePseudoProbes(Function &F); bool canFormExtLd(const SmallVectorImpl<Instruction *> &MovedExts, LoadInst *&LI, Instruction *&Inst, bool HasPromoted); bool tryToPromoteExts(TypePromotionTransaction &TPT, @@ -611,6 +612,7 @@ bool CodeGenPrepare::runOnFunction(Function &F) { // Do this last to clean up use-before-def scenarios introduced by other // preparatory transforms. EverMadeChange |= placeDbgValues(F); + EverMadeChange |= placePseudoProbes(F); #ifndef NDEBUG if (VerifyBFIUpdates) @@ -7989,6 +7991,28 @@ bool CodeGenPrepare::placeDbgValues(Function &F) { return MadeChange; } +// Group scattered pseudo probes in a block to favor SelectionDAG. Scattered +// probes can be chained dependencies of other regular DAG nodes and block DAG +// combine optimizations. +bool CodeGenPrepare::placePseudoProbes(Function &F) { + bool MadeChange = false; + for (auto &Block : F) { + // Move the rest probes to the beginning of the block. + auto FirstInst = Block.getFirstInsertionPt(); + while (FirstInst != Block.end() && FirstInst->isDebugOrPseudoInst()) + ++FirstInst; + BasicBlock::iterator I(FirstInst); + I++; + while (I != Block.end()) { + if (auto *II = dyn_cast<PseudoProbeInst>(I++)) { + II->moveBefore(&*FirstInst); + MadeChange = true; + } + } + } + return MadeChange; +} + /// Scale down both weights to fit into uint32_t. static void scaleWeights(uint64_t &NewTrue, uint64_t &NewFalse) { uint64_t NewMax = (NewTrue > NewFalse) ? NewTrue : NewFalse; |