78 lines · plain
1// RUN: mlir-opt --transform-interpreter %s | FileCheck %s2 3#map = affine_map<()[s0, s1] -> (s0, s1, 128)>4#map1 = affine_map<()[s0, s1] -> (s0 ceildiv 128 + s0 ceildiv s1)>5#map2 = affine_map<()[s0, s1, s2] -> (s0, s1 + s2)>6#map3 = affine_map<()[s0, s1, s2, s3] -> (3 * (s0 ceildiv s3) + s0 ceildiv (s1 + s2))>7#map4 = affine_map<()[s0, s1] -> (s1)>8#map5 = affine_map<()[s0, s1] -> (s0 ceildiv s1)>9#map6 = affine_map<()[s0, s1] -> (s0, s1, -128)>10// CHECK-DAG: #[[MAP1:.*]] = affine_map<()[s0, s1] -> (s0 ceildiv 128 + s0 ceildiv s1)>11// CHECK-DAG: #[[MAP5:.*]] = affine_map<()[s0, s1] -> (s0 ceildiv s1)>12 13// These test checks the `affine::makeComposedFoldedAffineApply` function when14// `composeAffineMin == true`.15 16// Check the apply gets simplified.17// CHECK: @apply_simplification18func.func @apply_simplification_1() -> index {19 %0 = test.value_with_bounds {max = 64 : index, min = 32 : index}20 %1 = test.value_with_bounds {max = 64 : index, min = 32 : index}21 %2 = affine.min #map()[%0, %1]22 // CHECK-NOT: affine.apply23 // CHECK: arith.constant 2 : index24 %3 = affine.apply #map1()[%2, %1]25 return %3 : index26}27 28// Check the simplification can match non-trivial affine expressions like s1 + s2.29func.func @apply_simplification_2() -> index {30 %0 = test.value_with_bounds {max = 64 : index, min = 32 : index}31 %1 = test.value_with_bounds {max = 64 : index, min = 32 : index}32 %2 = test.value_with_bounds {max = 64 : index, min = 32 : index}33 %3 = affine.min #map2()[%0, %1, %2]34 // CHECK-NOT: affine.apply35 // CHECK: arith.constant 4 : index36 %4 = affine.apply #map3()[%3, %1, %2, %0]37 return %4 : index38}39 40// Check there's no simplification.41// The apply cannot be simplified because `s1 = %0` doesn't appear in the input min.42// CHECK: @no_simplification_043func.func @no_simplification_0() -> index {44 // CHECK: %[[V0:.*]] = test.value_with_bounds {max = 64 : index, min = 32 : index}45 // CHECK: %[[V1:.*]] = test.value_with_bounds {max = 64 : index, min = 16 : index}46 // CHECK: %[[V2:.*]] = affine.min #{{.*}}()[%[[V0]], %[[V1]]]47 // CHECK: %[[V3:.*]] = affine.apply #[[MAP5]]()[%[[V2]], %[[V0]]]48 // CHECK: return %[[V3]] : index49 %0 = test.value_with_bounds {max = 64 : index, min = 32 : index}50 %1 = test.value_with_bounds {max = 64 : index, min = 16 : index}51 %2 = affine.min #map4()[%0, %1]52 %3 = affine.apply #map5()[%2, %0]53 return %3 : index54}55 56// The apply cannot be simplified because the min cannot be proven to be greater than 0.57// CHECK: @no_simplification_158func.func @no_simplification_1() -> index {59 // CHECK: %[[V0:.*]] = test.value_with_bounds {max = 64 : index, min = 32 : index}60 // CHECK: %[[V1:.*]] = test.value_with_bounds {max = 64 : index, min = 16 : index}61 // CHECK: %[[V2:.*]] = affine.min #{{.*}}()[%[[V0]], %[[V1]]]62 // CHECK: %[[V3:.*]] = affine.apply #[[MAP1]]()[%[[V2]], %[[V1]]]63 // CHECK: return %[[V3]] : index64 %0 = test.value_with_bounds {max = 64 : index, min = 32 : index}65 %1 = test.value_with_bounds {max = 64 : index, min = 16 : index}66 %2 = affine.min #map6()[%0, %1]67 %3 = affine.apply #map1()[%2, %1]68 return %3 : index69}70 71module attributes {transform.with_named_sequence} {72 transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {73 %0 = transform.structured.match ops{["affine.apply"]} in %arg0 : (!transform.any_op) -> !transform.any_op74 %1 = transform.test.make_composed_folded_affine_apply %0 : (!transform.any_op) -> !transform.any_op75 transform.yield 76 }77}78