Skip to content

Commit 8a28e29

Browse files
committed
Iterate backwards to find all trivially dead ops
1 parent c96c163 commit 8a28e29

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ static bool isTransitivelyUsedOutside(Value v, SingleRegion sr) {
200200
/// We clone pure operations in both the parallel and single blocks. this
201201
/// functions cleans them up if they end up with no uses
202202
static void cleanupBlock(Block *block) {
203-
for (Operation &op : llvm::make_early_inc_range(*block))
203+
for (Operation &op : llvm::make_early_inc_range(
204+
llvm::make_range(block->rbegin(), block->rend())))
204205
if (isOpTriviallyDead(&op))
205206
op.erase();
206207
}
Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
11
// RUN: fir-opt --split-input-file --lower-workshare --allow-unregistered-dialect %s | FileCheck %s
22

3-
// Check that we cleanup unused pure operations from either the parallel or
4-
// single regions
3+
// Check that we cleanup unused pure operations from the parallel and single
4+
// regions
55

6+
// CHECK-LABEL: func.func @wsfunc() {
7+
// CHECK: %[[VAL_0:.*]] = fir.alloca i32
8+
// CHECK: omp.parallel {
9+
// CHECK: omp.single {
10+
// CHECK: %[[VAL_1:.*]] = "test.test1"() : () -> i32
11+
// CHECK: %[[VAL_2:.*]] = arith.constant 2 : index
12+
// CHECK: %[[VAL_3:.*]] = arith.constant 3 : index
13+
// CHECK: %[[VAL_4:.*]] = arith.addi %[[VAL_2]], %[[VAL_3]] : index
14+
// CHECK: "test.test3"(%[[VAL_4]]) : (index) -> ()
15+
// CHECK: omp.terminator
16+
// CHECK: }
17+
// CHECK: %[[VAL_5:.*]] = arith.constant 1 : index
18+
// CHECK: %[[VAL_6:.*]] = arith.constant 42 : index
19+
// CHECK: omp.wsloop nowait {
20+
// CHECK: omp.loop_nest (%[[VAL_7:.*]]) : index = (%[[VAL_5]]) to (%[[VAL_6]]) inclusive step (%[[VAL_5]]) {
21+
// CHECK: "test.test2"() : () -> ()
22+
// CHECK: omp.yield
23+
// CHECK: }
24+
// CHECK: omp.terminator
25+
// CHECK: }
26+
// CHECK: omp.barrier
27+
// CHECK: omp.terminator
28+
// CHECK: }
29+
// CHECK: return
30+
// CHECK: }
631
func.func @wsfunc() {
732
%a = fir.alloca i32
833
omp.parallel {
@@ -13,7 +38,9 @@ func.func @wsfunc() {
1338
%c42 = arith.constant 42 : index
1439

1540
%c2 = arith.constant 2 : index
16-
"test.test3"(%c2) : (index) -> ()
41+
%c3 = arith.constant 3 : index
42+
%add = arith.addi %c2, %c3 : index
43+
"test.test3"(%add) : (index) -> ()
1744

1845
omp.workshare_loop_wrapper {
1946
omp.loop_nest (%arg1) : index = (%c1) to (%c42) inclusive step (%c1) {
@@ -29,27 +56,4 @@ func.func @wsfunc() {
2956
return
3057
}
3158

32-
// CHECK-LABEL: func.func @wsfunc() {
33-
// CHECK: %[[VAL_0:.*]] = fir.alloca i32
34-
// CHECK: omp.parallel {
35-
// CHECK: omp.single {
36-
// CHECK: %[[VAL_1:.*]] = "test.test1"() : () -> i32
37-
// CHECK: %[[VAL_2:.*]] = arith.constant 2 : index
38-
// CHECK: "test.test3"(%[[VAL_2]]) : (index) -> ()
39-
// CHECK: omp.terminator
40-
// CHECK: }
41-
// CHECK: %[[VAL_3:.*]] = arith.constant 1 : index
42-
// CHECK: %[[VAL_4:.*]] = arith.constant 42 : index
43-
// CHECK: omp.wsloop nowait {
44-
// CHECK: omp.loop_nest (%[[VAL_5:.*]]) : index = (%[[VAL_3]]) to (%[[VAL_4]]) inclusive step (%[[VAL_3]]) {
45-
// CHECK: "test.test2"() : () -> ()
46-
// CHECK: omp.yield
47-
// CHECK: }
48-
// CHECK: omp.terminator
49-
// CHECK: }
50-
// CHECK: omp.barrier
51-
// CHECK: omp.terminator
52-
// CHECK: }
53-
// CHECK: return
54-
// CHECK: }
5559

0 commit comments

Comments
 (0)