1// RUN: mlir-opt -allow-unregistered-dialect %s -affine-super-vectorizer-test -forward-slicing=true 2>&1 | FileCheck %s --check-prefix=FWD 2// RUN: mlir-opt -allow-unregistered-dialect %s -affine-super-vectorizer-test -backward-slicing=true 2>&1 | FileCheck %s --check-prefix=BWD 3// RUN: mlir-opt -allow-unregistered-dialect %s -affine-super-vectorizer-test -slicing=true 2>&1 | FileCheck %s --check-prefix=FWDBWD 4 5/// 1 2 3 4 6/// |_______| |______| 7/// | | | 8/// | 5 6 9/// |___|_____________| 10/// | | 11/// 7 8 12/// |_______________| 13/// | 14/// 9 15// FWD-LABEL: slicing_test 16// BWD-LABEL: slicing_test 17// FWDBWD-LABEL: slicing_test 18func @slicing_test() { 19 // Fake 0 to align on 1 and match ASCII art. 20 %0 = alloc() : memref<1xi32> 21 22 // FWD: matched: %[[v1:.*]] {{.*}} forward static slice: 23 // FWD-NEXT: %[[v5:.*]] {{.*}} -> i5 24 // FWD-DAG: %[[v8:.*]] {{.*}} -> i8 25 // FWD-DAG: %[[v7:.*]] {{.*}} -> i7 26 // FWD-NEXT: %[[v9:.*]] {{.*}} -> i9 27 // 28 // BWD: matched: %[[v1:.*]] {{.*}} backward static slice: 29 // 30 // FWDBWD: matched: %[[v1:.*]] {{.*}} static slice: 31 // FWDBWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 32 // FWDBWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 33 // FWDBWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 34 // FWDBWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 35 // FWDBWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 36 // FWDBWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 37 // FWDBWD-DAG: %[[v8:.*]] = "slicing-test-op"(%[[v5]], %[[v6]]) : (i5, i6) -> i8 38 // FWDBWD-DAG: %[[v7:.*]] = "slicing-test-op"(%[[v1]], %[[v5]]) : (i1, i5) -> i7 39 // FWDBWD-NEXT: %[[v9:.*]] = "slicing-test-op"(%[[v7]], %[[v8]]) : (i7, i8) -> i9 40 41 %1 = "slicing-test-op" () : () -> i1 42 43 // FWD-NEXT: matched: %[[v2:.*]] {{.*}} forward static slice: 44 // FWD-NEXT: %[[v5:.*]] {{.*}} -> i5 45 // FWD-DAG: %[[v8:.*]] {{.*}} -> i8 46 // FWD-DAG: %[[v7:.*]] {{.*}} -> i7 47 // FWD-NEXT: %[[v9:.*]] {{.*}} -> i9 48 // 49 // BWD: matched: %[[v2:.*]] {{.*}} backward static slice: 50 // 51 // FWDBWD-NEXT: matched: %[[v2:.*]] {{.*}} static slice: 52 // FWDBWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 53 // FWDBWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 54 // FWDBWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 55 // FWDBWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 56 // FWDBWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 57 // FWDBWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 58 // FWDBWD-DAG: %[[v8:.*]] = "slicing-test-op"(%[[v5]], %[[v6]]) : (i5, i6) -> i8 59 // FWDBWD-DAG: %[[v7:.*]] = "slicing-test-op"(%[[v1]], %[[v5]]) : (i1, i5) -> i7 60 // FWDBWD-NEXT: %[[v9:.*]] = "slicing-test-op"(%[[v7]], %[[v8]]) : (i7, i8) -> i9 61 62 %2 = "slicing-test-op" () : () -> i2 63 64 // FWD-NEXT: matched: %[[v3:.*]] {{.*}} forward static slice: 65 // FWD-NEXT: %[[v6:.*]] {{.*}} -> i6 66 // FWD-NEXT: %[[v8:.*]] {{.*}} -> i8 67 // FWD-NEXT: %[[v9:.*]] {{.*}} -> i9 68 // 69 // BWD: matched: %[[v3:.*]] {{.*}} backward static slice: 70 // 71 // FWDBWD-NEXT: matched: %[[v3:.*]] {{.*}} static slice: 72 // FWDBWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 73 // FWDBWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 74 // FWDBWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 75 // FWDBWD-NEXT: %[[v7:.*]] = "slicing-test-op"(%[[v1]], %[[v5]]) : (i1, i5) -> i7 76 // FWDBWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 77 // FWDBWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 78 // FWDBWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 79 // FWDBWD-NEXT: %[[v8:.*]] = "slicing-test-op"(%[[v5]], %[[v6]]) : (i5, i6) -> i8 80 // FWDBWD-NEXT: %[[v9:.*]] = "slicing-test-op"(%[[v7]], %[[v8]]) : (i7, i8) -> i9 81 82 %3 = "slicing-test-op" () : () -> i3 83 84 // FWD-NEXT: matched: %[[v4:.*]] {{.*}} forward static slice: 85 // FWD-NEXT: %[[v6:.*]] {{.*}} -> i6 86 // FWD-NEXT: %[[v8:.*]] {{.*}} -> i8 87 // FWD-NEXT: %[[v9:.*]] {{.*}} -> i9 88 // 89 // BWD: matched: %[[v4:.*]] {{.*}} backward static slice: 90 // 91 // FWDBWD-NEXT: matched: %[[v4:.*]] {{.*}} static slice: 92 // FWDBWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 93 // FWDBWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 94 // FWDBWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 95 // FWDBWD-NEXT: %[[v7:.*]] = "slicing-test-op"(%[[v1]], %[[v5]]) : (i1, i5) -> i7 96 // FWDBWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 97 // FWDBWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 98 // FWDBWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 99 // FWDBWD-NEXT: %[[v8:.*]] = "slicing-test-op"(%[[v5]], %[[v6]]) : (i5, i6) -> i8 100 // FWDBWD-NEXT: %[[v9:.*]] = "slicing-test-op"(%[[v7]], %[[v8]]) : (i7, i8) -> i9 101 102 %4 = "slicing-test-op" () : () -> i4 103 104 // FWD-NEXT: matched: %[[v5:.*]] {{.*}} forward static slice: 105 // FWD-DAG: %[[v7:.*]] {{.*}} -> i7 106 // FWD-DAG: %[[v8:.*]] {{.*}} -> i8 107 // FWD-NEXT: %[[v9:.*]] {{.*}} -> i9 108 // 109 // BWD: matched: %[[v5:.*]] {{.*}} backward static slice: 110 // BWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 111 // BWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 112 // 113 // FWDBWD-NEXT: matched: %[[v5:.*]] {{.*}} static slice: 114 // FWDBWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 115 // FWDBWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 116 // FWDBWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 117 // FWDBWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 118 // FWDBWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 119 // FWDBWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 120 // FWDBWD-DAG: %[[v8:.*]] = "slicing-test-op"(%[[v5]], %[[v6]]) : (i5, i6) -> i8 121 // FWDBWD-DAG: %[[v7:.*]] = "slicing-test-op"(%[[v1]], %[[v5]]) : (i1, i5) -> i7 122 // FWDBWD-NEXT: %[[v9:.*]] = "slicing-test-op"(%[[v7]], %[[v8]]) : (i7, i8) -> i9 123 124 %5 = "slicing-test-op" (%1, %2) : (i1, i2) -> i5 125 126 // FWD-NEXT: matched: %[[v6:.*]] {{.*}} forward static slice: 127 // FWD-NEXT: %[[v8:.*]] {{.*}} -> i8 128 // FWD-NEXT: %[[v9:.*]] {{.*}} -> i9 129 // 130 // BWD: matched: %[[v6:.*]] {{.*}} backward static slice: 131 // BWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 132 // BWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 133 // 134 // FWDBWD-NEXT: matched: %[[v6:.*]] {{.*}} static slice: 135 // FWDBWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 136 // FWDBWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 137 // FWDBWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 138 // FWDBWD-NEXT: %[[v7:.*]] = "slicing-test-op"(%[[v1]], %[[v5]]) : (i1, i5) -> i7 139 // FWDBWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 140 // FWDBWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 141 // FWDBWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 142 // FWDBWD-NEXT: %[[v8:.*]] = "slicing-test-op"(%[[v5]], %[[v6]]) : (i5, i6) -> i8 143 // FWDBWD-NEXT: %[[v9:.*]] = "slicing-test-op"(%[[v7]], %[[v8]]) : (i7, i8) -> i9 144 145 %6 = "slicing-test-op" (%3, %4) : (i3, i4) -> i6 146 147 // FWD-NEXT: matched: %[[v7:.*]] {{.*}} forward static slice: 148 // FWD-NEXT: %[[v9:.*]] {{.*}} -> i9 149 // 150 // BWD: matched: %[[v7:.*]] {{.*}} backward static slice: 151 // BWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 152 // BWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 153 // BWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 154 // 155 // FWDBWD-NEXT: matched: %[[v7:.*]] {{.*}} static slice: 156 // FWDBWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 157 // FWDBWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 158 // FWDBWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 159 // FWDBWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 160 // FWDBWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 161 // FWDBWD: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 162 // FWDBWD-DAG: %[[v8:.*]] = "slicing-test-op"(%[[v5]], %[[v6]]) : (i5, i6) -> i8 163 // FWDBWD-DAG: %[[v7:.*]] = "slicing-test-op"(%[[v1]], %[[v5]]) : (i1, i5) -> i7 164 // FWDBWD-NEXT: %[[v9:.*]] = "slicing-test-op"(%[[v7]], %[[v8]]) : (i7, i8) -> i9 165 166 %7 = "slicing-test-op" (%1, %5) : (i1, i5) -> i7 167 168 // FWD-NEXT: matched: %[[v8:.*]] {{.*}} forward static slice: 169 // FWD-NEXT: %[[v9:.*]] {{.*}} -> i9 170 // 171 // BWD: matched: %[[v8:.*]] {{.*}} backward static slice: 172 // BWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 173 // BWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 174 // BWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 175 // BWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 176 // BWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 177 // BWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 178 // 179 // FWDBWD-NEXT: matched: %[[v8:.*]] {{.*}} static slice: 180 // FWDBWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 181 // FWDBWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 182 // FWDBWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 183 // FWDBWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 184 // FWDBWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 185 // FWDBWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 186 // FWDBWD-DAG: %[[v8:.*]] = "slicing-test-op"(%[[v5]], %[[v6]]) : (i5, i6) -> i8 187 // FWDBWD-DAG: %[[v7:.*]] = "slicing-test-op"(%[[v1]], %[[v5]]) : (i1, i5) -> i7 188 // FWDBWD-NEXT: %[[v9:.*]] = "slicing-test-op"(%[[v7]], %[[v8]]) : (i7, i8) -> i9 189 190 %8 = "slicing-test-op" (%5, %6) : (i5, i6) -> i8 191 192 // FWD-NEXT: matched: %[[v9:.*]] {{.*}} forward static slice: 193 // 194 // BWD: matched: %[[v9:.*]] {{.*}} backward static slice: 195 // BWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 196 // BWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 197 // BWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 198 // BWD-NEXT: %[[v7:.*]] = "slicing-test-op"(%[[v1]], %[[v5]]) : (i1, i5) -> i7 199 // BWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 200 // BWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 201 // BWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 202 // BWD-NEXT: %[[v8:.*]] = "slicing-test-op"(%[[v5]], %[[v6]]) : (i5, i6) -> i8 203 // 204 // FWDBWD-NEXT: matched: %[[v9:.*]] {{.*}} static slice: 205 // FWDBWD-DAG: %[[v4:.*]] = "slicing-test-op"() : () -> i4 206 // FWDBWD-DAG: %[[v3:.*]] = "slicing-test-op"() : () -> i3 207 // FWDBWD-NEXT: %[[v6:.*]] = "slicing-test-op"(%[[v3]], %[[v4]]) : (i3, i4) -> i6 208 // FWDBWD-DAG: %[[v2:.*]] = "slicing-test-op"() : () -> i2 209 // FWDBWD-DAG: %[[v1:.*]] = "slicing-test-op"() : () -> i1 210 // FWDBWD-NEXT: %[[v5:.*]] = "slicing-test-op"(%[[v1]], %[[v2]]) : (i1, i2) -> i5 211 // FWDBWD-DAG: %[[v8:.*]] = "slicing-test-op"(%[[v5]], %[[v6]]) : (i5, i6) -> i8 212 // FWDBWD-DAG: %[[v7:.*]] = "slicing-test-op"(%[[v1]], %[[v5]]) : (i1, i5) -> i7 213 // FWDBWD-NEXT: %[[v9:.*]] = "slicing-test-op"(%[[v7]], %[[v8]]) : (i7, i8) -> i9 214 215 %9 = "slicing-test-op" (%7, %8) : (i7, i8) -> i9 216 217 return 218} 219 220// FWD-LABEL: slicing_test_2 221// BWD-LABEL: slicing_test_2 222// FWDBWD-LABEL: slicing_test_2 223func @slicing_test_2() { 224 %c0 = constant 0 : index 225 %c2 = constant 2 : index 226 %c16 = constant 16 : index 227 affine.for %i0 = %c0 to %c16 { 228 affine.for %i1 = affine_map<(i)[] -> (i)>(%i0) to 10 { 229 // BWD: matched: %[[b:.*]] {{.*}} backward static slice: 230 // BWD: affine.for {{.*}} 231 232 // affine.for appears in the body of scf.for 233 // BWD: affine.for {{.*}} 234 235 // affine.for appears as a proper op in the backward slice 236 // BWD: affine.for {{.*}} 237 %b = "slicing-test-op"(%i1): (index) -> index 238 239 // BWD: matched: %[[c:.*]] {{.*}} backward static slice: 240 // BWD: affine.for {{.*}} 241 242 // affine.for appears in the body of scf.for 243 // BWD-NEXT: affine.for {{.*}} 244 245 // affine.for only appears in the body of scf.for 246 // BWD-NOT: affine.for {{.*}} 247 %c = "slicing-test-op"(%i0): (index) -> index 248 } 249 } 250 return 251} 252 253// FWD-LABEL: slicing_test_3 254// BWD-LABEL: slicing_test_3 255// FWDBWD-LABEL: slicing_test_3 256func @slicing_test_3() { 257 %f = constant 1.0 : f32 258 %c = "slicing-test-op"(%f): (f32) -> index 259 // FWD: matched: {{.*}} (f32) -> index forward static slice: 260 // FWD: scf.for {{.*}} 261 // FWD: matched: {{.*}} (index, index) -> index forward static slice: 262 scf.for %i2 = %c to %c step %c { 263 %d = "slicing-test-op"(%c, %i2): (index, index) -> index 264 } 265 return 266} 267 268// FWD-LABEL: slicing_test_function_argument 269// BWD-LABEL: slicing_test_function_argument 270// FWDBWD-LABEL: slicing_test_function_argument 271func @slicing_test_function_argument(%arg0: index) -> index { 272 // BWD: matched: {{.*}} (index, index) -> index backward static slice: 273 %0 = "slicing-test-op"(%arg0, %arg0): (index, index) -> index 274 return %0 : index 275} 276 277// FWD-LABEL: slicing_test_multiple_return 278// BWD-LABEL: slicing_test_multiple_return 279// FWDBWD-LABEL: slicing_test_multiple_return 280func @slicing_test_multiple_return(%arg0: index) -> (index, index) { 281 // BWD: matched: {{.*}} (index, index) -> (index, index) backward static slice: 282 // FWD: matched: %{{.*}}:2 = "slicing-test-op"(%arg0, %arg0) : (index, index) -> (index, index) forward static slice: 283 // FWD: return %{{.*}}#0, %{{.*}}#1 : index, index 284 %0:2 = "slicing-test-op"(%arg0, %arg0): (index, index) -> (index, index) 285 return %0#0, %0#1 : index, index 286} 287 288// This test dumps 2 sets of outputs: first the test outputs themselves followed 289// by the module. These labels isolate the test outputs from the module dump. 290// FWD-LABEL: slicing_test 291// BWD-LABEL: slicing_test 292// FWDBWD-LABEL: slicing_test 293// FWD-LABEL: slicing_test_2 294// BWD-LABEL: slicing_test_2 295// FWDBWD-LABEL: slicing_test_2 296// FWD-LABEL: slicing_test_3 297// BWD-LABEL: slicing_test_3 298// FWDBWD-LABEL: slicing_test_3 299// FWD-LABEL: slicing_test_function_argument 300// BWD-LABEL: slicing_test_function_argument 301// FWDBWD-LABEL: slicing_test_function_argument 302