brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.0 KiB · 09c9516 Raw
132 lines · plain
1// Test array-copy-value pass (copy elision) with fir.array_modify2// RUN: fir-opt %s --array-value-copy | FileCheck %s3// RUN: fir-opt %s --array-value-copy="optimize-conflicts=true" | FileCheck %s4 5// Test user_defined_assignment(arg0(:), arg1(:))6func.func @no_overlap(%arg0: !fir.ref<!fir.array<100xf32>>, %arg1: !fir.ref<!fir.array<100xf32>>) {7  %c100 = arith.constant 100 : index8  %c99 = arith.constant 99 : index9  %c1 = arith.constant 1 : index10  %c0 = arith.constant 0 : index11  %0 = fir.alloca f3212  %1 = fir.shape %c100 : (index) -> !fir.shape<1>13  %2 = fir.array_load %arg0(%1) : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> !fir.array<100xf32>14  %3 = fir.array_load %arg1(%1) : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> !fir.array<100xf32>15  %4 = fir.do_loop %arg2 = %c0 to %c99 step %c1 unordered iter_args(%arg3 = %2) -> (!fir.array<100xf32>) {16    %5 = fir.array_fetch %3, %arg2 : (!fir.array<100xf32>, index) -> f3217    %6:2 = fir.array_modify %arg3, %arg2 : (!fir.array<100xf32>, index) -> (!fir.ref<f32>, !fir.array<100xf32>)18    fir.store %5 to %0 : !fir.ref<f32>19    fir.call @user_defined_assignment(%6#0, %0) : (!fir.ref<f32>, !fir.ref<f32>) -> ()20    fir.result %6#1 : !fir.array<100xf32>21  }22  fir.array_merge_store %2, %4 to %arg0 : !fir.array<100xf32>, !fir.array<100xf32>, !fir.ref<!fir.array<100xf32>>23  return24}25// CHECK-LABEL:   func @no_overlap(26// CHECK-SAME:                     %[[VAL_0:.*]]: !fir.ref<!fir.array<100xf32>>,27// CHECK-SAME:                     %[[VAL_1:.*]]: !fir.ref<!fir.array<100xf32>>) {28// CHECK-DAG:           %[[VAL_2:.*]] = arith.constant 100 : index29// CHECK-DAG:           %[[VAL_3:.*]] = arith.constant 99 : index30// CHECK-DAG:           %[[VAL_4:.*]] = arith.constant 1 : index31// CHECK-DAG:           %[[VAL_5:.*]] = arith.constant 0 : index32// CHECK:           %[[VAL_6:.*]] = fir.alloca f3233// CHECK:           %[[VAL_7:.*]] = fir.shape %[[VAL_2]] : (index) -> !fir.shape<1>34// CHECK:           %[[VAL_8:.*]] = fir.undefined !fir.array<100xf32>35// CHECK:           %[[VAL_9:.*]] = fir.undefined !fir.array<100xf32>36// CHECK:           %[[VAL_10:.*]] = fir.do_loop %[[VAL_11:.*]] = %[[VAL_5]] to %[[VAL_3]] step %[[VAL_4]] unordered iter_args(%[[VAL_12:.*]] = %[[VAL_8]]) -> (!fir.array<100xf32>) {37// CHECK:             %[[VAL_13:.*]] = arith.constant 1 : index38// CHECK:             %[[VAL_14:.*]] = arith.addi %[[VAL_11]], %[[VAL_13]] : index39// CHECK:             %[[VAL_15:.*]] = fir.array_coor %[[VAL_1]](%[[VAL_7]]) %[[VAL_14]] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>40// CHECK:             %[[VAL_16:.*]] = fir.load %[[VAL_15]] : !fir.ref<f32>41// CHECK:             %[[VAL_17:.*]] = arith.constant 1 : index42// CHECK:             %[[VAL_18:.*]] = arith.addi %[[VAL_11]], %[[VAL_17]] : index43// CHECK:             %[[VAL_19:.*]] = fir.array_coor %[[VAL_0]](%[[VAL_7]]) %[[VAL_18]] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>44// CHECK:             fir.store %[[VAL_16]] to %[[VAL_6]] : !fir.ref<f32>45// CHECK:             fir.call @user_defined_assignment(%[[VAL_19]], %[[VAL_6]]) : (!fir.ref<f32>, !fir.ref<f32>) -> ()46// CHECK:             fir.result %[[VAL_8]] : !fir.array<100xf32>47// CHECK:           }48// CHECK:           return49// CHECK:         }50 51 52// Test user_defined_assignment(arg0(:), arg0(100:1:-1))53func.func @overlap(%arg0: !fir.ref<!fir.array<100xf32>>) {54  %c100 = arith.constant 100 : index55  %c99 = arith.constant 99 : index56  %c1 = arith.constant 1 : index57  %c-1 = arith.constant -1 : index58  %c0 = arith.constant 0 : index59  %0 = fir.alloca f3260  %1 = fir.shape %c100 : (index) -> !fir.shape<1>61  %2 = fir.array_load %arg0(%1) : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>) -> !fir.array<100xf32>62  %3 = fir.slice %c100, %c1, %c-1 : (index, index, index) -> !fir.slice<1>63  %4 = fir.array_load %arg0(%1) [%3] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.slice<1>) -> !fir.array<100xf32>64  %5 = fir.do_loop %arg1 = %c0 to %c99 step %c1 unordered iter_args(%arg2 = %2) -> (!fir.array<100xf32>) {65    %6 = fir.array_fetch %4, %arg1 : (!fir.array<100xf32>, index) -> f3266    %7:2 = fir.array_modify %arg2, %arg1 : (!fir.array<100xf32>, index) -> (!fir.ref<f32>, !fir.array<100xf32>)67    fir.store %6 to %0 : !fir.ref<f32>68    fir.call @user_defined_assignment(%7#0, %0) : (!fir.ref<f32>, !fir.ref<f32>) -> ()69    fir.result %7#1 : !fir.array<100xf32>70  }71  fir.array_merge_store %2, %5 to %arg0 : !fir.array<100xf32>, !fir.array<100xf32>, !fir.ref<!fir.array<100xf32>>72  return73}74// CHECK-LABEL:   func @overlap(75// CHECK-SAME:                  %[[VAL_0:.*]]: !fir.ref<!fir.array<100xf32>>) {76// CHECK-DAG:           %[[VAL_1:.*]] = arith.constant 100 : index77// CHECK-DAG:           %[[VAL_2:.*]] = arith.constant 99 : index78// CHECK-DAG:           %[[VAL_3:.*]] = arith.constant 1 : index79// CHECK-DAG:           %[[VAL_4:.*]] = arith.constant -1 : index80// CHECK-DAG:           %[[VAL_5:.*]] = arith.constant 0 : index81// CHECK:           %[[VAL_6:.*]] = fir.alloca f3282// CHECK:           %[[VAL_7:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1>83// CHECK:           %[[VAL_8:.*]] = fir.allocmem !fir.array<100xf32>{{$}}84// CHECK:           %[[VAL_9:.*]] = fir.convert %[[VAL_1]] : (index) -> index85// CHECK:           %[[VAL_10:.*]] = arith.constant 0 : index86// CHECK:           %[[VAL_11:.*]] = arith.constant 1 : index87// CHECK:           %[[VAL_12:.*]] = arith.subi %[[VAL_9]], %[[VAL_11]] : index88// CHECK:           fir.do_loop %[[VAL_13:.*]] = %[[VAL_10]] to %[[VAL_12]] step %[[VAL_11]] {89// CHECK:             %[[VAL_14:.*]] = arith.constant 1 : index90// CHECK:             %[[VAL_15:.*]] = arith.addi %[[VAL_13]], %[[VAL_14]] : index91// CHECK:             %[[VAL_16:.*]] = fir.array_coor %[[VAL_0]](%[[VAL_7]]) %[[VAL_15]] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>92// CHECK:             %[[VAL_18:.*]] = arith.constant 1 : index93// CHECK:             %[[VAL_19:.*]] = arith.addi %[[VAL_13]], %[[VAL_18]] : index94// CHECK:             %[[VAL_20:.*]] = fir.array_coor %[[VAL_8]](%[[VAL_7]]) %[[VAL_19]] : (!fir.heap<!fir.array<100xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>95// CHECK:             %[[VAL_17:.*]] = fir.load %[[VAL_16]] : !fir.ref<f32>96// CHECK:             fir.store %[[VAL_17]] to %[[VAL_20]] : !fir.ref<f32>97// CHECK:           }98// CHECK:           %[[VAL_21:.*]] = fir.undefined !fir.array<100xf32>99// CHECK:           %[[VAL_22:.*]] = fir.slice %[[VAL_1]], %[[VAL_3]], %[[VAL_4]] : (index, index, index) -> !fir.slice<1>100// CHECK:           %[[VAL_23:.*]] = fir.undefined !fir.array<100xf32>101// CHECK:           %[[VAL_24:.*]] = fir.do_loop %[[VAL_25:.*]] = %[[VAL_5]] to %[[VAL_2]] step %[[VAL_3]] unordered iter_args(%[[VAL_26:.*]] = %[[VAL_21]]) -> (!fir.array<100xf32>) {102// CHECK:             %[[VAL_27:.*]] = arith.constant 1 : index103// CHECK:             %[[VAL_28:.*]] = arith.addi %[[VAL_25]], %[[VAL_27]] : index104// CHECK:             %[[VAL_29:.*]] = fir.array_coor %[[VAL_0]](%[[VAL_7]]) {{\[}}%[[VAL_22]]] %[[VAL_28]] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, !fir.slice<1>, index) -> !fir.ref<f32>105// CHECK:             %[[VAL_30:.*]] = fir.load %[[VAL_29]] : !fir.ref<f32>106// CHECK:             %[[VAL_31:.*]] = arith.constant 1 : index107// CHECK:             %[[VAL_32:.*]] = arith.addi %[[VAL_25]], %[[VAL_31]] : index108// CHECK:             %[[VAL_33:.*]] = fir.array_coor %[[VAL_8]](%[[VAL_7]]) %[[VAL_32]] : (!fir.heap<!fir.array<100xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>109// CHECK:             fir.store %[[VAL_30]] to %[[VAL_6]] : !fir.ref<f32>110// CHECK:             fir.call @user_defined_assignment(%[[VAL_33]], %[[VAL_6]]) : (!fir.ref<f32>, !fir.ref<f32>) -> ()111// CHECK:             fir.result %[[VAL_21]] : !fir.array<100xf32>112// CHECK:           }113// CHECK:           %[[VAL_34:.*]] = fir.convert %[[VAL_1]] : (index) -> index114// CHECK:           %[[VAL_35:.*]] = arith.constant 0 : index115// CHECK:           %[[VAL_36:.*]] = arith.constant 1 : index116// CHECK:           %[[VAL_37:.*]] = arith.subi %[[VAL_34]], %[[VAL_36]] : index117// CHECK:           fir.do_loop %[[VAL_38:.*]] = %[[VAL_35]] to %[[VAL_37]] step %[[VAL_36]] {118// CHECK:             %[[VAL_39:.*]] = arith.constant 1 : index119// CHECK:             %[[VAL_40:.*]] = arith.addi %[[VAL_38]], %[[VAL_39]] : index120// CHECK:             %[[VAL_41:.*]] = fir.array_coor %[[VAL_8]](%[[VAL_7]]) %[[VAL_40]] : (!fir.heap<!fir.array<100xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>121// CHECK:             %[[VAL_43:.*]] = arith.constant 1 : index122// CHECK:             %[[VAL_44:.*]] = arith.addi %[[VAL_38]], %[[VAL_43]] : index123// CHECK:             %[[VAL_45:.*]] = fir.array_coor %[[VAL_0]](%[[VAL_7]]) %[[VAL_44]] : (!fir.ref<!fir.array<100xf32>>, !fir.shape<1>, index) -> !fir.ref<f32>124// CHECK:             %[[VAL_42:.*]] = fir.load %[[VAL_41]] : !fir.ref<f32>125// CHECK:             fir.store %[[VAL_42]] to %[[VAL_45]] : !fir.ref<f32>126// CHECK:           }127// CHECK:           fir.freemem %[[VAL_8]] : !fir.heap<!fir.array<100xf32>>128// CHECK:           return129// CHECK:         }130 131func.func private @user_defined_assignment(!fir.ref<f32>, !fir.ref<f32>)132