File: value-bounds-op-interface-impl.mlir

package info (click to toggle)
swiftlang 6.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,604 kB
  • sloc: cpp: 9,901,740; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (233 lines) | stat: -rw-r--r-- 8,347 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// RUN: mlir-opt %s -test-affine-reify-value-bounds="reify-to-func-args" \
// RUN:     -verify-diagnostics -split-input-file | FileCheck %s

// CHECK-LABEL: func @scf_for(
//  CHECK-SAME:     %[[a:.*]]: index, %[[b:.*]]: index, %[[c:.*]]: index
//       CHECK:   "test.some_use"(%[[a]], %[[b]])
func.func @scf_for(%a: index, %b: index, %c: index) {
  scf.for %iv = %a to %b step %c {
    %0 = "test.reify_bound"(%iv) {type = "LB"} : (index) -> (index)
    %1 = "test.reify_bound"(%iv) {type = "UB"} : (index) -> (index)
    "test.some_use"(%0, %1) : (index, index) -> ()
  }
  return
}

// -----

// CHECK-LABEL: func @scf_for_index_result_small(
//  CHECK-SAME:     %[[i:.*]]: index, %[[a:.*]]: index, %[[b:.*]]: index, %[[c:.*]]: index
//       CHECK:   "test.some_use"(%[[i]])
//       CHECK:   "test.some_use"(%[[i]])
func.func @scf_for_index_result_small(%i: index, %a: index, %b: index, %c: index) {
  %0 = scf.for %iv = %a to %b step %c iter_args(%arg = %i) -> index {
    %1 = "test.reify_bound"(%arg) {type = "EQ"} : (index) -> (index)
    "test.some_use"(%1) : (index) -> ()
    scf.yield %arg : index
  }
  %2 = "test.reify_bound"(%0) {type = "EQ"} : (index) -> (index)
  "test.some_use"(%2) : (index) -> ()
  return
}

// -----

// CHECK-LABEL: func @scf_for_index_result(
//  CHECK-SAME:     %[[i:.*]]: index, %[[a:.*]]: index, %[[b:.*]]: index, %[[c:.*]]: index
//       CHECK:   "test.some_use"(%[[i]])
//       CHECK:   "test.some_use"(%[[i]])
func.func @scf_for_index_result(%i: index, %a: index, %b: index, %c: index) {
  %0 = scf.for %iv = %a to %b step %c iter_args(%arg = %i) -> index {
    %add = arith.addi %arg, %a : index
    %sub = arith.subi %add, %a : index

    %1 = "test.reify_bound"(%arg) {type = "EQ"} : (index) -> (index)
    "test.some_use"(%1) : (index) -> ()
    scf.yield %sub : index
  }
  %2 = "test.reify_bound"(%0) {type = "EQ"} : (index) -> (index)
  "test.some_use"(%2) : (index) -> ()
  return
}

// -----

// CHECK-LABEL: func @scf_for_tensor_result_small(
//  CHECK-SAME:     %[[t:.*]]: tensor<?xf32>, %[[a:.*]]: index, %[[b:.*]]: index, %[[c:.*]]: index
//       CHECK:   %[[dim:.*]] = tensor.dim %[[t]]
//       CHECK:   "test.some_use"(%[[dim]])
//       CHECK:   %[[dim:.*]] = tensor.dim %[[t]]
//       CHECK:   "test.some_use"(%[[dim]])
func.func @scf_for_tensor_result_small(%t: tensor<?xf32>, %a: index, %b: index, %c: index) {
  %0 = scf.for %iv = %a to %b step %c iter_args(%arg = %t) -> tensor<?xf32> {
    %1 = "test.reify_bound"(%arg) {type = "EQ", dim = 0} : (tensor<?xf32>) -> (index)
    "test.some_use"(%1) : (index) -> ()
    scf.yield %arg : tensor<?xf32>
  }
  %2 = "test.reify_bound"(%0) {type = "EQ", dim = 0} : (tensor<?xf32>) -> (index)
  "test.some_use"(%2) : (index) -> ()
  return
}

// -----

// CHECK-LABEL: func @scf_for_tensor_result(
//  CHECK-SAME:     %[[t:.*]]: tensor<?xf32>, %[[a:.*]]: index, %[[b:.*]]: index, %[[c:.*]]: index
//       CHECK:   %[[dim:.*]] = tensor.dim %[[t]]
//       CHECK:   "test.some_use"(%[[dim]])
//       CHECK:   %[[dim:.*]] = tensor.dim %[[t]]
//       CHECK:   "test.some_use"(%[[dim]])
func.func @scf_for_tensor_result(%t: tensor<?xf32>, %a: index, %b: index, %c: index) {
  %cst = arith.constant 5.0 : f32
  %0 = scf.for %iv = %a to %b step %c iter_args(%arg = %t) -> tensor<?xf32> {
    %filled = linalg.fill ins(%cst : f32) outs(%arg : tensor<?xf32>) -> tensor<?xf32>
    %1 = "test.reify_bound"(%arg) {type = "EQ", dim = 0} : (tensor<?xf32>) -> (index)
    "test.some_use"(%1) : (index) -> ()
    scf.yield %filled : tensor<?xf32>
  }
  %2 = "test.reify_bound"(%0) {type = "EQ", dim = 0} : (tensor<?xf32>) -> (index)
  "test.some_use"(%2) : (index) -> ()
  return
}

// -----

func.func @scf_for_swapping_yield(%t1: tensor<?xf32>, %t2: tensor<?xf32>, %a: index, %b: index, %c: index) {
  %cst = arith.constant 5.0 : f32
  %r1, %r2 = scf.for %iv = %a to %b step %c iter_args(%arg1 = %t1, %arg2 = %t2) -> (tensor<?xf32>, tensor<?xf32>) {
    %filled1 = linalg.fill ins(%cst : f32) outs(%arg1 : tensor<?xf32>) -> tensor<?xf32>
    %filled2 = linalg.fill ins(%cst : f32) outs(%arg2 : tensor<?xf32>) -> tensor<?xf32>
    scf.yield %filled2, %filled1 : tensor<?xf32>, tensor<?xf32>
  }
  // expected-error @below{{could not reify bound}}
  %reify1 = "test.reify_bound"(%r1) {type = "EQ", dim = 0} : (tensor<?xf32>) -> (index)
  "test.some_use"(%reify1) : (index) -> ()
  return
}

// -----

// CHECK-LABEL: func @scf_if_constant(
func.func @scf_if_constant(%c : i1) {
  // CHECK: arith.constant 4 : index
  // CHECK: arith.constant 9 : index
  %c4 = arith.constant 4 : index
  %c9 = arith.constant 9 : index
  %r = scf.if %c -> index {
    scf.yield %c4 : index
  } else {
    scf.yield %c9 : index
  }

  // CHECK: %[[c4:.*]] = arith.constant 4 : index
  // CHECK: %[[c10:.*]] = arith.constant 10 : index
  %reify1 = "test.reify_bound"(%r) {type = "LB"} : (index) -> (index)
  %reify2 = "test.reify_bound"(%r) {type = "UB"} : (index) -> (index)
  // CHECK: "test.some_use"(%[[c4]], %[[c10]])
  "test.some_use"(%reify1, %reify2) : (index, index) -> ()
  return
}

// -----

// CHECK: #[[$map:.*]] = affine_map<()[s0, s1] -> (s0 + s1)>
// CHECK: #[[$map1:.*]] = affine_map<()[s0, s1] -> (s0 + s1 + 5)>
// CHECK-LABEL: func @scf_if_dynamic(
//  CHECK-SAME:     %[[a:.*]]: index, %[[b:.*]]: index, %{{.*}}: i1)
func.func @scf_if_dynamic(%a: index, %b: index, %c : i1) {
  %c4 = arith.constant 4 : index
  %r = scf.if %c -> index {
    %add1 = arith.addi %a, %b : index
    scf.yield %add1 : index
  } else {
    %add2 = arith.addi %b, %c4 : index
    %add3 = arith.addi %add2, %a : index
    scf.yield %add3 : index
  }

  // CHECK: %[[lb:.*]] = affine.apply #[[$map]]()[%[[a]], %[[b]]]
  // CHECK: %[[ub:.*]] = affine.apply #[[$map1]]()[%[[a]], %[[b]]]
  %reify1 = "test.reify_bound"(%r) {type = "LB"} : (index) -> (index)
  %reify2 = "test.reify_bound"(%r) {type = "UB"} : (index) -> (index)
  // CHECK: "test.some_use"(%[[lb]], %[[ub]])
  "test.some_use"(%reify1, %reify2) : (index, index) -> ()
  return
}

// -----

func.func @scf_if_no_affine_bound(%a: index, %b: index, %c : i1) {
  %r = scf.if %c -> index {
    scf.yield %a : index
  } else {
    scf.yield %b : index
  }
  // The reified bound would be min(%a, %b). min/max expressions are not
  // supported in reified bounds.
  // expected-error @below{{could not reify bound}}
  %reify1 = "test.reify_bound"(%r) {type = "LB"} : (index) -> (index)
  "test.some_use"(%reify1) : (index) -> ()
  return
}

// -----

// CHECK-LABEL: func @scf_if_tensor_dim(
func.func @scf_if_tensor_dim(%c : i1) {
  // CHECK: arith.constant 4 : index
  // CHECK: arith.constant 9 : index
  %c4 = arith.constant 4 : index
  %c9 = arith.constant 9 : index
  %t1 = tensor.empty(%c4) : tensor<?xf32>
  %t2 = tensor.empty(%c9) : tensor<?xf32>
  %r = scf.if %c -> tensor<?xf32> {
    scf.yield %t1 : tensor<?xf32>
  } else {
    scf.yield %t2 : tensor<?xf32>
  }

  // CHECK: %[[c4:.*]] = arith.constant 4 : index
  // CHECK: %[[c10:.*]] = arith.constant 10 : index
  %reify1 = "test.reify_bound"(%r) {type = "LB", dim = 0}
      : (tensor<?xf32>) -> (index)
  %reify2 = "test.reify_bound"(%r) {type = "UB", dim = 0}
      : (tensor<?xf32>) -> (index)
  // CHECK: "test.some_use"(%[[c4]], %[[c10]])
  "test.some_use"(%reify1, %reify2) : (index, index) -> ()
  return
}

// -----

// CHECK: #[[$map:.*]] = affine_map<()[s0, s1] -> (s0 + s1)>
// CHECK-LABEL: func @scf_if_eq(
//  CHECK-SAME:     %[[a:.*]]: index, %[[b:.*]]: index, %{{.*}}: i1)
func.func @scf_if_eq(%a: index, %b: index, %c : i1) {
  %c0 = arith.constant 0 : index
  %r = scf.if %c -> index {
    %add1 = arith.addi %a, %b : index
    scf.yield %add1 : index
  } else {
    %add2 = arith.addi %b, %c0 : index
    %add3 = arith.addi %add2, %a : index
    scf.yield %add3 : index
  }

  // CHECK: %[[eq:.*]] = affine.apply #[[$map]]()[%[[a]], %[[b]]]
  %reify1 = "test.reify_bound"(%r) {type = "EQ"} : (index) -> (index)
  // CHECK: "test.some_use"(%[[eq]])
  "test.some_use"(%reify1) : (index) -> ()
  return
}

// -----

func.func @compare_scf_for(%a: index, %b: index, %c: index) {
  scf.for %iv = %a to %b step %c {
    // expected-remark @below{{true}}
    "test.compare"(%iv, %a) {cmp = "GE"} : (index, index) -> ()
    // expected-remark @below{{true}}
    "test.compare"(%iv, %b) {cmp = "LT"} : (index, index) -> ()
  }
  return
}