Skip to content

Commit c900d26

Browse files
committed
[WIP] Try to fix more SCEV stuff
1 parent c843a3a commit c900d26

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,14 @@ bool RISCVTTIImpl::isLegalBaseRegForLSR(const SCEV *S) const {
24182418
return false;
24192419
}
24202420
}
2421+
if (const auto *Add = dyn_cast<SCEVAddExpr>(S)) {
2422+
const auto *Offset = dyn_cast<SCEVConstant>(Add->getOperand(0));
2423+
if (Offset && Offset->getValue()->isNegative())
2424+
return false;
2425+
Offset = dyn_cast<SCEVConstant>(Add->getOperand(1));
2426+
if (Offset && Offset->getValue()->isNegative())
2427+
return false;
2428+
}
24212429
}
24222430
return BasicTTIImplBase::isLegalBaseRegForLSR(S);
24232431
}

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,14 @@ void Cost::RateFormula(const Formula &F,
15021502
if (isLoser())
15031503
return;
15041504
assert(F.isCanonical(*L) && "Cost is accurate only for canonical formula");
1505+
1506+
for (const SCEV *Reg : Regs) {
1507+
if (!TTI->isLegalBaseRegForLSR(Reg)) {
1508+
Lose();
1509+
return;
1510+
}
1511+
}
1512+
15051513
// Tally up the registers.
15061514
unsigned PrevAddRecCost = C.AddRecCost;
15071515
unsigned PrevNumRegs = C.NumRegs;

0 commit comments

Comments
 (0)