Skip to content

Commit b0032a9

Browse files
committed
Add
1 parent 1cec5ff commit b0032a9

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ ChangeResult Liveness::meet(const AbstractSparseLattice &other) {
4949
/// For every value, liveness analysis determines whether or not it is "live".
5050
///
5151
/// A value is considered "live" iff it:
52-
/// (1) has memory effects OR
53-
/// (2) is returned by a public function OR
54-
/// (3) is used to compute a value of type (1) or (2).
52+
/// (1) has memory effects
53+
/// (2) is returned by a public function
54+
/// (3) is used to compute a value of type (1) or (2) OR
55+
/// (4) is returned by a return-like op whose parent isn't a callable
56+
/// (e.g.: linalg.yield, gpu.yield,...) These ops have their own
57+
/// semantics, so we conservatively mark the value as live.
5558
/// It is also to be noted that a value could be of multiple types (1/2/3) at
5659
/// the same time.
5760
///
@@ -73,8 +76,8 @@ ChangeResult Liveness::meet(const AbstractSparseLattice &other) {
7376
LogicalResult
7477
LivenessAnalysis::visitOperation(Operation *op, ArrayRef<Liveness *> operands,
7578
ArrayRef<const Liveness *> results) {
76-
// This marks values of type (1.a) liveness as "live".
77-
if (!isMemoryEffectFree(op)) {
79+
// This marks values of type (1.a) and (4) liveness as "live".
80+
if (!isMemoryEffectFree(op) || op->hasTrait<OpTrait::ReturnLike>()) {
7881
for (auto *operand : operands)
7982
propagateIfChanged(operand, operand->markLive());
8083
}

mlir/test/Transforms/remove-dead-values.mlir

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,40 @@ func.func private @no_block_func_declaration() -> ()
468468

469469
// CHECK: llvm.func @no_block_external_func()
470470
llvm.func @no_block_external_func() attributes {sym_visibility = "private"}
471+
472+
// -----
473+
474+
// Check that yielded values aren't incorrectly removed in gpu regions
475+
gpu.module @test_module_3 {
476+
gpu.func @gpu_all_reduce_region() {
477+
%arg0 = arith.constant 1 : i32
478+
%result = gpu.all_reduce %arg0 uniform {
479+
^bb(%lhs : i32, %rhs : i32):
480+
%xor = arith.xori %lhs, %rhs : i32
481+
"gpu.yield"(%xor) : (i32) -> ()
482+
} : (i32) -> (i32)
483+
gpu.return
484+
}
485+
}
486+
487+
// CHECK-LABEL: func @gpu_all_reduce_region()
488+
// CHECK: %[[yield:.*]] = arith.xori %{{.*}}, %{{.*}} : i32
489+
// CHECK: "gpu.yield"(%[[yield]]) : (i32) -> ()
490+
491+
// -----
492+
493+
// Check that yielded values aren't incorrectly removed in linalg regions
494+
module {
495+
func.func @linalg_red_add(%arg0: tensor<?xf32>, %arg1: tensor<1xf32>) -> tensor<1xf32> {
496+
%0 = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["reduction"]} ins(%arg0 : tensor<?xf32>) outs(%arg1 : tensor<1xf32>) {
497+
^bb0(%in: f32, %out: f32):
498+
%1 = arith.addf %in, %out : f32
499+
linalg.yield %1 : f32
500+
} -> tensor<1xf32>
501+
return %0 : tensor<1xf32>
502+
}
503+
}
504+
505+
// CHECK-LABEL: func @linalg_red_add
506+
// CHECK: %[[yield:.*]] = arith.addf %{{.*}}, %{{.*}} : f32
507+
// CHECK: linalg.yield %[[yield]] : f32

0 commit comments

Comments
 (0)