aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp24
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;