forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add operands to worklist when only used by deleted op (llvm#86990)
I believe the existing check to determine if an operand should be added is incorrect: `operand.use_empty() || operand.hasOneUse()`. This is because these checks do not take into account the fact that the op is being deleted. It hasn't been deleted yet, so `operand.use_empty()` cannot be true, and `operand.hasOneUse()` may be true if the op being deleted is the only user of the operand and it only uses it once, but it will fail if the operand is used more than once (e.g. something like `add %0, %0`). Instead, check if the op being deleted is the only _user_ of the operand. If so, add the operand to the worklist. Fixes llvm#86765
- Loading branch information
mlevesquedion
committed
Mar 29, 2024
1 parent
cc8c6b0
commit ddc9892
Showing
4 changed files
with
92 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// RUN: mlir-opt %s -test-patterns="max-iterations=1 top-down=true" \ | ||
// RUN: --split-input-file | FileCheck %s | ||
|
||
// Tests for https://github.com/llvm/llvm-project/issues/86765. Ensure | ||
// that operands of a dead op are added to the worklist even if the same value | ||
// appears multiple times as an operand. | ||
|
||
// 2 uses of the same operand | ||
|
||
// CHECK: func.func @f(%arg0: i1) { | ||
// CHECK-NEXT: return | ||
// CHECK-NEXT: } | ||
func.func @f(%arg0: i1) { | ||
%0 = arith.constant 0 : i32 | ||
%if = scf.if %arg0 -> (i32) { | ||
scf.yield %0 : i32 | ||
} else { | ||
scf.yield %0 : i32 | ||
} | ||
%dead_leaf = arith.addi %if, %if : i32 | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
// 3 uses of the same operand | ||
|
||
// CHECK: func.func @f() { | ||
// CHECK-NEXT: return | ||
// CHECK-NEXT: } | ||
func.func @f() { | ||
%0 = arith.constant 0 : i1 | ||
%if = scf.if %0 -> (i1) { | ||
scf.yield %0 : i1 | ||
} else { | ||
scf.yield %0 : i1 | ||
} | ||
%dead_leaf = arith.select %if, %if, %if : i1 | ||
return | ||
} | ||
|
||
// ----- | ||
|
||
// 2 uses of the same operand, op has 3 operands | ||
|
||
// CHECK: func.func @f() { | ||
// CHECK-NEXT: return | ||
// CHECK-NEXT: } | ||
func.func @f() { | ||
%0 = arith.constant 0 : i1 | ||
%if = scf.if %0 -> (i1) { | ||
scf.yield %0 : i1 | ||
} else { | ||
scf.yield %0 : i1 | ||
} | ||
%dead_leaf = arith.select %0, %if, %if : i1 | ||
return | ||
} |