[PATCH] D127553: [mlir] Replace iterOperand with a neutral element

Amy Zhuang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 17 13:17:43 PDT 2023


ayzhuang added a comment.

@bondhugula @dcaballe Please review, thanks. Please read my last comment for an example. We don't need this for unroll because unroll does not widen the loop. This is the test I copied from unroll.mlir:

  // UNROLL-BY-4-LABEL: unroll_with_iter_args_and_promotion
  func.func @unroll_with_iter_args_and_promotion(%arg0 : f32, %arg1 : f32) -> f32 {
    %from = arith.constant 0 : index
    %to = arith.constant 10 : index
    %step = arith.constant 1 : index
    %sum = affine.for %iv = 0 to 9 iter_args(%sum_iter = %arg0) -> (f32) {
      %next = arith.addf %sum_iter, %arg1 : f32
      affine.yield %next : f32
    }
    // UNROLL-BY-4:      %[[SUM:.*]] = affine.for %{{.*}} = 0 to 8 step 4 iter_args(%[[V0:.*]] =
    // UNROLL-BY-4-NEXT:   %[[V1:.*]] = arith.addf %[[V0]]
    // UNROLL-BY-4-NEXT:   %[[V2:.*]] = arith.addf %[[V1]]
    // UNROLL-BY-4-NEXT:   %[[V3:.*]] = arith.addf %[[V2]]
    // UNROLL-BY-4-NEXT:   %[[V4:.*]] = arith.addf %[[V3]]
    // UNROLL-BY-4-NEXT:   affine.yield %[[V4]]
    // UNROLL-BY-4-NEXT: }
    // UNROLL-BY-4-NEXT: %[[RES:.*]] = arith.addf %[[SUM]],
    // UNROLL-BY-4-NEXT: return %[[RES]]
    return %sum : f32
  }

There is only one iterArg which is only used once in the unrolled loop.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127553/new/

https://reviews.llvm.org/D127553



More information about the llvm-commits mailing list