diff --git a/mlir/lib/Dialect/SCF/SCF.cpp b/mlir/lib/Dialect/SCF/SCF.cpp --- a/mlir/lib/Dialect/SCF/SCF.cpp +++ b/mlir/lib/Dialect/SCF/SCF.cpp @@ -547,7 +547,7 @@ // If the loop is known to have 1 iteration, inline its body and remove the // loop. - llvm::APInt stepValue = lb.getValue().cast().getValue(); + llvm::APInt stepValue = step.getValue().cast().getValue(); if ((lbValue + stepValue).sge(ubValue)) { SmallVector blockArgs; blockArgs.reserve(op.getNumIterOperands() + 1); diff --git a/mlir/test/Dialect/Linalg/fusion.mlir b/mlir/test/Dialect/Linalg/fusion.mlir --- a/mlir/test/Dialect/Linalg/fusion.mlir +++ b/mlir/test/Dialect/Linalg/fusion.mlir @@ -665,9 +665,9 @@ #map1 = affine_map<(d0, d1, d2, d3)[s0, s1, s2, s3, s4] -> (d0 * s1 + s0 + d1 * s2 + d2 * s3 + d3 * s4)> #map2 = affine_map<()[s0] -> (s0 + 3)> -func @fill_and_conv(%arg0: memref<1x4x5x1xf32>, %arg1: memref<2x3x1x1xf32>, %arg2: memref<1x4x5x1xf32>) { +func @fill_and_conv(%arg0: memref, %arg1: memref<2x3x1x1xf32>, %arg2: memref) { %cst = constant 0.000000e+00 : f32 - linalg.fill(%arg2, %cst) : memref<1x4x5x1xf32>, f32 + linalg.fill(%arg2, %cst) : memref, f32 %c4 = constant 4 : index %c1 = constant 1 : index @@ -676,13 +676,13 @@ %c3 = constant 3 : index %4 = dim %arg1, %c0 : memref<2x3x1x1xf32> %5 = dim %arg1, %c1 : memref<2x3x1x1xf32> - %6 = dim %arg0, %c0 : memref<1x4x5x1xf32> - %7 = dim %arg0, %c1 : memref<1x4x5x1xf32> - %8 = dim %arg0, %c3 : memref<1x4x5x1xf32> - %9 = dim %arg2, %c0 : memref<1x4x5x1xf32> - %10 = dim %arg2, %c1 : memref<1x4x5x1xf32> - %11 = dim %arg2, %c2 : memref<1x4x5x1xf32> - %12 = dim %arg2, %c3 : memref<1x4x5x1xf32> + %6 = dim %arg0, %c0 : memref + %7 = dim %arg0, %c1 : memref + %8 = dim %arg0, %c3 : memref + %9 = dim %arg2, %c0 : memref + %10 = dim %arg2, %c1 : memref + %11 = dim %arg2, %c2 : memref + %12 = dim %arg2, %c3 : memref %13 = linalg.range %c0 : %6 : %c2 : !linalg.range %14 = linalg.range %c0 : %10 : %c3 : !linalg.range scf.for %arg3 = %c0 to %6 step %c2 { @@ -690,14 +690,14 @@ %15 = affine.min #map0(%c2, %c1, %arg3) %16 = affine.apply #map2()[%7] %17 = affine.min #map0(%16, %c4, %arg4) - %18 = dim %arg0, %c2 : memref<1x4x5x1xf32> - %19 = dim %arg0, %c3 : memref<1x4x5x1xf32> - %20 = subview %arg0[%arg3, %arg4, %c0, %c0] [%15, %17, %18, %19] [%c1, %c1, %c1, %c1] : memref<1x4x5x1xf32> to memref + %18 = dim %arg0, %c2 : memref + %19 = dim %arg0, %c3 : memref + %20 = subview %arg0[%arg3, %arg4, %c0, %c0] [%15, %17, %18, %19] [%c1, %c1, %c1, %c1] : memref to memref %21 = affine.min #map0(%c2, %c1, %arg3) %22 = affine.min #map0(%c3, %c4, %arg4) - %23 = dim %arg2, %c2 : memref<1x4x5x1xf32> - %24 = dim %arg2, %c3 : memref<1x4x5x1xf32> - %25 = subview %arg2[%arg3, %arg4, %c0, %c0] [%21, %22, %23, %24] [%c1, %c1, %c1, %c1] : memref<1x4x5x1xf32> to memref + %23 = dim %arg2, %c2 : memref + %24 = dim %arg2, %c3 : memref + %25 = subview %arg2[%arg3, %arg4, %c0, %c0] [%21, %22, %23, %24] [%c1, %c1, %c1, %c1] : memref to memref linalg.conv(%arg1, %20, %25) {dilations = [1, 1], strides = [1, 1]} : memref<2x3x1x1xf32>, memref, memref } } diff --git a/mlir/test/Dialect/SCF/canonicalize.mlir b/mlir/test/Dialect/SCF/canonicalize.mlir --- a/mlir/test/Dialect/SCF/canonicalize.mlir +++ b/mlir/test/Dialect/SCF/canonicalize.mlir @@ -233,8 +233,8 @@ return } -// CHECK-LABEL: @replace_single_iteration_loop -func @replace_single_iteration_loop() { +// CHECK-LABEL: @replace_single_iteration_loop_1 +func @replace_single_iteration_loop_1() { // CHECK: %[[LB:.*]] = constant 42 %c42 = constant 42 : index %c43 = constant 43 : index @@ -252,6 +252,26 @@ return } +// CHECK-LABEL: @replace_single_iteration_loop_2 +func @replace_single_iteration_loop_2() { + // CHECK: %[[LB:.*]] = constant 5 + %c5 = constant 5 : index + %c6 = constant 6 : index + %c11 = constant 11 : index + // CHECK: %[[INIT:.*]] = "test.init" + %init = "test.init"() : () -> i32 + // CHECK-NOT: scf.for + // CHECK: %[[VAL:.*]] = "test.op"(%[[LB]], %[[INIT]]) + %0 = scf.for %i = %c5 to %c11 step %c6 iter_args(%arg = %init) -> (i32) { + %1 = "test.op"(%i, %arg) : (index, i32) -> i32 + scf.yield %1 : i32 + } + // CHECK: "test.consume"(%[[VAL]]) + "test.consume"(%0) : (i32) -> () + return +} + + // CHECK-LABEL: @replace_single_iteration_loop_non_unit_step func @replace_single_iteration_loop_non_unit_step() { // CHECK: %[[LB:.*]] = constant 42