Skip to content

Commit

Permalink
Add case where offset is directly the induction variable, without aff…
Browse files Browse the repository at this point in the history
…ine.apply in between (Xilinx#616)
  • Loading branch information
erwei-xilinx authored Jun 24, 2024
1 parent b82f610 commit a5b66a1
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions mlir/lib/Util/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ LogicalResult air::canonicalizeWrapAndStrideList(OpBuilder builder,
SmallVector<Value> &offsets,
SmallVector<Value> &sizes,
SmallVector<Value> &strides) {
auto original_insert_point = builder.saveInsertionPoint();
bool erased = false;
for (auto i : erase_dims) {
auto const_offset = getConstantIntValue(offsets[i]);
Expand Down Expand Up @@ -871,8 +872,23 @@ LogicalResult air::canonicalizeWrapAndStrideList(OpBuilder builder,
} else {
// Get affine.apply which produces the offset ssa
Operation *offset_producer = offsets[i].getDefiningOp();
if (!offset_producer)
continue;
if (offset_producer && isa<arith::IndexCastOp>(offset_producer)) {
auto castOp = dyn_cast<arith::IndexCastOp>(offset_producer);
offsets[i] = castOp.getIn();
offset_producer = castOp.getIn().getDefiningOp();
}
if (!offset_producer) {
if (!affine::getForInductionVarOwner(offsets[i]))
continue;
auto afo = affine::getForInductionVarOwner(offsets[i]);
builder.setInsertionPointToStart(afo.getBody());
// Create a new affine.apply on affine.for ind. vars, as handle for
// subsequent offset composition.
auto sym0_expr = getAffineSymbolExpr(0, builder.getContext());
auto iv_map = AffineMap::get(0, 1, sym0_expr);
offset_producer = builder.create<affine::AffineApplyOp>(
builder.getUnknownLoc(), iv_map, offsets[i]);
}
if (auto exec = dyn_cast<air::ExecuteOp>(offset_producer))
offset_producer = exec.getChildOp();
auto affine_apply = dyn_cast<affine::AffineApplyOp>(offset_producer);
Expand Down Expand Up @@ -900,6 +916,7 @@ LogicalResult air::canonicalizeWrapAndStrideList(OpBuilder builder,
strides.erase(strides.begin() + i);
erased = true;
}
builder.restoreInsertionPoint(original_insert_point);
return erased;
};

Expand Down

0 comments on commit a5b66a1

Please sign in to comment.