1 // RUN: fir-opt --split-input-file --fir-memref-dataflow-opt %s | FileCheck %s
3 // Test that all load-store chains are removed
5 func.func @load_store_chain_removal(%arg0: !fir.ref<!fir.array<60xi32>>, %arg1: !fir.ref<!fir.array<60xi32>>, %arg2: !fir.ref<!fir.array<60xi32>>) {
6 %c1_i64 = arith.constant 1 : i64
7 %c60 = arith.constant 60 : index
8 %c0 = arith.constant 0 : index
9 %c1 = arith.constant 1 : index
10 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFf1dcEi"}
11 %1 = fir.alloca !fir.array<60xi32> {bindc_name = "t1", uniq_name = "_QFf1dcEt1"}
12 cf.br ^bb1(%c1, %c60 : index, index)
13 ^bb1(%2: index, %3: index): // 2 preds: ^bb0, ^bb2
14 %4 = arith.cmpi sgt, %3, %c0 : index
15 cf.cond_br %4, ^bb2, ^bb3
17 %5 = fir.convert %2 : (index) -> i32
18 fir.store %5 to %0 : !fir.ref<i32>
19 %6 = fir.load %0 : !fir.ref<i32>
20 %7 = fir.convert %6 : (i32) -> i64
21 %8 = arith.subi %7, %c1_i64 : i64
22 %9 = fir.coordinate_of %arg0, %8 : (!fir.ref<!fir.array<60xi32>>, i64) -> !fir.ref<i32>
23 %10 = fir.load %9 : !fir.ref<i32>
24 %11 = arith.addi %10, %10 : i32
25 %12 = fir.coordinate_of %1, %8 : (!fir.ref<!fir.array<60xi32>>, i64) -> !fir.ref<i32>
26 fir.store %11 to %12 : !fir.ref<i32>
27 %13 = arith.addi %2, %c1 : index
28 %14 = arith.subi %3, %c1 : index
29 cf.br ^bb1(%13, %14 : index, index)
31 %15 = fir.convert %2 : (index) -> i32
32 fir.store %15 to %0 : !fir.ref<i32>
33 cf.br ^bb4(%c1, %c60 : index, index)
34 ^bb4(%16: index, %17: index): // 2 preds: ^bb3, ^bb5
35 %18 = arith.cmpi sgt, %17, %c0 : index
36 cf.cond_br %18, ^bb5, ^bb6
38 %19 = fir.convert %16 : (index) -> i32
39 fir.store %19 to %0 : !fir.ref<i32>
40 %20 = fir.load %0 : !fir.ref<i32>
41 %21 = fir.convert %20 : (i32) -> i64
42 %22 = arith.subi %21, %c1_i64 : i64
43 %23 = fir.coordinate_of %1, %22 : (!fir.ref<!fir.array<60xi32>>, i64) -> !fir.ref<i32>
44 %24 = fir.load %23 : !fir.ref<i32>
45 %25 = fir.coordinate_of %arg1, %22 : (!fir.ref<!fir.array<60xi32>>, i64) -> !fir.ref<i32>
46 %26 = fir.load %25 : !fir.ref<i32>
47 %27 = arith.muli %24, %26 : i32
48 %28 = fir.coordinate_of %arg2, %22 : (!fir.ref<!fir.array<60xi32>>, i64) -> !fir.ref<i32>
49 fir.store %27 to %28 : !fir.ref<i32>
50 %29 = arith.addi %16, %c1 : index
51 %30 = arith.subi %17, %c1 : index
52 cf.br ^bb4(%29, %30 : index, index)
54 %31 = fir.convert %16 : (index) -> i32
55 fir.store %31 to %0 : !fir.ref<i32>
59 // CHECK-LABEL: func @load_store_chain_removal
62 // Make sure the previous fir.store/fir.load pair have been elimated and we
63 // preserve the last pair of fir.load/fir.store.
64 // CHECK-COUNT-1: %{{.*}} = fir.load %{{.*}} : !fir.ref<i32>
65 // CHECK-COUNT-1: fir.store %{{.*}} to %{{.*}} : !fir.ref<i32>
67 // Make sure the fir.store has been removed.
68 // CHECK-NOT: fir.store %{{.*}} to %{{.*}} : !fir.ref<i32>
70 // CHECK: %{{.*}} = fir.convert %{{.*}} : (index) -> i32
71 // Check that the fir.store/fir.load pair has been removed between the convert.
72 // CHECK-NOT: fir.store %{{.*}} to %{{.*}} : !fir.ref<i32>
73 // CHECK-NOT: %{{.*}} = fir.load %{{.*}} : !fir.ref<i32>
74 // CHECK: %{{.*}} = fir.convert %{{.*}} : (i32) -> i64
75 // CHECK: %{{.*}} = fir.load %{{.*}} : !fir.ref<i32>
76 // CHECK: %{{.*}} = fir.load %{{.*}} : !fir.ref<i32>
77 // CHECK: fir.store %{{.*}} to %{{.*}} : !fir.ref<i32>
79 // CHECK-NOT: fir.store %{{.*}} to %{{.*}} : !fir.ref<i32>