Skip to content

Commit 896009b

Browse files
committed
fixup! Address review comments
And add more optimization remarks
1 parent 8616f22 commit 896009b

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

llvm/lib/Transforms/Vectorize/EVLIndVarSimplify.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ static uint32_t getVFFromIndVar(const SCEV *Step, const Function &F) {
6363

6464
// Looking for loops with IV step value in the form of `(<constant VF> x
6565
// vscale)`.
66-
if (auto *Mul = dyn_cast<SCEVMulExpr>(Step)) {
66+
if (const auto *Mul = dyn_cast<SCEVMulExpr>(Step)) {
6767
if (Mul->getNumOperands() == 2) {
6868
const SCEV *LHS = Mul->getOperand(0);
6969
const SCEV *RHS = Mul->getOperand(1);
70-
if (auto *Const = dyn_cast<SCEVConstant>(LHS)) {
70+
if (const auto *Const = dyn_cast<SCEVConstant>(LHS);
71+
Const && isa<SCEVVScale>(RHS)) {
7172
uint64_t V = Const->getAPInt().getLimitedValue();
72-
if (isa<SCEVVScale>(RHS) && llvm::isUInt<32>(V))
73+
if (llvm::isUInt<32>(V))
7374
return V;
7475
}
7576
}
@@ -78,7 +79,7 @@ static uint32_t getVFFromIndVar(const SCEV *Step, const Function &F) {
7879
// If not, see if the vscale_range of the parent function is a fixed value,
7980
// which makes the step value to be replaced by a constant.
8081
if (F.hasFnAttribute(Attribute::VScaleRange))
81-
if (auto *ConstStep = dyn_cast<SCEVConstant>(Step)) {
82+
if (const auto *ConstStep = dyn_cast<SCEVConstant>(Step)) {
8283
APInt V = ConstStep->getAPInt().abs();
8384
ConstantRange CR = llvm::getVScaleRange(&F, 64);
8485
if (const APInt *Fixed = CR.getSingleElement()) {
@@ -120,7 +121,7 @@ bool EVLIndVarSimplifyImpl::run(Loop &L) {
120121
<< " because" << Reason << "\n");
121122
if (ORE) {
122123
ORE->emit([&]() {
123-
return OptimizationRemarkMissed(DEBUG_TYPE, "MissingIndVar",
124+
return OptimizationRemarkMissed(DEBUG_TYPE, "UnrecognizedIndVar",
124125
L.getStartLoc(), L.getHeader())
125126
<< "Cannot retrieve IV because " << ore::NV("Reason", Reason);
126127
});
@@ -132,6 +133,13 @@ bool EVLIndVarSimplifyImpl::run(Loop &L) {
132133
if (!L.getIncomingAndBackEdge(InitBlock, BackEdgeBlock)) {
133134
LLVM_DEBUG(dbgs() << "Expect unique incoming and backedge in "
134135
<< L.getName() << "\n");
136+
if (ORE) {
137+
ORE->emit([&]() {
138+
return OptimizationRemarkMissed(DEBUG_TYPE, "UnrecognizedLoopStructure",
139+
L.getStartLoc(), L.getHeader())
140+
<< "Does not have a unique incoming and backedge";
141+
});
142+
}
135143
return false;
136144
}
137145

@@ -140,6 +148,13 @@ bool EVLIndVarSimplifyImpl::run(Loop &L) {
140148
if (!Bounds) {
141149
LLVM_DEBUG(dbgs() << "Could not obtain the bounds for loop " << L.getName()
142150
<< "\n");
151+
if (ORE) {
152+
ORE->emit([&]() {
153+
return OptimizationRemarkMissed(DEBUG_TYPE, "UnrecognizedLoopStructure",
154+
L.getStartLoc(), L.getHeader())
155+
<< "Could not obtain the loop bounds";
156+
});
157+
}
143158
return false;
144159
}
145160
Value *CanonicalIVInit = &Bounds->getInitialIVValue();
@@ -150,6 +165,14 @@ bool EVLIndVarSimplifyImpl::run(Loop &L) {
150165
if (!VF) {
151166
LLVM_DEBUG(dbgs() << "Could not infer VF from IndVar step '" << *StepV
152167
<< "'\n");
168+
if (ORE) {
169+
ORE->emit([&]() {
170+
return OptimizationRemarkMissed(DEBUG_TYPE, "UnrecognizedIndVar",
171+
L.getStartLoc(), L.getHeader())
172+
<< "Could not infer VF from IndVar step "
173+
<< ore::NV("Step", StepV);
174+
});
175+
}
153176
return false;
154177
}
155178
LLVM_DEBUG(dbgs() << "Using VF=" << VF << " for loop " << L.getName()
@@ -196,7 +219,7 @@ bool EVLIndVarSimplifyImpl::run(Loop &L) {
196219
break;
197220
}
198221
Value *RecValue = PN.getIncomingValueForBlock(BackEdgeBlock);
199-
assert(RecValue);
222+
assert(RecValue && "expect recurrent IndVar value");
200223

201224
LLVM_DEBUG(dbgs() << "Found candidate PN of EVL-based IndVar: " << PN
202225
<< "\n");
@@ -238,7 +261,8 @@ bool EVLIndVarSimplifyImpl::run(Loop &L) {
238261
// Loop::getLatchCmpInst check at the beginning of this function has ensured
239262
// that latch block ends in a conditional branch.
240263
auto *LatchBranch = cast<BranchInst>(LatchBlock->getTerminator());
241-
assert(LatchBranch->isConditional());
264+
assert(LatchBranch->isConditional() &&
265+
"expect the loop latch to be ended with a conditional branch");
242266
ICmpInst::Predicate Pred;
243267
if (LatchBranch->getSuccessor(0) == L.getHeader())
244268
Pred = ICmpInst::ICMP_NE;

0 commit comments

Comments
 (0)