Skip to content

Commit 4aabe7a

Browse files
committed
[WIP] Try to fix more SCEV stuff
1 parent 465ec58 commit 4aabe7a

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,20 +2404,28 @@ RISCVTTIImpl::getPreferredAddressingMode(const Loop *L,
24042404

24052405
bool RISCVTTIImpl::isLegalBaseRegForLSR(const SCEV *S) const {
24062406
if (ST->hasVendorXCheriot()) {
2407-
// Disallow any add-recurrence SCEV where the base offset is negative.
2407+
// Disallow any SCEV where the base offset is negative.
24082408
// This is needed because CHERIoT can't represent pointers before the
24092409
// beginning of an array.
2410+
auto IsAddOfNegativeCst = [](const SCEVAddExpr *A) {
2411+
if (!A)
2412+
return false;
2413+
const auto *Offset = dyn_cast<SCEVConstant>(A->getOperand(0));
2414+
if (Offset && Offset->getValue()->isNegative())
2415+
return true;
2416+
Offset = dyn_cast<SCEVConstant>(A->getOperand(1));
2417+
if (Offset && Offset->getValue()->isNegative())
2418+
return true;
2419+
return false;
2420+
};
2421+
24102422
if (const auto *AddRec = dyn_cast<SCEVAddRecExpr>(S)) {
2411-
const auto *StartAdd = dyn_cast<SCEVAddExpr>(AddRec->getStart());
2412-
if (StartAdd) {
2413-
const auto *Offset = dyn_cast<SCEVConstant>(StartAdd->getOperand(0));
2414-
if (Offset && Offset->getValue()->isNegative())
2415-
return false;
2416-
Offset = dyn_cast<SCEVConstant>(StartAdd->getOperand(1));
2417-
if (Offset && Offset->getValue()->isNegative())
2418-
return false;
2419-
}
2423+
if (const auto *Cst = dyn_cast<SCEVConstant>(AddRec->getStart()))
2424+
return !Cst->getValue()->isNegative();
2425+
return !IsAddOfNegativeCst(dyn_cast<SCEVAddExpr>(AddRec->getStart()));
24202426
}
2427+
2428+
return !IsAddOfNegativeCst(dyn_cast<SCEVAddExpr>(S));
24212429
}
24222430
return BasicTTIImplBase::isLegalBaseRegForLSR(S);
24232431
}

0 commit comments

Comments
 (0)