Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion mlir/include/mlir/IR/AffineMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,10 @@ AffineMap inverseAndBroadcastProjectedPermutation(AffineMap map);
/// potentially empty maps. Assumes each of the underlying map has 0 symbols.
/// The resulting map has a number of dims equal to the max of `maps`' dims and
/// the concatenated results as its results.
/// Returns an empty map if all input `maps` are empty.
///
/// This method asserts when `maps` is empty.
/// TODO: this should return an empty map when `maps` is empty but there is no
/// way to get the MLIRContext needed to construct it.
///
/// Example:
/// When applied to the following list of 3 affine maps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ static bool isOpOperandCanBeDroppedAfterFusedLinalgs(
// the bounds of the op can be still computed after dropping the selected
// operand. inversePermutation returns an empty AffineMap in case the
// concatanated indexing maps are not invertible.
return inversePermutation(concatAffineMaps(indexingMaps)) != AffineMap();
return !indexingMaps.empty() &&
inversePermutation(concatAffineMaps(indexingMaps)) != AffineMap();
}

/// Returns a set of indices of the producer's results which would
Expand Down
1 change: 1 addition & 0 deletions mlir/lib/IR/AffineMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ AffineMap mlir::inverseAndBroadcastProjectedPermutation(AffineMap map) {
}

AffineMap mlir::concatAffineMaps(ArrayRef<AffineMap> maps) {
assert(maps.size());
unsigned numResults = 0, numDims = 0, numSymbols = 0;
for (auto m : maps)
numResults += m.getNumResults();
Expand Down
31 changes: 31 additions & 0 deletions mlir/test/Dialect/Linalg/fusion-elementwise.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,34 @@ func.func @drop_unused_producer_result(%arg0 : tensor<?x?xf32>,
// CHECK: %[[FUSED_OP:.+]] = linalg.generic
// CHECK-SAME: ins(%[[ARG0]], %[[ARG1]] :
// CHECK: return %[[FUSED_OP]]

// -----

#map = affine_map<(d0) -> (d0)>
func.func @handle_unused_operands(%arg0: tensor<8xf32>, %arg1: tensor<8xf32>) -> tensor<8xf32> {
%cst_0 = arith.constant 0.000000e+00 : f32
%cst_1 = arith.constant 1.000000e+00 : f32
%0:2 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel"]} outs(%arg0, %arg1 : tensor<8xf32>, tensor<8xf32>) {
^bb0(%out: f32, %out_2: f32):
%1 = linalg.index 0 : index
%2 = arith.index_cast %1 : index to i64
%3 = arith.sitofp %2 : i64 to f32
%4 = arith.divf %3, %cst_0 : f32
linalg.yield %3, %4 : f32, f32
} -> (tensor<8xf32>, tensor<8xf32>)
linalg.generic {indexing_maps = [#map], iterator_types = ["parallel"]} ins(%0#1 : tensor<8xf32>) {
^bb0(%in: f32):
%2 = arith.cmpf one, %in, %cst_1 : f32
cf.assert %2, "Side effect op"
linalg.yield
}
func.return %arg1 : tensor<8xf32>
}

// CHECK-LABEL: func @handle_unused_operands
// CHECK-SAME: %[[ARG0:[a-zA-Z0-9]+]]: tensor<8xf32>
// CHECK-SAME: %[[ARG1:[a-zA-Z0-9]+]]: tensor<8xf32>
// CHECK: %[[EMPTY:.+]] = tensor.empty() : tensor<8xf32>
// CHECK: %[[FUSED_OP:.+]] = linalg.generic
// CHECK-SAME: outs(%[[EMPTY]] :
// CHECK-NOT: linalg.generic
Loading