--- /dev/null
+// 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
+}
+
--- /dev/null
+// 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
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
// -----
-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}}