mirror of
https://github.com/zama-ai/concrete.git
synced 2026-04-17 03:00:54 -04:00
fix(compiler): Batching: Do not attempt to extract static bounds for dynamic loops
The batching pass erroneously assumes that any expression solely composed of an induction variable has static bounds. This commit adds a test for the lower bound, upper bound and step checking that they are indeed static before attempting to determine their static values.
This commit is contained in:
@@ -88,11 +88,16 @@ static mlir::OpFoldResult getValueAsOpFoldResult(mlir::Value v) {
|
||||
return v;
|
||||
}
|
||||
|
||||
// Checks whether `v` is a constant value of type index
|
||||
static bool isConstantIndexValue(mlir::Value v) {
|
||||
return v.getDefiningOp() &&
|
||||
llvm::isa<mlir::arith::ConstantIndexOp>(*v.getDefiningOp());
|
||||
}
|
||||
|
||||
/// Assumes that `v` is a constant index operation and returns the
|
||||
/// constant value as an `int64_t`.
|
||||
static int64_t getConstantIndexValue(mlir::Value v) {
|
||||
assert(v.getDefiningOp() &&
|
||||
llvm::isa<mlir::arith::ConstantIndexOp>(*v.getDefiningOp()));
|
||||
assert(isConstantIndexValue(v));
|
||||
|
||||
return llvm::dyn_cast<mlir::arith::ConstantIndexOp>(*v.getDefiningOp())
|
||||
.value();
|
||||
@@ -223,9 +228,12 @@ struct BoundsAndStep {
|
||||
/// operation.
|
||||
static std::optional<BoundsAndStep>
|
||||
getBoundsOfQuasiAffineIVExpression(mlir::Value expr, mlir::scf::ForOp forOp) {
|
||||
// Base case: expression is the induction variable itself -> return
|
||||
// loop bounds
|
||||
if (expr == forOp.getInductionVar()) {
|
||||
// Base case: expression is the induction variable itself -> check
|
||||
// if the bounds are static and return them
|
||||
if (expr == forOp.getInductionVar() &&
|
||||
isConstantIndexValue(forOp.getLowerBound()) &&
|
||||
isConstantIndexValue(forOp.getUpperBound()) &&
|
||||
isConstantIndexValue(forOp.getStep())) {
|
||||
return BoundsAndStep{getConstantIndexValue(forOp.getLowerBound()),
|
||||
getConstantIndexValue(forOp.getUpperBound()),
|
||||
getConstantIndexValue(forOp.getStep())};
|
||||
@@ -273,7 +281,7 @@ getBoundsOfQuasiAffineIVExpression(mlir::Value expr, mlir::scf::ForOp forOp) {
|
||||
}
|
||||
}
|
||||
|
||||
llvm_unreachable("Expression could not be evaluated statically");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/// Checks whether the expression `expr` is a quasi-affine expression
|
||||
|
||||
Reference in New Issue
Block a user