80 lines · plain
1// RUN: fir-opt --split-input-file --fir-memref-dataflow-opt %s | FileCheck %s2 3// Test that all load-store chains are removed4 5func.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 : i647 %c60 = arith.constant 60 : index8 %c0 = arith.constant 0 : index9 %c1 = arith.constant 1 : index10 %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, ^bb214 %4 = arith.cmpi sgt, %3, %c0 : index15 cf.cond_br %4, ^bb2, ^bb316^bb2: // pred: ^bb117 %5 = fir.convert %2 : (index) -> i3218 fir.store %5 to %0 : !fir.ref<i32>19 %6 = fir.load %0 : !fir.ref<i32>20 %7 = fir.convert %6 : (i32) -> i6421 %8 = arith.subi %7, %c1_i64 : i6422 %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 : i3225 %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 : index28 %14 = arith.subi %3, %c1 : index29 cf.br ^bb1(%13, %14 : index, index)30^bb3: // pred: ^bb131 %15 = fir.convert %2 : (index) -> i3232 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, ^bb535 %18 = arith.cmpi sgt, %17, %c0 : index36 cf.cond_br %18, ^bb5, ^bb637^bb5: // pred: ^bb438 %19 = fir.convert %16 : (index) -> i3239 fir.store %19 to %0 : !fir.ref<i32>40 %20 = fir.load %0 : !fir.ref<i32>41 %21 = fir.convert %20 : (i32) -> i6442 %22 = arith.subi %21, %c1_i64 : i6443 %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 : i3248 %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 : index51 %30 = arith.subi %17, %c1 : index52 cf.br ^bb4(%29, %30 : index, index)53^bb6: // pred: ^bb454 %31 = fir.convert %16 : (index) -> i3255 fir.store %31 to %0 : !fir.ref<i32>56 return57}58 59// CHECK-LABEL: func @load_store_chain_removal60// CHECK-LABEL: ^bb161// CHECK-LABEL: ^bb2: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>66// CHECK-LABEL: ^bb3:67// Make sure the fir.store has been removed.68// CHECK-NOT: fir.store %{{.*}} to %{{.*}} : !fir.ref<i32>69// CHECK-LABEL: ^bb5:70// CHECK: %{{.*}} = fir.convert %{{.*}} : (index) -> i3271// 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) -> i6475// CHECK: %{{.*}} = fir.load %{{.*}} : !fir.ref<i32>76// CHECK: %{{.*}} = fir.load %{{.*}} : !fir.ref<i32>77// CHECK: fir.store %{{.*}} to %{{.*}} : !fir.ref<i32>78// CHECK-LABEL: ^bb6:79// CHECK-NOT: fir.store %{{.*}} to %{{.*}} : !fir.ref<i32>80