File: algebraic-simplification.mlir

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (271 lines) | stat: -rw-r--r-- 12,447 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// RUN: mlir-opt %s -test-math-algebraic-simplification | FileCheck %s --dump-input=always

// CHECK-LABEL: @pow_noop
func.func @pow_noop(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
  // CHECK: return %arg0, %arg1
  %c = arith.constant 1.0 : f32
  %v = arith.constant dense <1.0> : vector<4xf32>
  %0 = math.powf %arg0, %c : f32
  %1 = math.powf %arg1, %v : vector<4xf32>
  return %0, %1 : f32, vector<4xf32>
}

// CHECK-LABEL: @pow_square
func.func @pow_square(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
  // CHECK: %[[SCALAR:.*]] = arith.mulf %arg0, %arg0
  // CHECK: %[[VECTOR:.*]] = arith.mulf %arg1, %arg1
  // CHECK: return %[[SCALAR]], %[[VECTOR]]
  %c = arith.constant 2.0 : f32
  %v = arith.constant dense <2.0> : vector<4xf32>
  %0 = math.powf %arg0, %c : f32
  %1 = math.powf %arg1, %v : vector<4xf32>
  return %0, %1 : f32, vector<4xf32>
}

// CHECK-LABEL: @pow_cube
func.func @pow_cube(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
  // CHECK: %[[TMP_S:.*]] = arith.mulf %arg0, %arg0
  // CHECK: %[[SCALAR:.*]] = arith.mulf %arg0, %[[TMP_S]]
  // CHECK: %[[TMP_V:.*]] = arith.mulf %arg1, %arg1
  // CHECK: %[[VECTOR:.*]] = arith.mulf %arg1, %[[TMP_V]]
  // CHECK: return %[[SCALAR]], %[[VECTOR]]
  %c = arith.constant 3.0 : f32
  %v = arith.constant dense <3.0> : vector<4xf32>
  %0 = math.powf %arg0, %c : f32
  %1 = math.powf %arg1, %v : vector<4xf32>
  return %0, %1 : f32, vector<4xf32>
}

// CHECK-LABEL: @pow_recip
func.func @pow_recip(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
  // CHECK: %[[CST_S:.*]] = arith.constant 1.0{{.*}} : f32
  // CHECK: %[[CST_V:.*]] = arith.constant dense<1.0{{.*}}> : vector<4xf32>
  // CHECK: %[[SCALAR:.*]] = arith.divf %[[CST_S]], %arg0
  // CHECK: %[[VECTOR:.*]] = arith.divf %[[CST_V]], %arg1
  // CHECK: return %[[SCALAR]], %[[VECTOR]]
  %c = arith.constant -1.0 : f32
  %v = arith.constant dense <-1.0> : vector<4xf32>
  %0 = math.powf %arg0, %c : f32
  %1 = math.powf %arg1, %v : vector<4xf32>
  return %0, %1 : f32, vector<4xf32>
}

// CHECK-LABEL: @pow_sqrt
func.func @pow_sqrt(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
  // CHECK: %[[SCALAR:.*]] = math.sqrt %arg0
  // CHECK: %[[VECTOR:.*]] = math.sqrt %arg1
  // CHECK: return %[[SCALAR]], %[[VECTOR]]
  %c = arith.constant 0.5 : f32
  %v = arith.constant dense <0.5> : vector<4xf32>
  %0 = math.powf %arg0, %c : f32
  %1 = math.powf %arg1, %v : vector<4xf32>
  return %0, %1 : f32, vector<4xf32>
}

// CHECK-LABEL: @pow_rsqrt
func.func @pow_rsqrt(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
  // CHECK: %[[SCALAR:.*]] = math.rsqrt %arg0
  // CHECK: %[[VECTOR:.*]] = math.rsqrt %arg1
  // CHECK: return %[[SCALAR]], %[[VECTOR]]
  %c = arith.constant -0.5 : f32
  %v = arith.constant dense <-0.5> : vector<4xf32>
  %0 = math.powf %arg0, %c : f32
  %1 = math.powf %arg1, %v : vector<4xf32>
  return %0, %1 : f32, vector<4xf32>
}

// CHECK-LABEL: @pow_0_75
func.func @pow_0_75(%arg0: f32, %arg1 : vector<4xf32>) -> (f32, vector<4xf32>) {
  // CHECK: %[[SQRT1S:.*]] = math.sqrt %arg0
  // CHECK: %[[SQRT2S:.*]] = math.sqrt %[[SQRT1S]]
  // CHECK: %[[SCALAR:.*]] = arith.mulf %[[SQRT1S]], %[[SQRT2S]]
  // CHECK: %[[SQRT1V:.*]] = math.sqrt %arg1
  // CHECK: %[[SQRT2V:.*]] = math.sqrt %[[SQRT1V]]
  // CHECK: %[[VECTOR:.*]] = arith.mulf %[[SQRT1V]], %[[SQRT2V]]
  // CHECK: return %[[SCALAR]], %[[VECTOR]]
  %c = arith.constant 0.75 : f32
  %v = arith.constant dense <0.75> : vector<4xf32>
  %0 = math.powf %arg0, %c : f32
  %1 = math.powf %arg1, %v : vector<4xf32>
  return %0, %1 : f32, vector<4xf32>
}

// CHECK-LABEL: @ipowi_zero_exp(
// CHECK-SAME: %[[ARG0:.+]]: i32
// CHECK-SAME: %[[ARG1:.+]]: vector<4xi32>
// CHECK-SAME: -> (i32, vector<4xi32>) {
func.func @ipowi_zero_exp(%arg0: i32, %arg1: vector<4xi32>) -> (i32, vector<4xi32>) {
  // CHECK: %[[CST_S:.*]] = arith.constant 1 : i32
  // CHECK: %[[CST_V:.*]] = arith.constant dense<1> : vector<4xi32>
  // CHECK: return %[[CST_S]], %[[CST_V]]
  %c = arith.constant 0 : i32
  %v = arith.constant dense <0> : vector<4xi32>
  %0 = math.ipowi %arg0, %c : i32
  %1 = math.ipowi %arg1, %v : vector<4xi32>
  return %0, %1 : i32, vector<4xi32>
}

// CHECK-LABEL: @ipowi_exp_one(
// CHECK-SAME: %[[ARG0:.+]]: i32
// CHECK-SAME: %[[ARG1:.+]]: vector<4xi32>
// CHECK-SAME: -> (i32, vector<4xi32>, i32, vector<4xi32>) {
func.func @ipowi_exp_one(%arg0: i32, %arg1: vector<4xi32>) -> (i32, vector<4xi32>, i32, vector<4xi32>) {
  // CHECK: %[[CST_S:.*]] = arith.constant 1 : i32
  // CHECK: %[[CST_V:.*]] = arith.constant dense<1> : vector<4xi32>
  // CHECK: %[[SCALAR:.*]] = arith.divsi %[[CST_S]], %[[ARG0]]
  // CHECK: %[[VECTOR:.*]] = arith.divsi %[[CST_V]], %[[ARG1]]
  // CHECK: return %[[ARG0]], %[[ARG1]], %[[SCALAR]], %[[VECTOR]]
  %c1 = arith.constant 1 : i32
  %v1 = arith.constant dense <1> : vector<4xi32>
  %0 = math.ipowi %arg0, %c1 : i32
  %1 = math.ipowi %arg1, %v1 : vector<4xi32>
  %cm1 = arith.constant -1 : i32
  %vm1 = arith.constant dense <-1> : vector<4xi32>
  %2 = math.ipowi %arg0, %cm1 : i32
  %3 = math.ipowi %arg1, %vm1 : vector<4xi32>
  return %0, %1, %2, %3 : i32, vector<4xi32>, i32, vector<4xi32>
}

// CHECK-LABEL: @ipowi_exp_two(
// CHECK-SAME: %[[ARG0:.+]]: i32
// CHECK-SAME: %[[ARG1:.+]]: vector<4xi32>
// CHECK-SAME: -> (i32, vector<4xi32>, i32, vector<4xi32>) {
func.func @ipowi_exp_two(%arg0: i32, %arg1: vector<4xi32>) -> (i32, vector<4xi32>, i32, vector<4xi32>) {
  // CHECK: %[[CST_S:.*]] = arith.constant 1 : i32
  // CHECK: %[[CST_V:.*]] = arith.constant dense<1> : vector<4xi32>
  // CHECK: %[[SCALAR0:.*]] = arith.muli %[[ARG0]], %[[ARG0]]
  // CHECK: %[[VECTOR0:.*]] = arith.muli %[[ARG1]], %[[ARG1]]
  // CHECK: %[[SCALAR1:.*]] = arith.divsi %[[CST_S]], %[[ARG0]]
  // CHECK: %[[SMUL:.*]] = arith.muli %[[SCALAR1]], %[[SCALAR1]]
  // CHECK: %[[VECTOR1:.*]] = arith.divsi %[[CST_V]], %[[ARG1]]
  // CHECK: %[[VMUL:.*]] = arith.muli %[[VECTOR1]], %[[VECTOR1]]
  // CHECK: return %[[SCALAR0]], %[[VECTOR0]], %[[SMUL]], %[[VMUL]]
  %c1 = arith.constant 2 : i32
  %v1 = arith.constant dense <2> : vector<4xi32>
  %0 = math.ipowi %arg0, %c1 : i32
  %1 = math.ipowi %arg1, %v1 : vector<4xi32>
  %cm1 = arith.constant -2 : i32
  %vm1 = arith.constant dense <-2> : vector<4xi32>
  %2 = math.ipowi %arg0, %cm1 : i32
  %3 = math.ipowi %arg1, %vm1 : vector<4xi32>
  return %0, %1, %2, %3 : i32, vector<4xi32>, i32, vector<4xi32>
}

// CHECK-LABEL: @ipowi_exp_three(
// CHECK-SAME: %[[ARG0:.+]]: i32
// CHECK-SAME: %[[ARG1:.+]]: vector<4xi32>
// CHECK-SAME: -> (i32, vector<4xi32>, i32, vector<4xi32>) {
func.func @ipowi_exp_three(%arg0: i32, %arg1: vector<4xi32>) -> (i32, vector<4xi32>, i32, vector<4xi32>) {
  // CHECK: %[[CST_S:.*]] = arith.constant 1 : i32
  // CHECK: %[[CST_V:.*]] = arith.constant dense<1> : vector<4xi32>
  // CHECK: %[[SMUL0:.*]] = arith.muli %[[ARG0]], %[[ARG0]]
  // CHECK: %[[SCALAR0:.*]] = arith.muli %[[SMUL0]], %[[ARG0]]
  // CHECK: %[[VMUL0:.*]] = arith.muli %[[ARG1]], %[[ARG1]]
  // CHECK: %[[VECTOR0:.*]] = arith.muli %[[VMUL0]], %[[ARG1]]
  // CHECK: %[[SCALAR1:.*]] = arith.divsi %[[CST_S]], %[[ARG0]]
  // CHECK: %[[SMUL1:.*]] = arith.muli %[[SCALAR1]], %[[SCALAR1]]
  // CHECK: %[[SMUL2:.*]] = arith.muli %[[SMUL1]], %[[SCALAR1]]
  // CHECK: %[[VECTOR1:.*]] = arith.divsi %[[CST_V]], %[[ARG1]]
  // CHECK: %[[VMUL1:.*]] = arith.muli %[[VECTOR1]], %[[VECTOR1]]
  // CHECK: %[[VMUL2:.*]] = arith.muli %[[VMUL1]], %[[VECTOR1]]
  // CHECK: return %[[SCALAR0]], %[[VECTOR0]], %[[SMUL2]], %[[VMUL2]]
  %c1 = arith.constant 3 : i32
  %v1 = arith.constant dense <3> : vector<4xi32>
  %0 = math.ipowi %arg0, %c1 : i32
  %1 = math.ipowi %arg1, %v1 : vector<4xi32>
  %cm1 = arith.constant -3 : i32
  %vm1 = arith.constant dense <-3> : vector<4xi32>
  %2 = math.ipowi %arg0, %cm1 : i32
  %3 = math.ipowi %arg1, %vm1 : vector<4xi32>
  return %0, %1, %2, %3 : i32, vector<4xi32>, i32, vector<4xi32>
}

// CHECK-LABEL: @fpowi_zero_exp(
// CHECK-SAME: %[[ARG0:.+]]: f32
// CHECK-SAME: %[[ARG1:.+]]: vector<4xf32>
// CHECK-SAME: -> (f32, vector<4xf32>) {
func.func @fpowi_zero_exp(%arg0: f32, %arg1: vector<4xf32>) -> (f32, vector<4xf32>) {
  // CHECK: %[[CST_S:.*]] = arith.constant 1.000000e+00 : f32
  // CHECK: %[[CST_V:.*]] = arith.constant dense<1.000000e+00> : vector<4xf32>
  // CHECK: return %[[CST_S]], %[[CST_V]]
  %c = arith.constant 0 : i32
  %v = arith.constant dense <0> : vector<4xi32>
  %0 = math.fpowi %arg0, %c : f32, i32
  %1 = math.fpowi %arg1, %v : vector<4xf32>, vector<4xi32>
  return %0, %1 : f32, vector<4xf32>
}

// CHECK-LABEL: @fpowi_exp_one(
// CHECK-SAME: %[[ARG0:.+]]: f32
// CHECK-SAME: %[[ARG1:.+]]: vector<4xf32>
// CHECK-SAME: -> (f32, vector<4xf32>, f32, vector<4xf32>) {
func.func @fpowi_exp_one(%arg0: f32, %arg1: vector<4xf32>) -> (f32, vector<4xf32>, f32, vector<4xf32>) {
  // CHECK: %[[CST_S:.*]] = arith.constant 1.000000e+00 : f32
  // CHECK: %[[CST_V:.*]] = arith.constant dense<1.000000e+00> : vector<4xf32>
  // CHECK: %[[SCALAR:.*]] = arith.divf %[[CST_S]], %[[ARG0]]
  // CHECK: %[[VECTOR:.*]] = arith.divf %[[CST_V]], %[[ARG1]]
  // CHECK: return %[[ARG0]], %[[ARG1]], %[[SCALAR]], %[[VECTOR]]
  %c1 = arith.constant 1 : i32
  %v1 = arith.constant dense <1> : vector<4xi32>
  %0 = math.fpowi %arg0, %c1 : f32, i32
  %1 = math.fpowi %arg1, %v1 : vector<4xf32>, vector<4xi32>
  %cm1 = arith.constant -1 : i32
  %vm1 = arith.constant dense <-1> : vector<4xi32>
  %2 = math.fpowi %arg0, %cm1 : f32, i32
  %3 = math.fpowi %arg1, %vm1 : vector<4xf32>, vector<4xi32>
  return %0, %1, %2, %3 : f32, vector<4xf32>, f32, vector<4xf32>
}

// CHECK-LABEL: @fpowi_exp_two(
// CHECK-SAME: %[[ARG0:.+]]: f32
// CHECK-SAME: %[[ARG1:.+]]: vector<4xf32>
// CHECK-SAME: -> (f32, vector<4xf32>, f32, vector<4xf32>) {
func.func @fpowi_exp_two(%arg0: f32, %arg1: vector<4xf32>) -> (f32, vector<4xf32>, f32, vector<4xf32>) {
  // CHECK: %[[CST_S:.*]] = arith.constant 1.000000e+00 : f32
  // CHECK: %[[CST_V:.*]] = arith.constant dense<1.000000e+00> : vector<4xf32>
  // CHECK: %[[SCALAR0:.*]] = arith.mulf %[[ARG0]], %[[ARG0]]
  // CHECK: %[[VECTOR0:.*]] = arith.mulf %[[ARG1]], %[[ARG1]]
  // CHECK: %[[SCALAR1:.*]] = arith.divf %[[CST_S]], %[[ARG0]]
  // CHECK: %[[SMUL:.*]] = arith.mulf %[[SCALAR1]], %[[SCALAR1]]
  // CHECK: %[[VECTOR1:.*]] = arith.divf %[[CST_V]], %[[ARG1]]
  // CHECK: %[[VMUL:.*]] = arith.mulf %[[VECTOR1]], %[[VECTOR1]]
  // CHECK: return %[[SCALAR0]], %[[VECTOR0]], %[[SMUL]], %[[VMUL]]
  %c1 = arith.constant 2 : i32
  %v1 = arith.constant dense <2> : vector<4xi32>
  %0 = math.fpowi %arg0, %c1 : f32, i32
  %1 = math.fpowi %arg1, %v1 : vector<4xf32>, vector<4xi32>
  %cm1 = arith.constant -2 : i32
  %vm1 = arith.constant dense <-2> : vector<4xi32>
  %2 = math.fpowi %arg0, %cm1 : f32, i32
  %3 = math.fpowi %arg1, %vm1 : vector<4xf32>, vector<4xi32>
  return %0, %1, %2, %3 : f32, vector<4xf32>, f32, vector<4xf32>
}

// CHECK-LABEL: @fpowi_exp_three(
// CHECK-SAME: %[[ARG0:.+]]: f32
// CHECK-SAME: %[[ARG1:.+]]: vector<4xf32>
// CHECK-SAME: -> (f32, vector<4xf32>, f32, vector<4xf32>) {
func.func @fpowi_exp_three(%arg0: f32, %arg1: vector<4xf32>) -> (f32, vector<4xf32>, f32, vector<4xf32>) {
  // CHECK: %[[CST_S:.*]] = arith.constant 1.000000e+00 : f32
  // CHECK: %[[CST_V:.*]] = arith.constant dense<1.000000e+00> : vector<4xf32>
  // CHECK: %[[SMUL0:.*]] = arith.mulf %[[ARG0]], %[[ARG0]]
  // CHECK: %[[SCALAR0:.*]] = arith.mulf %[[SMUL0]], %[[ARG0]]
  // CHECK: %[[VMUL0:.*]] = arith.mulf %[[ARG1]], %[[ARG1]]
  // CHECK: %[[VECTOR0:.*]] = arith.mulf %[[VMUL0]], %[[ARG1]]
  // CHECK: %[[SCALAR1:.*]] = arith.divf %[[CST_S]], %[[ARG0]]
  // CHECK: %[[SMUL1:.*]] = arith.mulf %[[SCALAR1]], %[[SCALAR1]]
  // CHECK: %[[SMUL2:.*]] = arith.mulf %[[SMUL1]], %[[SCALAR1]]
  // CHECK: %[[VECTOR1:.*]] = arith.divf %[[CST_V]], %[[ARG1]]
  // CHECK: %[[VMUL1:.*]] = arith.mulf %[[VECTOR1]], %[[VECTOR1]]
  // CHECK: %[[VMUL2:.*]] = arith.mulf %[[VMUL1]], %[[VECTOR1]]
  // CHECK: return %[[SCALAR0]], %[[VECTOR0]], %[[SMUL2]], %[[VMUL2]]
  %c1 = arith.constant 3 : i32
  %v1 = arith.constant dense <3> : vector<4xi32>
  %0 = math.fpowi %arg0, %c1 : f32, i32
  %1 = math.fpowi %arg1, %v1 : vector<4xf32>, vector<4xi32>
  %cm1 = arith.constant -3 : i32
  %vm1 = arith.constant dense <-3> : vector<4xi32>
  %2 = math.fpowi %arg0, %cm1 : f32, i32
  %3 = math.fpowi %arg1, %vm1 : vector<4xf32>, vector<4xi32>
  return %0, %1, %2, %3 : f32, vector<4xf32>, f32, vector<4xf32>
}