|
1 | 1 | // RUN: mlir-opt %s --test-loop-unrolling="unroll-factor=3" -split-input-file -canonicalize | FileCheck %s
|
2 | 2 | // RUN: mlir-opt %s --test-loop-unrolling="unroll-factor=1" -split-input-file -canonicalize | FileCheck %s --check-prefix UNROLL-BY-1
|
| 3 | +// RUN: mlir-opt %s --test-loop-unrolling="unroll-full=true" -split-input-file -canonicalize | FileCheck %s --check-prefix UNROLL-FULL |
3 | 4 |
|
4 | 5 | // CHECK-LABEL: scf_loop_unroll_single
|
5 | 6 | func.func @scf_loop_unroll_single(%arg0 : f32, %arg1 : f32) -> f32 {
|
@@ -56,3 +57,59 @@ func.func @scf_loop_unroll_factor_1_promote() -> () {
|
56 | 57 | // UNROLL-BY-1-NEXT: %[[C0:.*]] = arith.constant 0 : index
|
57 | 58 | // UNROLL-BY-1-NEXT: %{{.*}} = "test.foo"(%[[C0]]) : (index) -> i32
|
58 | 59 | }
|
| 60 | + |
| 61 | +// UNROLL-FULL-LABEL: func @scf_loop_unroll_full_single |
| 62 | +// UNROLL-FULL-SAME: %[[ARG:.*]]: index) |
| 63 | +func.func @scf_loop_unroll_full_single(%arg : index) -> index { |
| 64 | + %0 = arith.constant 0 : index |
| 65 | + %1 = arith.constant 1 : index |
| 66 | + %2 = arith.constant 4 : index |
| 67 | + %4 = scf.for %iv = %0 to %2 step %1 iter_args(%arg1 = %1) -> index { |
| 68 | + %3 = arith.addi %arg1, %arg : index |
| 69 | + scf.yield %3 : index |
| 70 | + } |
| 71 | + return %4 : index |
| 72 | + // UNROLL-FULL: %[[C1:.*]] = arith.constant 1 : index |
| 73 | + // UNROLL-FULL: %[[V0:.*]] = arith.addi %[[ARG]], %[[C1]] : index |
| 74 | + // UNROLL-FULL: %[[V1:.*]] = arith.addi %[[V0]], %[[ARG]] : index |
| 75 | + // UNROLL-FULL: %[[V2:.*]] = arith.addi %[[V1]], %[[ARG]] : index |
| 76 | + // UNROLL-FULL: %[[V3:.*]] = arith.addi %[[V2]], %[[ARG]] : index |
| 77 | + // UNROLL-FULL: return %[[V3]] : index |
| 78 | +} |
| 79 | + |
| 80 | +// UNROLL-FULL-LABEL: func @scf_loop_unroll_full_outter_loops |
| 81 | +// UNROLL-FULL-SAME: %[[ARG:.*]]: vector<4x4xindex>) |
| 82 | +func.func @scf_loop_unroll_full_outter_loops(%arg0: vector<4x4xindex>) -> index { |
| 83 | + %0 = arith.constant 0 : index |
| 84 | + %1 = arith.constant 1 : index |
| 85 | + %2 = arith.constant 4 : index |
| 86 | + %6 = scf.for %arg1 = %0 to %2 step %1 iter_args(%it0 = %0) -> index { |
| 87 | + %5 = scf.for %arg2 = %0 to %2 step %1 iter_args(%it1 = %it0) -> index { |
| 88 | + %3 = vector.extract %arg0[%arg1, %arg2] : index from vector<4x4xindex> |
| 89 | + %4 = arith.addi %3, %it1 : index |
| 90 | + scf.yield %3 : index |
| 91 | + } |
| 92 | + scf.yield %5 : index |
| 93 | + } |
| 94 | + return %6 : index |
| 95 | + // UNROLL-FULL: %[[C0:.*]] = arith.constant 0 : index |
| 96 | + // UNROLL-FULL: %[[C1:.*]] = arith.constant 1 : index |
| 97 | + // UNROLL-FULL: %[[C4:.*]] = arith.constant 4 : index |
| 98 | + // UNROLL-FULL: %[[SUM0:.*]] = scf.for %[[IV:.*]] = %[[C0]] to %[[C4]] step %[[C1]] iter_args(%{{.*}} = %[[C0]]) |
| 99 | + // UNROLL-FULL: %[[VAL:.*]] = vector.extract %[[ARG]][0, %[[IV]]] : index from vector<4x4xindex> |
| 100 | + // UNROLL-FULL: scf.yield %[[VAL]] : index |
| 101 | + // UNROLL-FULL: } |
| 102 | + // UNROLL-FULL: %[[SUM1:.*]] = scf.for %[[IV:.*]] = %[[C0]] to %[[C4]] step %[[C1]] iter_args(%{{.*}} = %[[SUM0]]) |
| 103 | + // UNROLL-FULL: %[[VAL:.*]] = vector.extract %[[ARG]][1, %[[IV]]] : index from vector<4x4xindex> |
| 104 | + // UNROLL-FULL: scf.yield %[[VAL]] : index |
| 105 | + // UNROLL-FULL: } |
| 106 | + // UNROLL-FULL: %[[SUM2:.*]] = scf.for %[[IV:.*]] = %[[C0]] to %[[C4]] step %[[C1]] iter_args(%{{.*}} = %[[SUM1]]) |
| 107 | + // UNROLL-FULL: %[[VAL:.*]] = vector.extract %[[ARG]][2, %[[IV]]] : index from vector<4x4xindex> |
| 108 | + // UNROLL-FULL: scf.yield %[[VAL]] : index |
| 109 | + // UNROLL-FULL: } |
| 110 | + // UNROLL-FULL: %[[SUM3:.*]] = scf.for %[[IV:.*]] = %[[C0]] to %[[C4]] step %[[C1]] iter_args(%{{.*}} = %[[SUM2]]) |
| 111 | + // UNROLL-FULL: %[[VAL:.*]] = vector.extract %[[ARG]][3, %[[IV]]] : index from vector<4x4xindex> |
| 112 | + // UNROLL-FULL: scf.yield %[[VAL]] : index |
| 113 | + // UNROLL-FULL: } |
| 114 | + // UNROLL-FULL: return %[[SUM3]] : index |
| 115 | +} |
0 commit comments