| 1 |
// RUN: fir-opt %s --test-side-effects --verify-diagnostics |
| 2 |
|
| 3 |
func.func @concat(%arg0: !fir.ref<!fir.char<1,10>>, %arg1: !fir.ref<!fir.char<1, 20>>) { |
| 4 |
// expected-remark@+1 {{operation has no memory effects}} |
| 5 |
%c30 = arith.constant 30 : index |
| 6 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 7 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 8 |
%0 = hlfir.concat %arg0, %arg1 len %c30 : (!fir.ref<!fir.char<1,10>>, !fir.ref<!fir.char<1,20>>, index) -> (!hlfir.expr<!fir.char<1,30>>) |
| 9 |
return |
| 10 |
} |
| 11 |
|
| 12 |
func.func @all_no_effects(%arg0: !hlfir.expr<2x!fir.logical<4>>) { |
| 13 |
// expected-remark@+1 {{operation has no memory effects}} |
| 14 |
%all = hlfir.all %arg0 : (!hlfir.expr<2x!fir.logical<4>>) -> !fir.logical<4> |
| 15 |
return |
| 16 |
} |
| 17 |
|
| 18 |
func.func @all_effects(%arg0: !fir.ref<!fir.array<2x10x!fir.logical<4>>>, %arg1: i32) { |
| 19 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 20 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 21 |
%all = hlfir.all %arg0 dim %arg1 : (!fir.ref<!fir.array<2x10x!fir.logical<4>>>, i32) -> !hlfir.expr<?x!fir.logical<4>> |
| 22 |
return |
| 23 |
} |
| 24 |
|
| 25 |
func.func @any_no_effects(%arg0: !hlfir.expr<2x!fir.logical<4>>) { |
| 26 |
// expected-remark@+1 {{operation has no memory effects}} |
| 27 |
%all = hlfir.any %arg0 : (!hlfir.expr<2x!fir.logical<4>>) -> !fir.logical<4> |
| 28 |
return |
| 29 |
} |
| 30 |
|
| 31 |
func.func @any_effects(%arg0: !fir.ref<!fir.array<2x10x!fir.logical<4>>>, %arg1: i32) { |
| 32 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 33 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 34 |
%all = hlfir.any %arg0 dim %arg1 : (!fir.ref<!fir.array<2x10x!fir.logical<4>>>, i32) -> !hlfir.expr<?x!fir.logical<4>> |
| 35 |
return |
| 36 |
} |
| 37 |
|
| 38 |
func.func @count_no_effects(%arg0: !hlfir.expr<2x!fir.logical<4>>) { |
| 39 |
// expected-remark@+1 {{operation has no memory effects}} |
| 40 |
%all = hlfir.count %arg0 : (!hlfir.expr<2x!fir.logical<4>>) -> i32 |
| 41 |
return |
| 42 |
} |
| 43 |
|
| 44 |
func.func @count_effects(%arg0: !fir.ref<!fir.array<2x10x!fir.logical<4>>>, %arg1: i32) { |
| 45 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 46 |
%all = hlfir.count %arg0 dim %arg1 : (!fir.ref<!fir.array<2x10x!fir.logical<4>>>, i32) -> i32 |
| 47 |
return |
| 48 |
} |
| 49 |
|
| 50 |
func.func @product_no_effects(%arg0: !hlfir.expr<?xf32>) { |
| 51 |
// expected-remark@+1 {{operation has no memory effects}} |
| 52 |
%product = hlfir.product %arg0 : (!hlfir.expr<?xf32>) -> f32 |
| 53 |
return |
| 54 |
} |
| 55 |
|
| 56 |
func.func @product_effects(%arg0: !fir.ref<!fir.array<2x2xf32>>, %arg1: i32) { |
| 57 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 58 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 59 |
%product = hlfir.product %arg0 dim %arg1 : (!fir.ref<!fir.array<2x2xf32>>, i32) -> !hlfir.expr<2xf32> |
| 60 |
return |
| 61 |
} |
| 62 |
|
| 63 |
func.func @set_length_read(%arg0: !fir.ref<!fir.char<1,10>>, %arg1: index) { |
| 64 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 65 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 66 |
%0 = hlfir.set_length %arg0 len %arg1 : (!fir.ref<!fir.char<1,10>>, index) -> !hlfir.expr<!fir.char<1,?>> |
| 67 |
return |
| 68 |
} |
| 69 |
|
| 70 |
func.func @sum_no_effects(%arg0: !hlfir.expr<?xf32>) { |
| 71 |
// expected-remark@+1 {{operation has no memory effects}} |
| 72 |
%sum = hlfir.sum %arg0 : (!hlfir.expr<?xf32>) -> f32 |
| 73 |
return |
| 74 |
} |
| 75 |
|
| 76 |
func.func @sum_effects(%arg0: !fir.ref<!fir.array<2x2xf32>>, %arg1: i32) { |
| 77 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 78 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 79 |
%sum = hlfir.sum %arg0 dim %arg1 : (!fir.ref<!fir.array<2x2xf32>>, i32) -> !hlfir.expr<2xf32> |
| 80 |
return |
| 81 |
} |
| 82 |
|
| 83 |
func.func @maxval_no_effects(%arg0: !hlfir.expr<?xf32>) { |
| 84 |
// expected-remark@+1 {{operation has no memory effects}} |
| 85 |
%maxval = hlfir.maxval %arg0 : (!hlfir.expr<?xf32>) -> f32 |
| 86 |
return |
| 87 |
} |
| 88 |
|
| 89 |
func.func @maxval_effects(%arg0: !fir.ref<!fir.array<2x2xf32>>, %arg1: i32) { |
| 90 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 91 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 92 |
%maxval = hlfir.maxval %arg0 dim %arg1 : (!fir.ref<!fir.array<2x2xf32>>, i32) -> !hlfir.expr<2xf32> |
| 93 |
return |
| 94 |
} |
| 95 |
|
| 96 |
func.func @minval_no_effects(%arg0: !hlfir.expr<?xf32>) { |
| 97 |
// expected-remark@+1 {{operation has no memory effects}} |
| 98 |
%minval = hlfir.minval %arg0 : (!hlfir.expr<?xf32>) -> f32 |
| 99 |
return |
| 100 |
} |
| 101 |
|
| 102 |
func.func @minval_effects(%arg0: !fir.ref<!fir.array<2x2xf32>>, %arg1: i32) { |
| 103 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 104 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 105 |
%minval = hlfir.minval %arg0 dim %arg1 : (!fir.ref<!fir.array<2x2xf32>>, i32) -> !hlfir.expr<2xf32> |
| 106 |
return |
| 107 |
} |
| 108 |
|
| 109 |
func.func @minloc_effects_simple(%arg0: !hlfir.expr<?xf32>) { |
| 110 |
// expected-remark@+1 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 111 |
%minloc = hlfir.minloc %arg0 : (!hlfir.expr<?xf32>) -> !hlfir.expr<?xi32> |
| 112 |
return |
| 113 |
} |
| 114 |
|
| 115 |
func.func @minloc_effects(%arg0: !fir.ref<!fir.array<2x2xf32>>, %arg1: i32) { |
| 116 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 117 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 118 |
%minloc = hlfir.minloc %arg0 dim %arg1 : (!fir.ref<!fir.array<2x2xf32>>, i32) -> !hlfir.expr<2xi32> |
| 119 |
return |
| 120 |
} |
| 121 |
|
| 122 |
func.func @maxloc_effects_simple(%arg0: !hlfir.expr<?xf32>) { |
| 123 |
// expected-remark@+1 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 124 |
%maxloc = hlfir.maxloc %arg0 : (!hlfir.expr<?xf32>) -> !hlfir.expr<?xi32> |
| 125 |
return |
| 126 |
} |
| 127 |
|
| 128 |
func.func @maxloc_effects(%arg0: !fir.ref<!fir.array<2x2xf32>>, %arg1: i32) { |
| 129 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 130 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 131 |
%maxloc = hlfir.maxloc %arg0 dim %arg1 : (!fir.ref<!fir.array<2x2xf32>>, i32) -> !hlfir.expr<2xi32> |
| 132 |
return |
| 133 |
} |
| 134 |
|
| 135 |
func.func @dot_product_no_effects(%arg0: !hlfir.expr<?xf32>, %arg1: !hlfir.expr<?xf32>) { |
| 136 |
// expected-remark@+1 {{operation has no memory effects}} |
| 137 |
%0 = hlfir.dot_product %arg0 %arg1 : (!hlfir.expr<?xf32>, !hlfir.expr<?xf32>) -> f32 |
| 138 |
return |
| 139 |
} |
| 140 |
|
| 141 |
func.func @dot_product_effects(%arg0: !fir.ref<!fir.array<10xf32>>, %arg1: !fir.ref<!fir.array<10xf32>>) { |
| 142 |
// there are read effects on both arguments - the diagnostic verification just doesn't register duplicate identical diagnostics |
| 143 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 144 |
%0 = hlfir.dot_product %arg0 %arg1 : (!fir.ref<!fir.array<10xf32>>, !fir.ref<!fir.array<10xf32>>) -> f32 |
| 145 |
return |
| 146 |
} |
| 147 |
|
| 148 |
func.func @matmul_no_reads(%arg0: !hlfir.expr<?x?xf32>, %arg1: !hlfir.expr<?x?xf32>) { |
| 149 |
// expected-remark@+1 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 150 |
%0 = hlfir.matmul %arg0 %arg1 : (!hlfir.expr<?x?xf32>, !hlfir.expr<?x?xf32>) -> !hlfir.expr<?x?xf32> |
| 151 |
return |
| 152 |
} |
| 153 |
|
| 154 |
func.func @matmul_reads(%arg0: !fir.ref<!fir.array<10x5xf32>>, %arg1: !fir.ref<!fir.array<5x10xf32>>) { |
| 155 |
// expected-remark@+3 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 156 |
// there are read effects on both arguments - the diagnostic verification just doesn't register duplicate identical diagnostics |
| 157 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 158 |
%0 = hlfir.matmul %arg0 %arg1 : (!fir.ref<!fir.array<10x5xf32>>, !fir.ref<!fir.array<5x10xf32>>) -> !hlfir.expr<10x10xf32> |
| 159 |
return |
| 160 |
} |
| 161 |
|
| 162 |
func.func @transpose_no_reads(%arg0: !hlfir.expr<?x?xf32>) { |
| 163 |
// expected-remark@+1 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 164 |
%0 = hlfir.transpose %arg0 : (!hlfir.expr<?x?xf32>) -> !hlfir.expr<?x?xf32> |
| 165 |
return |
| 166 |
} |
| 167 |
|
| 168 |
func.func @transpose_read(%arg0: !fir.ref<!fir.array<10x5xf32>>) { |
| 169 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 170 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 171 |
%0 = hlfir.transpose %arg0 : (!fir.ref<!fir.array<10x5xf32>>) -> !hlfir.expr<5x10xf32> |
| 172 |
return |
| 173 |
} |
| 174 |
|
| 175 |
func.func @matmul_transpose_no_reads(%arg0: !hlfir.expr<?x?xf32>, %arg1: !hlfir.expr<?x?xf32>) { |
| 176 |
// expected-remark@+1 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 177 |
%0 = hlfir.matmul_transpose %arg0 %arg1 : (!hlfir.expr<?x?xf32>, !hlfir.expr<?x?xf32>) -> !hlfir.expr<?x?xf32> |
| 178 |
return |
| 179 |
} |
| 180 |
|
| 181 |
func.func @matmul_transpose_reads(%arg0: !fir.ref<!fir.array<5x10xf32>>, %arg1: !fir.ref<!fir.array<5x10xf32>>) { |
| 182 |
// expected-remark@+3 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 183 |
// there are read effects on both arguments - the diagnostic verification just doesn't register duplicate identical diagnostics |
| 184 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 185 |
%0 = hlfir.matmul_transpose %arg0 %arg1 : (!fir.ref<!fir.array<5x10xf32>>, !fir.ref<!fir.array<5x10xf32>>) -> !hlfir.expr<10x10xf32> |
| 186 |
return |
| 187 |
} |
| 188 |
|
| 189 |
func.func @associate(%arg0: i32) { |
| 190 |
// expected-remark@+1 {{found an instance of 'allocate' on resource '<Default>'}} |
| 191 |
%0:3 = hlfir.associate %arg0 {uniq_name = "x"} : (i32) -> (!fir.ref<i32>, !fir.ref<i32>, i1) |
| 192 |
// expected-remark@+1 {{found an instance of 'free' on resource '<Default>'}} |
| 193 |
hlfir.end_associate %0#1, %0#2 : !fir.ref<i32>, i1 |
| 194 |
return |
| 195 |
} |
| 196 |
|
| 197 |
func.func @as_expr_read(%arg0: !fir.ref<!fir.array<2xi32>>) { |
| 198 |
// expected-remark@+2 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 199 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 200 |
%0 = hlfir.as_expr %arg0 : (!fir.ref<!fir.array<2xi32>>) -> !hlfir.expr<?xi32> |
| 201 |
// expected-remark@+1 {{found an instance of 'free' on resource '<Default>'}} |
| 202 |
hlfir.destroy %0 : !hlfir.expr<?xi32> |
| 203 |
return |
| 204 |
} |
| 205 |
|
| 206 |
func.func @char_extremum(%arg0: !fir.ref<!fir.char<1,10>>, %arg1: !fir.ref<!fir.char<1,20>>) { |
| 207 |
// expected-remark@+3 {{found an instance of 'allocate' on a op result, on resource '<Default>'}} |
| 208 |
// there are read effects on both arguments - the diagnostic verification just doesn't register duplicate identical diagnostics |
| 209 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 210 |
%0 = hlfir.char_extremum min, %arg0, %arg1 : (!fir.ref<!fir.char<1, 10>>, !fir.ref<!fir.char<1,20>>) -> !hlfir.expr<!fir.char<1,10>> |
| 211 |
return |
| 212 |
} |
| 213 |
|
| 214 |
func.func @copy_in(%box: !fir.box<!fir.array<?xf64>>, %temp: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>, %is_present: i1) { |
| 215 |
// expected-remark@+3 {{found an instance of 'allocate' on resource '<Default>'}} |
| 216 |
// expected-remark@+2 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 217 |
// expected-remark@+1 {{found an instance of 'write' on a op operand, on resource '<Default>'}} |
| 218 |
%0:2 = hlfir.copy_in %box to %temp : (!fir.box<!fir.array<?xf64>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>) -> (!fir.box<!fir.array<?xf64>>, i1) |
| 219 |
return |
| 220 |
} |
| 221 |
|
| 222 |
func.func @copy_out(%box: !fir.box<!fir.array<?xf64>>, %temp: !fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>, %was_copied: i1) { |
| 223 |
// expected-remark@+2 {{found an instance of 'free' on resource '<Default>'}} |
| 224 |
// expected-remark@+1 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 225 |
hlfir.copy_out %temp, %was_copied : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>, i1) -> () |
| 226 |
// expected-remark@+3 {{found an instance of 'free' on resource '<Default>'}} |
| 227 |
// expected-remark@+2 {{found an instance of 'read' on a op operand, on resource '<Default>'}} |
| 228 |
// expected-remark@+1 {{found an instance of 'write' on a op operand, on resource '<Default>'}} |
| 229 |
hlfir.copy_out %temp, %was_copied to %box : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xf64>>>>, i1, !fir.box<!fir.array<?xf64>>) -> () |
| 230 |
return |
| 231 |
} |