Skip to content

Commit 4732b0c

Browse files
authored
[mlir][dataflow] Remove early exit in dead code analysis for zero-operand returns (llvm#68151)
The PredecessorState in dead code analysis does not register zero-operand returns as predecessors of their corresponding call ops. This causes bugs with dense dataflow analyses that use dead code analysis to query for the predecessors of CallOpInterfaces. This was reasonable for sparse analyses, but isn't for dense ones.
1 parent 18933c6 commit 4732b0c

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,6 @@ void DeadCodeAnalysis::visitRegionTerminator(
407407

408408
void DeadCodeAnalysis::visitCallableTerminator(Operation *op,
409409
CallableOpInterface callable) {
410-
// If there are no exiting values, we have nothing to do.
411-
if (op->getNumOperands() == 0)
412-
return;
413-
414410
// Add as predecessors to all callsites this return op.
415411
auto *callsites = getOrCreateFor<PredecessorState>(op, callable);
416412
bool canResolve = op->hasTrait<OpTrait::ReturnLike>();

mlir/test/Analysis/DataFlow/test-dead-code-analysis.mlir

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ func.func @test_callgraph(%cond: i1, %arg0: i32) -> i32 {
118118
return %2 : i32
119119
}
120120

121+
func.func private @bax(%arg0: i32) {
122+
return {void_return}
123+
}
124+
125+
func.func @test_callgraph_void_return(%arg0: i32) -> i32 {
126+
// CHECK: call_void_return:
127+
// CHECK: op_preds: (all) predecessors:
128+
// CHECK: func.return {void_return}
129+
func.call @bax(%arg0) {tag = "call_void_return"}: (i32) -> ()
130+
return %arg0 : i32
131+
}
132+
121133
// CHECK: test_unknown_branch:
122134
// CHECK: region #0
123135
// CHECK: ^bb0 = live

mlir/test/Analysis/DataFlow/test-last-modified-callgraph.mlir

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ func.func @test_multiple_return_sites(%cond: i1, %a: i32, %ptr: memref<i32>) ->
6868

6969
// -----
7070

71+
// CHECK-LABEL: test_tag: after_call
72+
// CHECK: operand #0
73+
// CHECK-NEXT: - write0
74+
func.func private @void_return(%ptr: memref<i32>) {
75+
return
76+
}
77+
78+
func.func @test_call_void_return() {
79+
%ptr = memref.alloc() : memref<i32>
80+
%c0 = arith.constant 0 : i32
81+
memref.store %c0, %ptr[] {tag_name = "write0"} : memref<i32>
82+
func.call @void_return(%ptr) : (memref<i32>) -> ()
83+
memref.load %ptr[] {tag = "after_call"} : memref<i32>
84+
return
85+
}
86+
87+
// -----
7188

7289
func.func private @callee(%arg0: memref<f32>) -> memref<f32> {
7390
%2 = arith.constant 2.0 : f32

0 commit comments

Comments
 (0)