brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.2 KiB · e5db5cd Raw
151 lines · plain
1// RUN: mlir-opt %s -allow-unregistered-dialect -test-decompose-affine-ops -split-input-file -loop-invariant-code-motion -cse | FileCheck %s2 3// CHECK-DAG: #[[$c42:.*]] = affine_map<() -> (42)>4// CHECK-DAG: #[[$div32mod4:.*]] = affine_map<()[s0] -> ((s0 floordiv 32) mod 4)>5// CHECK-DAG: #[[$add:.*]] = affine_map<()[s0, s1] -> (s0 + s1)>6 7// CHECK-LABEL:  func.func @simple_test_18//  CHECK-SAME:  %[[I0:[0-9a-zA-Z]+]]: index,9//  CHECK-SAME:  %[[I1:[0-9a-zA-Z]+]]: index,10//  CHECK-SAME:  %[[I2:[0-9a-zA-Z]+]]: index,11//  CHECK-SAME:  %[[LB:[0-9a-zA-Z]+]]: index,12//  CHECK-SAME:  %[[UB:[0-9a-zA-Z]+]]: index,13//  CHECK-SAME:  %[[STEP:[0-9a-zA-Z]+]]: index14func.func @simple_test_1(%0: index, %1: index, %2: index, %lb: index, %ub: index, %step: index) {15  // CHECK: %[[c42:.*]] = affine.apply #[[$c42]]()16  // CHECK: %[[R1:.*]] = affine.apply #[[$div32mod4]]()[%[[I1]]]17  // CHECK: %[[a:.*]] = affine.apply #[[$add]]()[%[[c42]], %[[R1]]]18  %a = affine.apply affine_map<(d0) -> ((d0 floordiv 32) mod 4 + 42)>(%1)19 20  // CHECK:     "some_side_effecting_consumer"(%[[a]]) : (index) -> ()21  "some_side_effecting_consumer"(%a) : (index) -> ()22  return23}24 25// -----26 27// CHECK-DAG: #[[$c42:.*]] = affine_map<() -> (42)>28// CHECK-DAG: #[[$id:.*]] = affine_map<()[s0] -> (s0)>29// CHECK-DAG: #[[$add:.*]] = affine_map<()[s0, s1] -> (s0 + s1)>30// CHECK-DAG: #[[$div32mod4:.*]] = affine_map<()[s0] -> ((s0 floordiv 32) mod 4)>31 32// CHECK-LABEL:  func.func @simple_test_233//  CHECK-SAME:  %[[I0:[0-9a-zA-Z]+]]: index,34//  CHECK-SAME:  %[[I1:[0-9a-zA-Z]+]]: index,35//  CHECK-SAME:  %[[I2:[0-9a-zA-Z]+]]: index,36//  CHECK-SAME:  %[[LB:[0-9a-zA-Z]+]]: index,37//  CHECK-SAME:  %[[UB:[0-9a-zA-Z]+]]: index,38//  CHECK-SAME:  %[[STEP:[0-9a-zA-Z]+]]: index39func.func @simple_test_2(%0: index, %1: index, %2: index, %lb: index, %ub: index, %step: index) {40  // CHECK: %[[c42:.*]] = affine.apply #[[$c42]]()41  // CHECK: scf.for %[[i:.*]] =42  scf.for %i = %lb to %ub step %step {43    // CHECK:   %[[R1:.*]] = affine.apply #[[$id]]()[%[[i]]]44    // CHECK:   %[[R2:.*]] = affine.apply #[[$add]]()[%[[c42]], %[[R1]]]45    // CHECK:   scf.for %[[j:.*]] =46    scf.for %j = %lb to %ub step %step {47      // CHECK:     %[[R3:.*]] = affine.apply #[[$div32mod4]]()[%[[j]]]48      // CHECK:     %[[a:.*]] = affine.apply #[[$add]]()[%[[R2]], %[[R3]]]49      %a = affine.apply affine_map<(d0)[s0] -> ((d0 floordiv 32) mod 4 + s0 + 42)>(%j)[%i]50 51      // CHECK:     "some_side_effecting_consumer"(%[[a]]) : (index) -> ()52      "some_side_effecting_consumer"(%a) : (index) -> ()53    }54  }55  return56}57 58// -----59 60// CHECK-DAG: #[[$div4:.*]] = affine_map<()[s0] -> (s0 floordiv 4)>61// CHECK-DAG: #[[$times32:.*]] = affine_map<()[s0] -> (s0 * 32)>62// CHECK-DAG: #[[$times16:.*]] = affine_map<()[s0] -> (s0 * 16)>63// CHECK-DAG: #[[$add:.*]] = affine_map<()[s0, s1] -> (s0 + s1)>64// CHECK-DAG: #[[$div4timesm32:.*]] = affine_map<()[s0] -> ((s0 floordiv 4) * -32)>65// CHECK-DAG: #[[$times8:.*]] = affine_map<()[s0] -> (s0 * 8)>66// CHECK-DAG: #[[$id:.*]] = affine_map<()[s0] -> (s0)>67// CHECK-DAG: #[[$div32mod4:.*]] = affine_map<()[s0] -> ((s0 floordiv 32) mod 4)>68 69// CHECK-LABEL:  func.func @larger_test70//  CHECK-SAME:  %[[I0:[0-9a-zA-Z]+]]: index,71//  CHECK-SAME:  %[[I1:[0-9a-zA-Z]+]]: index,72//  CHECK-SAME:  %[[I2:[0-9a-zA-Z]+]]: index,73//  CHECK-SAME:  %[[LB:[0-9a-zA-Z]+]]: index,74//  CHECK-SAME:  %[[UB:[0-9a-zA-Z]+]]: index,75//  CHECK-SAME:  %[[STEP:[0-9a-zA-Z]+]]: index76func.func @larger_test(%0: index, %1: index, %2: index, %lb: index, %ub: index, %step: index) {77    %c2 = arith.constant 2 : index78    %c6 = arith.constant 6 : index79 80    //      CHECK: %[[R0:.*]] = affine.apply #[[$div4]]()[%[[I0]]]81    // CHECK-NEXT: %[[R1:.*]] = affine.apply #[[$times16]]()[%[[I1]]]82    // CHECK-NEXT: %[[R2:.*]] = affine.apply #[[$add]]()[%[[R0]], %[[R1]]]83    // CHECK-NEXT: %[[R3:.*]] = affine.apply #[[$times32]]()[%[[I2]]]84 85    // I1 * 16 + I2 * 32 + I0 floordiv 486    // CHECK-NEXT: %[[b:.*]] = affine.apply #[[$add]]()[%[[R2]], %[[R3]]]87 88    // (I0 floordiv 4) * 3289    // CHECK-NEXT: %[[R5:.*]] = affine.apply #[[$div4timesm32]]()[%[[I0]]]90    // 8 * I091    // CHECK-NEXT: %[[R6:.*]] = affine.apply #[[$times8]]()[%[[I0]]]92    // 8 * I0 + (I0 floordiv 4) * 3293    // CHECK-NEXT: %[[c:.*]] = affine.apply #[[$add]]()[%[[R5]], %[[R6]]]94 95    // CHECK-NEXT: scf.for %[[i:.*]] =96    scf.for %i = %lb to %ub step %step {97      // remainder from %a not hoisted above %i.98      // CHECK-NEXT: %[[R8:.*]] = affine.apply #[[$times32]]()[%[[i]]]99      // CHECK-NEXT: %[[a:.*]] = affine.apply #[[$add]]()[%[[b]], %[[R8]]]100 101      // CHECK-NEXT: scf.for %[[j:.*]] =102      scf.for %j = %lb to %ub step %step {103        // Gets hoisted partially to i and rest outermost.104        // The hoisted part is %b.105        %a = affine.apply affine_map<()[s0, s1, s2, s3] -> (s1 * 16 + s2 * 32 + s3 * 32 + s0 floordiv 4)>()[%0, %1, %2, %i]106 107        // Gets completely hoisted 108        %b = affine.apply affine_map<()[s0, s1, s2] -> (s1 * 16 + s2 * 32 + s0 floordiv 4)>()[%0, %1, %2]109 110        // Gets completely hoisted 111        %c = affine.apply affine_map<()[s0] -> (s0 * 8 - (s0 floordiv 4) * 32)>()[%0]112 113        // 32 * %j + %c remains here, the rest is hoisted.114        // CHECK-DAG: %[[R10:.*]] = affine.apply #[[$times32]]()[%[[j]]]115        // CHECK-DAG: %[[d:.*]] = affine.apply #[[$add]]()[%[[c]], %[[R10]]]116        %d = affine.apply affine_map<()[s0, s1] -> (s0 * 8 + s1 * 32 - (s0 floordiv 4) * 32)>()[%0, %j]117 118        // CHECK-DAG: %[[idj:.*]] = affine.apply #[[$id]]()[%[[j]]]119        // CHECK-NEXT: scf.for %[[k:.*]] =120        scf.for %k = %lb to %ub step %step {121          // CHECK-NEXT: %[[idk:.*]] = affine.apply #[[$id]]()[%[[k]]]122          // CHECK-NEXT: %[[e:.*]] = affine.apply #[[$add]]()[%[[c]], %[[idk]]]123          %e = affine.apply affine_map<()[s0, s1] -> (s0 + s1 * 8 - (s1 floordiv 4) * 32)>()[%k, %0]124 125          // CHECK-NEXT: %[[R15:.*]] = affine.apply #[[$div32mod4]]()[%[[k]]]126          // CHECK-NEXT: %[[f:.*]] = affine.apply #[[$add]]()[%[[idj]], %[[R15]]]127          %f = affine.apply affine_map<(d0)[s0] -> ((d0 floordiv 32) mod 4 + s0)>(%k)[%j]128 129          // CHECK-NEXT: %[[g:.*]] = affine.apply #[[$add]]()[%[[b]], %[[idk]]]130          %g = affine.apply affine_map<()[s0, s1, s2, s3] -> (s0 + s2 * 16 + s3 * 32 + s1 floordiv 4)>()[%k, %0, %1, %2]131          132          // CHECK-NEXT: "some_side_effecting_consumer"(%[[a]]) : (index) -> ()133          "some_side_effecting_consumer"(%a) : (index) -> ()134          // CHECK-NEXT: "some_side_effecting_consumer"(%[[b]]) : (index) -> ()135          "some_side_effecting_consumer"(%b) : (index) -> ()136          // CHECK-NEXT: "some_side_effecting_consumer"(%[[c]]) : (index) -> ()137          "some_side_effecting_consumer"(%c) : (index) -> ()138          // CHECK-NEXT: "some_side_effecting_consumer"(%[[d]]) : (index) -> ()139          "some_side_effecting_consumer"(%d) : (index) -> ()140          // CHECK-NEXT: "some_side_effecting_consumer"(%[[e]]) : (index) -> ()141          "some_side_effecting_consumer"(%e) : (index) -> ()142          // CHECK-NEXT: "some_side_effecting_consumer"(%[[f]]) : (index) -> ()143          "some_side_effecting_consumer"(%f) : (index) -> ()144          // CHECK-NEXT: "some_side_effecting_consumer"(%[[g]]) : (index) -> ()145          "some_side_effecting_consumer"(%g) : (index) -> ()146        }147    }148  }   149  return150}151