[Mlir-commits] [mlir] [mlir][scf] add unroll-full option to test-loop-unrolling pass. (PR #127158)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Mon Feb 17 00:41:52 PST 2025


================
@@ -56,3 +57,59 @@ func.func @scf_loop_unroll_factor_1_promote() -> () {
   // UNROLL-BY-1-NEXT: %[[C0:.*]] = arith.constant 0 : index
   // UNROLL-BY-1-NEXT: %{{.*}} = "test.foo"(%[[C0]]) : (index) -> i32
 }
+
+// UNROLL-FULL-LABEL: func @scf_loop_unroll_full_single(
+// UNROLL-FULL-SAME:    %[[VAL_0:.*]]: index) -> index {
+func.func @scf_loop_unroll_full_single(%arg : index) -> index {
+  %0 = arith.constant 0 : index
+  %1 = arith.constant 1 : index
+  %2 = arith.constant 4 : index
+  %4 = scf.for %iv = %0 to %2 step %1 iter_args(%arg1 = %1) -> index {
+    %3 = arith.addi %arg1, %arg : index
+    scf.yield %3 : index
+  }
+  return %4 : index
+  // UNROLL-FULL: %[[VAL_1:.*]] = arith.constant 1 : index
+  // UNROLL-FULL: %[[VAL_2:.*]] = arith.addi %[[VAL_0]], %[[VAL_1]] : index
+  // UNROLL-FULL: %[[VAL_3:.*]] = arith.addi %[[VAL_2]], %[[VAL_0]] : index
+  // UNROLL-FULL: %[[VAL_4:.*]] = arith.addi %[[VAL_3]], %[[VAL_0]] : index
+  // UNROLL-FULL: %[[VAL_5:.*]] = arith.addi %[[VAL_4]], %[[VAL_0]] : index
+  // UNROLL-FULL: return %[[VAL_5]] : index
+}
+
+// UNROLL-FULL-LABEL: func @scf_loop_unroll_full_outter_loops(
+// UNROLL-FULL-SAME:    %[[VAL_0:.*]]: vector<4x4xindex>) -> index {
+func.func @scf_loop_unroll_full_outter_loops(%arg0: vector<4x4xindex>) -> index {
+  %0 = arith.constant 0 : index
+  %1 = arith.constant 1 : index
+  %2 = arith.constant 4 : index
+  %6 = scf.for %arg1 = %0 to %2 step %1 iter_args(%it0 = %0) -> index {
+    %5 = scf.for %arg2 = %0 to %2 step %1 iter_args(%it1 = %it0) -> index {
+      %3 = vector.extract %arg0[%arg1, %arg2] : index from vector<4x4xindex>
+      %4 = arith.addi %3, %it1 : index
+      scf.yield %3 : index
+    }
+    scf.yield %5 : index
+  }
+  return %6 : index
+  // UNROLL-FULL:   %[[VAL_1:.*]] = arith.constant 0 : index
----------------
ftynse wrote:

https://mlir.llvm.org/getting_started/TestingGuide/#filecheck-best-practices

Please minimize the test to only check for the unrolling functionality. For example, drop the irrelevant syntactic fluff of trailing types, closing braces, etc. We are not testing the IR printer here. Also use more descriptive names for values, this helps people to read this and understand what is going on.

https://github.com/llvm/llvm-project/pull/127158


More information about the Mlir-commits mailing list