Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GlobalOptimization] Do not hoist fill-like operations #19719

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions compiler/src/iree/compiler/Dialect/LinalgExt/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/IR/Builders.h"
#include "mlir/Transforms/RegionUtils.h"

namespace mlir::iree_compiler::IREE::LinalgExt {

Expand Down Expand Up @@ -363,6 +364,25 @@ bool isGatherlikeOp(Operation *op) {
return true;
}

bool isFillLikeOp(linalg::GenericOp linalgOp) {
// Check if there are any non-scalar inputs or non-scalar captures in the
// region.
for (Value input : linalgOp.getDpsInputs()) {
if (isa<ShapedType>(input.getType())) {
return false;
}
}

bool foundNonScalar = false;
visitUsedValuesDefinedAbove(linalgOp.getRegion(), [&](OpOperand *operand) {
if (isa<ShapedType>(operand->get().getType())) {
foundNonScalar = true;
}
});

return !foundNonScalar;
}

FailureOr<SmallVector<AffineMap>>
getIGEMMContractionIndexingMaps(linalg::LinalgOp linalgOp) {
MLIRContext *ctx = linalgOp->getContext();
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/iree/compiler/Dialect/LinalgExt/Utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,9 @@ bool isBroadcastingOp(linalg::LinalgOp op);
/// 2. `linalg.yield` consumes the result of a `tensor.extract_slice`
bool isGatherlikeOp(Operation *op);

/// Returns true if the operation is a GenericOp that has no tensor inputs,
/// either as inputs or as implicit captures.
bool isFillLikeOp(linalg::GenericOp op);

} // namespace mlir::iree_compiler::IREE::LinalgExt
#endif // IREE_COMPILER_DIALECT_LINALGEXT_UTILS_UTILS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "iree/compiler/Dialect/Encoding/IR/EncodingOps.h"
#include "iree/compiler/Dialect/LinalgExt/IR/LinalgExtDialect.h"
#include "iree/compiler/Dialect/LinalgExt/IR/LinalgExtOps.h"
#include "iree/compiler/Dialect/LinalgExt/Utils/Utils.h"
#include "iree/compiler/Dialect/Util/IR/UtilTypes.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
Expand Down Expand Up @@ -325,7 +326,7 @@ struct HoistableLinalgOpInterface
}
}
}
return !linalg::isaFillOpInterface(genericOp).has_value();
return !IREE::LinalgExt::isFillLikeOp(genericOp);
}
bool isAtomicallyHoistableOp(Operation *) const { return true; }
bool isOperandHoistable(Operation *, OpOperand *) const { return true; }
Expand Down
Loading