Skip to content

Commit f21428d

Browse files
committed
fixup! Add some optimization remarks
1 parent 9b41ae3 commit f21428d

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

llvm/lib/Transforms/Vectorize/EVLIndVarSimplify.cpp

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/Analysis/IVDescriptors.h"
1717
#include "llvm/Analysis/LoopInfo.h"
1818
#include "llvm/Analysis/LoopPass.h"
19+
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
1920
#include "llvm/Analysis/ScalarEvolution.h"
2021
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
2122
#include "llvm/Analysis/ValueTracking.h"
@@ -43,19 +44,19 @@ static cl::opt<bool> EnableEVLIndVarSimplify(
4344
namespace {
4445
struct EVLIndVarSimplifyImpl {
4546
ScalarEvolution &SE;
47+
OptimizationRemarkEmitter *ORE = nullptr;
4648

47-
explicit EVLIndVarSimplifyImpl(LoopStandardAnalysisResults &LAR)
48-
: SE(LAR.SE) {}
49-
50-
explicit EVLIndVarSimplifyImpl(ScalarEvolution &SE) : SE(SE) {}
49+
EVLIndVarSimplifyImpl(LoopStandardAnalysisResults &LAR,
50+
OptimizationRemarkEmitter *ORE)
51+
: SE(LAR.SE), ORE(ORE) {}
5152

5253
// Returns true if modify the loop.
5354
bool run(Loop &L);
5455
};
5556
} // anonymous namespace
5657

57-
// Returns the constant part of vectorization factor from the induction
58-
// variable's step value SCEV expression.
58+
/// Returns the constant part of vectorization factor from the induction
59+
/// variable's step value SCEV expression.
5960
static uint32_t getVFFromIndVar(const SCEV *Step, const Function &F) {
6061
if (!Step)
6162
return 0U;
@@ -113,8 +114,17 @@ bool EVLIndVarSimplifyImpl::run(Loop &L) {
113114
InductionDescriptor IVD;
114115
PHINode *IndVar = L.getInductionVariable(SE);
115116
if (!IndVar || !L.getInductionDescriptor(SE, IVD)) {
117+
const char *Reason = (IndVar ? "induction descriptor is not available"
118+
: "cannot recognize induction variable");
116119
LLVM_DEBUG(dbgs() << "Cannot retrieve IV from loop " << L.getName()
117-
<< "\n");
120+
<< " because" << Reason << "\n");
121+
if (ORE) {
122+
ORE->emit([&]() {
123+
return OptimizationRemarkMissed(DEBUG_TYPE, "MissingIndVar",
124+
L.getStartLoc(), L.getHeader())
125+
<< "Cannot retrieve IV because " << ore::NV("Reason", Reason);
126+
});
127+
}
118128
return false;
119129
}
120130

@@ -205,6 +215,22 @@ bool EVLIndVarSimplifyImpl::run(Loop &L) {
205215
return false;
206216

207217
LLVM_DEBUG(dbgs() << "Using " << *EVLIndVar << " for EVL-based IndVar\n");
218+
if (ORE) {
219+
ORE->emit([&]() {
220+
DebugLoc DL;
221+
BasicBlock *Region = nullptr;
222+
if (auto *I = dyn_cast<Instruction>(EVLIndVar)) {
223+
DL = I->getDebugLoc();
224+
Region = I->getParent();
225+
} else {
226+
DL = L.getStartLoc();
227+
Region = L.getHeader();
228+
}
229+
return OptimizationRemark(DEBUG_TYPE, "UseEVLIndVar", DL, Region)
230+
<< "Using " << ore::NV("EVLIndVar", EVLIndVar)
231+
<< " for EVL-based IndVar";
232+
});
233+
}
208234

209235
// Create an EVL-based comparison and replace the branch to use it as
210236
// predicate.
@@ -240,7 +266,12 @@ bool EVLIndVarSimplifyImpl::run(Loop &L) {
240266
PreservedAnalyses EVLIndVarSimplifyPass::run(Loop &L, LoopAnalysisManager &LAM,
241267
LoopStandardAnalysisResults &AR,
242268
LPMUpdater &U) {
243-
if (EVLIndVarSimplifyImpl(AR).run(L))
269+
Function &F = *L.getHeader()->getParent();
270+
auto &FAMProxy = LAM.getResult<FunctionAnalysisManagerLoopProxy>(L, AR);
271+
OptimizationRemarkEmitter *ORE =
272+
FAMProxy.getCachedResult<OptimizationRemarkEmitterAnalysis>(F);
273+
274+
if (EVLIndVarSimplifyImpl(AR, ORE).run(L))
244275
return PreservedAnalyses::allInSet<CFGAnalyses>();
245276
return PreservedAnalyses::all();
246277
}

0 commit comments

Comments
 (0)