From 6fe99662aa6c0d7dae467d91af4510b0d796d11f Mon Sep 17 00:00:00 2001 From: Alex Zinenko Date: Fri, 19 Jul 2019 08:13:27 -0700 Subject: [PATCH] Move loop dialect tests into separate files - NFC This was overlooked when moving out loop operations from Standard to a separate dialect. PiperOrigin-RevId: 258970115 --- mlir/test/Dialect/Loops/invalid.mlir | 115 +++++++++++++++++++++++++++++++++++ mlir/test/Dialect/Loops/ops.mlir | 51 ++++++++++++++++ mlir/test/IR/core-ops.mlir | 45 -------------- mlir/test/IR/invalid-ops.mlir | 115 ----------------------------------- 4 files changed, 166 insertions(+), 160 deletions(-) create mode 100644 mlir/test/Dialect/Loops/invalid.mlir create mode 100644 mlir/test/Dialect/Loops/ops.mlir diff --git a/mlir/test/Dialect/Loops/invalid.mlir b/mlir/test/Dialect/Loops/invalid.mlir new file mode 100644 index 0000000..02252b4 --- /dev/null +++ b/mlir/test/Dialect/Loops/invalid.mlir @@ -0,0 +1,115 @@ +// RUN: mlir-opt %s -split-input-file -verify-diagnostics + +func @loop_for_lb(%arg0: f32, %arg1: index) { + // expected-error@+1 {{operand #0 must be index}} + "loop.for"(%arg0, %arg1, %arg1) : (f32, index, index) -> () + return +} + +// ----- + +func @loop_for_ub(%arg0: f32, %arg1: index) { + // expected-error@+1 {{operand #1 must be index}} + "loop.for"(%arg1, %arg0, %arg1) : (index, f32, index) -> () + return +} + +// ----- + +func @loop_for_step(%arg0: f32, %arg1: index) { + // expected-error@+1 {{operand #2 must be index}} + "loop.for"(%arg1, %arg1, %arg0) : (index, index, f32) -> () + return +} + +// ----- + +func @loop_for_step_nonnegative(%arg0: index) { + // expected-error@+2 {{constant step operand must be nonnegative}} + %c0 = constant 0 : index + "loop.for"(%arg0, %arg0, %c0) ({ + ^bb0(%arg1: index): + "loop.terminator"() : () -> () + }) : (index, index, index) -> () + return +} + +// ----- + +func @loop_for_one_region(%arg0: index) { + // expected-error@+1 {{incorrect number of regions: expected 1 but found 2}} + "loop.for"(%arg0, %arg0, %arg0) ( + {"loop.terminator"() : () -> ()}, + {"loop.terminator"() : () -> ()} + ) : (index, index, index) -> () + return +} + +// ----- + +func @loop_for_single_block(%arg0: index) { + // expected-error@+1 {{expects region #0 to have 0 or 1 blocks}} + "loop.for"(%arg0, %arg0, %arg0) ( + { + ^bb1: + "loop.terminator"() : () -> () + ^bb2: + "loop.terminator"() : () -> () + } + ) : (index, index, index) -> () + return +} + +// ----- + +func @loop_for_single_index_argument(%arg0: index) { + // expected-error@+1 {{expected body to have a single index argument for the induction variable}} + "loop.for"(%arg0, %arg0, %arg0) ( + { + ^bb0(%i0 : f32): + "loop.terminator"() : () -> () + } + ) : (index, index, index) -> () + return +} + +// ----- + +func @loop_if_not_i1(%arg0: index) { + // expected-error@+1 {{operand #0 must be 1-bit integer}} + "loop.if"(%arg0) : (index) -> () + return +} + +// ----- + +func @loop_if_more_than_2_regions(%arg0: i1) { + // expected-error@+1 {{op has incorrect number of regions: expected 2}} + "loop.if"(%arg0) ({}, {}, {}): (i1) -> () + return +} + +// ----- + +func @loop_if_not_one_block_per_region(%arg0: i1) { + // expected-error@+1 {{expects region #0 to have 0 or 1 blocks}} + "loop.if"(%arg0) ({ + ^bb0: + "loop.terminator"() : () -> () + ^bb1: + "loop.terminator"() : () -> () + }, {}): (i1) -> () + return +} + +// ----- + +func @loop_if_illegal_block_argument(%arg0: i1) { + // expected-error@+1 {{requires that child entry blocks have no arguments}} + "loop.if"(%arg0) ({ + ^bb0(%0 : index): + "loop.terminator"() : () -> () + }, {}): (i1) -> () + return +} + diff --git a/mlir/test/Dialect/Loops/ops.mlir b/mlir/test/Dialect/Loops/ops.mlir new file mode 100644 index 0000000..a51438b --- /dev/null +++ b/mlir/test/Dialect/Loops/ops.mlir @@ -0,0 +1,51 @@ +// RUN: mlir-opt %s | FileCheck %s +// Verify the printed output can be parsed. +// RUN: mlir-opt %s | mlir-opt | FileCheck %s +// Verify the generic form can be parsed. +// RUN: mlir-opt -mlir-print-op-generic %s | mlir-opt | FileCheck %s + +func @std_for(%arg0 : index, %arg1 : index, %arg2 : index) { + loop.for %i0 = %arg0 to %arg1 step %arg2 { + loop.for %i1 = %arg0 to %arg1 step %arg2 { + %min_cmp = cmpi "slt", %i0, %i1 : index + %min = select %min_cmp, %i0, %i1 : index + %max_cmp = cmpi "sge", %i0, %i1 : index + %max = select %max_cmp, %i0, %i1 : index + loop.for %i2 = %min to %max step %i1 { + } + } + } + return +} +// CHECK-LABEL: func @std_for( +// CHECK-NEXT: loop.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} { +// CHECK-NEXT: loop.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} { +// CHECK-NEXT: %{{.*}} = cmpi "slt", %{{.*}}, %{{.*}} : index +// CHECK-NEXT: %{{.*}} = select %{{.*}}, %{{.*}}, %{{.*}} : index +// CHECK-NEXT: %{{.*}} = cmpi "sge", %{{.*}}, %{{.*}} : index +// CHECK-NEXT: %{{.*}} = select %{{.*}}, %{{.*}}, %{{.*}} : index +// CHECK-NEXT: loop.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} { + +func @std_if(%arg0: i1, %arg1: f32) { + loop.if %arg0 { + %0 = addf %arg1, %arg1 : f32 + } + return +} +// CHECK-LABEL: func @std_if( +// CHECK-NEXT: loop.if %{{.*}} { +// CHECK-NEXT: %{{.*}} = addf %{{.*}}, %{{.*}} : f32 + +func @std_if_else(%arg0: i1, %arg1: f32) { + loop.if %arg0 { + %0 = addf %arg1, %arg1 : f32 + } else { + %1 = addf %arg1, %arg1 : f32 + } + return +} +// CHECK-LABEL: func @std_if_else( +// CHECK-NEXT: loop.if %{{.*}} { +// CHECK-NEXT: %{{.*}} = addf %{{.*}}, %{{.*}} : f32 +// CHECK-NEXT: } else { +// CHECK-NEXT: %{{.*}} = addf %{{.*}}, %{{.*}} : f32 diff --git a/mlir/test/IR/core-ops.mlir b/mlir/test/IR/core-ops.mlir index 45de949..294b88a 100644 --- a/mlir/test/IR/core-ops.mlir +++ b/mlir/test/IR/core-ops.mlir @@ -424,48 +424,3 @@ func @test_vector.transfer_ops(%arg0: memref) { return } -func @std_for(%arg0 : index, %arg1 : index, %arg2 : index) { - loop.for %i0 = %arg0 to %arg1 step %arg2 { - loop.for %i1 = %arg0 to %arg1 step %arg2 { - %min_cmp = cmpi "slt", %i0, %i1 : index - %min = select %min_cmp, %i0, %i1 : index - %max_cmp = cmpi "sge", %i0, %i1 : index - %max = select %max_cmp, %i0, %i1 : index - loop.for %i2 = %min to %max step %i1 { - } - } - } - return -} -// CHECK-LABEL: func @std_for( -// CHECK-NEXT: loop.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} { -// CHECK-NEXT: loop.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} { -// CHECK-NEXT: %{{.*}} = cmpi "slt", %{{.*}}, %{{.*}} : index -// CHECK-NEXT: %{{.*}} = select %{{.*}}, %{{.*}}, %{{.*}} : index -// CHECK-NEXT: %{{.*}} = cmpi "sge", %{{.*}}, %{{.*}} : index -// CHECK-NEXT: %{{.*}} = select %{{.*}}, %{{.*}}, %{{.*}} : index -// CHECK-NEXT: loop.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} { - -func @std_if(%arg0: i1, %arg1: f32) { - loop.if %arg0 { - %0 = addf %arg1, %arg1 : f32 - } - return -} -// CHECK-LABEL: func @std_if( -// CHECK-NEXT: loop.if %{{.*}} { -// CHECK-NEXT: %{{.*}} = addf %{{.*}}, %{{.*}} : f32 - -func @std_if_else(%arg0: i1, %arg1: f32) { - loop.if %arg0 { - %0 = addf %arg1, %arg1 : f32 - } else { - %1 = addf %arg1, %arg1 : f32 - } - return -} -// CHECK-LABEL: func @std_if_else( -// CHECK-NEXT: loop.if %{{.*}} { -// CHECK-NEXT: %{{.*}} = addf %{{.*}}, %{{.*}} : f32 -// CHECK-NEXT: } else { -// CHECK-NEXT: %{{.*}} = addf %{{.*}}, %{{.*}} : f32 diff --git a/mlir/test/IR/invalid-ops.mlir b/mlir/test/IR/invalid-ops.mlir index 36e0ebb..552b19c 100644 --- a/mlir/test/IR/invalid-ops.mlir +++ b/mlir/test/IR/invalid-ops.mlir @@ -702,121 +702,6 @@ func @index_cast_float_to_index(%arg0: f32) { // ----- -func @std_for_lb(%arg0: f32, %arg1: index) { - // expected-error@+1 {{operand #0 must be index}} - "loop.for"(%arg0, %arg1, %arg1) : (f32, index, index) -> () - return -} - -// ----- - -func @std_for_ub(%arg0: f32, %arg1: index) { - // expected-error@+1 {{operand #1 must be index}} - "loop.for"(%arg1, %arg0, %arg1) : (index, f32, index) -> () - return -} - -// ----- - -func @std_for_step(%arg0: f32, %arg1: index) { - // expected-error@+1 {{operand #2 must be index}} - "loop.for"(%arg1, %arg1, %arg0) : (index, index, f32) -> () - return -} - -// ----- - -func @std_for_step_nonnegative(%arg0: index) { - // expected-error@+2 {{constant step operand must be nonnegative}} - %c0 = constant 0 : index - "loop.for"(%arg0, %arg0, %c0) ({ - ^bb0(%arg1: index): - "loop.terminator"() : () -> () - }) : (index, index, index) -> () - return -} - -// ----- - -func @std_for_one_region(%arg0: index) { - // expected-error@+1 {{incorrect number of regions: expected 1 but found 2}} - "loop.for"(%arg0, %arg0, %arg0) ( - {"loop.terminator"() : () -> ()}, - {"loop.terminator"() : () -> ()} - ) : (index, index, index) -> () - return -} - -// ----- - -func @std_for_single_block(%arg0: index) { - // expected-error@+1 {{expects region #0 to have 0 or 1 blocks}} - "loop.for"(%arg0, %arg0, %arg0) ( - { - ^bb1: - "loop.terminator"() : () -> () - ^bb2: - "loop.terminator"() : () -> () - } - ) : (index, index, index) -> () - return -} - -// ----- - -func @std_for_single_index_argument(%arg0: index) { - // expected-error@+1 {{expected body to have a single index argument for the induction variable}} - "loop.for"(%arg0, %arg0, %arg0) ( - { - ^bb0(%i0 : f32): - "loop.terminator"() : () -> () - } - ) : (index, index, index) -> () - return -} - -// ----- - -func @std_if_not_i1(%arg0: index) { - // expected-error@+1 {{operand #0 must be 1-bit integer}} - "loop.if"(%arg0) : (index) -> () - return -} - -// ----- - -func @std_if_more_than_2_regions(%arg0: i1) { - // expected-error@+1 {{op has incorrect number of regions: expected 2}} - "loop.if"(%arg0) ({}, {}, {}): (i1) -> () - return -} - -// ----- - -func @std_if_not_one_block_per_region(%arg0: i1) { - // expected-error@+1 {{expects region #0 to have 0 or 1 blocks}} - "loop.if"(%arg0) ({ - ^bb0: - "loop.terminator"() : () -> () - ^bb1: - "loop.terminator"() : () -> () - }, {}): (i1) -> () - return -} - -// ----- - -func @std_if_illegal_block_argument(%arg0: i1) { - // expected-error@+1 {{requires that child entry blocks have no arguments}} - "loop.if"(%arg0) ({ - ^bb0(%0 : index): - "loop.terminator"() : () -> () - }, {}): (i1) -> () - return -} - -// ----- - func @return_not_in_function() { "foo.region"() ({ // expected-error@+1 {{must be nested within a 'func' region}} -- 2.7.4