Allow signed devision in access functions
llvm-svn: 228833
diff --git a/polly/lib/Support/SCEVValidator.cpp b/polly/lib/Support/SCEVValidator.cpp
index 57acef8..60daa4b 100644
--- a/polly/lib/Support/SCEVValidator.cpp
+++ b/polly/lib/Support/SCEVValidator.cpp
@@ -326,6 +326,30 @@
return ValidatorResult(SCEVType::PARAM, Expr);
}
+ ValidatorResult visitGenericInst(Instruction *I, const SCEV *S) {
+ if (R->contains(I)) {
+ DEBUG(dbgs() << "INVALID: UnknownExpr references an instruction "
+ "within the region\n");
+ return ValidatorResult(SCEVType::INVALID);
+ }
+
+ return ValidatorResult(SCEVType::PARAM, S);
+ }
+
+ ValidatorResult visitSDivInstruction(Instruction *SDiv, const SCEV *S) {
+ assert(SDiv->getOpcode() == Instruction::SDiv &&
+ "Assumed SDiv instruction!");
+
+ auto *Divisor = SDiv->getOperand(1);
+ auto *CI = dyn_cast<ConstantInt>(Divisor);
+ if (!CI)
+ return visitGenericInst(SDiv, S);
+
+ auto *Dividend = SDiv->getOperand(0);
+ auto *DividendSCEV = SE.getSCEV(Dividend);
+ return visit(DividendSCEV);
+ }
+
ValidatorResult visitUnknown(const SCEVUnknown *Expr) {
Value *V = Expr->getValue();
@@ -339,18 +363,20 @@
return ValidatorResult(SCEVType::INVALID);
}
- if (Instruction *I = dyn_cast<Instruction>(Expr->getValue()))
- if (R->contains(I)) {
- DEBUG(dbgs() << "INVALID: UnknownExpr references an instruction "
- "within the region\n");
- return ValidatorResult(SCEVType::INVALID);
- }
-
if (BaseAddress == V) {
DEBUG(dbgs() << "INVALID: UnknownExpr references BaseAddress\n");
return ValidatorResult(SCEVType::INVALID);
}
+ if (Instruction *I = dyn_cast<Instruction>(Expr->getValue())) {
+ switch (I->getOpcode()) {
+ case Instruction::SDiv:
+ return visitSDivInstruction(I, Expr);
+ default:
+ return visitGenericInst(I, Expr);
+ }
+ }
+
return ValidatorResult(SCEVType::PARAM, Expr);
}
};