• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "midgard_nir.h"
2 
3 #include "nir.h"
4 #include "nir_builder.h"
5 #include "nir_search.h"
6 #include "nir_search_helpers.h"
7 
8 /* What follows is NIR algebraic transform code for the following 2
9  * transforms:
10  *    ('pack_unorm_4x8', 'a') => ('pack_32_4x8', ('f2u8', ('fround_even', ('fmul', ('fsat', 'a'), 255.0))))
11  *    ('~fadd', ('fadd', 'a', 'b'), 'a') => ('fadd', ('fadd', 'a', 'a'), 'b')
12  */
13 
14 
15    static const nir_search_variable search0_0 = {
16    { nir_search_value_variable, 32 },
17    0, /* a */
18    false,
19    nir_type_invalid,
20    NULL,
21    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
22 };
23 static const nir_search_expression search0 = {
24    { nir_search_value_expression, 32 },
25    false, false,
26    -1, 0,
27    nir_op_pack_unorm_4x8,
28    { &search0_0.value },
29    NULL,
30 };
31 
32    /* replace0_0_0_0_0_0 -> search0_0 in the cache */
33 static const nir_search_expression replace0_0_0_0_0 = {
34    { nir_search_value_expression, 32 },
35    false, false,
36    -1, 0,
37    nir_op_fsat,
38    { &search0_0.value },
39    NULL,
40 };
41 
42 static const nir_search_constant replace0_0_0_0_1 = {
43    { nir_search_value_constant, 32 },
44    nir_type_float, { 0x406fe00000000000 /* 255.0 */ },
45 };
46 static const nir_search_expression replace0_0_0_0 = {
47    { nir_search_value_expression, 32 },
48    false, false,
49    0, 1,
50    nir_op_fmul,
51    { &replace0_0_0_0_0.value, &replace0_0_0_0_1.value },
52    NULL,
53 };
54 static const nir_search_expression replace0_0_0 = {
55    { nir_search_value_expression, 32 },
56    false, false,
57    -1, 1,
58    nir_op_fround_even,
59    { &replace0_0_0_0.value },
60    NULL,
61 };
62 static const nir_search_expression replace0_0 = {
63    { nir_search_value_expression, 8 },
64    false, false,
65    -1, 1,
66    nir_op_f2u8,
67    { &replace0_0_0.value },
68    NULL,
69 };
70 static const nir_search_expression replace0 = {
71    { nir_search_value_expression, 32 },
72    false, false,
73    -1, 1,
74    nir_op_pack_32_4x8,
75    { &replace0_0.value },
76    NULL,
77 };
78 
79    static const nir_search_variable search1_0_0 = {
80    { nir_search_value_variable, -2 },
81    0, /* a */
82    false,
83    nir_type_invalid,
84    NULL,
85    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
86 };
87 
88 static const nir_search_variable search1_0_1 = {
89    { nir_search_value_variable, -2 },
90    1, /* b */
91    false,
92    nir_type_invalid,
93    NULL,
94    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
95 };
96 static const nir_search_expression search1_0 = {
97    { nir_search_value_expression, -2 },
98    false, false,
99    1, 1,
100    nir_op_fadd,
101    { &search1_0_0.value, &search1_0_1.value },
102    NULL,
103 };
104 
105 /* search1_1 -> search1_0_0 in the cache */
106 static const nir_search_expression search1 = {
107    { nir_search_value_expression, -2 },
108    true, false,
109    0, 2,
110    nir_op_fadd,
111    { &search1_0.value, &search1_0_0.value },
112    NULL,
113 };
114 
115    /* replace1_0_0 -> search1_0_0 in the cache */
116 
117 /* replace1_0_1 -> search1_0_0 in the cache */
118 static const nir_search_expression replace1_0 = {
119    { nir_search_value_expression, -2 },
120    false, false,
121    -1, 0,
122    nir_op_fadd,
123    { &search1_0_0.value, &search1_0_0.value },
124    NULL,
125 };
126 
127 /* replace1_1 -> search1_0_1 in the cache */
128 static const nir_search_expression replace1 = {
129    { nir_search_value_expression, -2 },
130    false, false,
131    0, 1,
132    nir_op_fadd,
133    { &replace1_0.value, &search1_0_1.value },
134    NULL,
135 };
136 
137 
138 static const struct transform midgard_nir_lower_algebraic_early_state2_xforms[] = {
139   { &search0, &replace0.value, 0 },
140 };
141 static const struct transform midgard_nir_lower_algebraic_early_state4_xforms[] = {
142   { &search1, &replace1.value, 0 },
143 };
144 
145 static const struct per_op_table midgard_nir_lower_algebraic_early_table[nir_num_search_ops] = {
146    [nir_op_pack_unorm_4x8] = {
147       .filter = (uint16_t []) {
148          0,
149          0,
150          0,
151          0,
152          0,
153       },
154 
155       .num_filtered_states = 1,
156       .table = (uint16_t []) {
157 
158          2,
159       },
160    },
161    [nir_op_fadd] = {
162       .filter = (uint16_t []) {
163          0,
164          0,
165          0,
166          1,
167          1,
168       },
169 
170       .num_filtered_states = 2,
171       .table = (uint16_t []) {
172 
173          3,
174          4,
175          4,
176          4,
177       },
178    },
179 };
180 
181 const struct transform *midgard_nir_lower_algebraic_early_transforms[] = {
182    NULL,
183    NULL,
184    midgard_nir_lower_algebraic_early_state2_xforms,
185    NULL,
186    midgard_nir_lower_algebraic_early_state4_xforms,
187 };
188 
189 const uint16_t midgard_nir_lower_algebraic_early_transform_counts[] = {
190    0,
191    0,
192    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_early_state2_xforms),
193    0,
194    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_early_state4_xforms),
195 };
196 
197 bool
midgard_nir_lower_algebraic_early(nir_shader * shader)198 midgard_nir_lower_algebraic_early(nir_shader *shader)
199 {
200    bool progress = false;
201    bool condition_flags[1];
202    const nir_shader_compiler_options *options = shader->options;
203    const shader_info *info = &shader->info;
204    (void) options;
205    (void) info;
206 
207    condition_flags[0] = true;
208 
209    nir_foreach_function(function, shader) {
210       if (function->impl) {
211          progress |= nir_algebraic_impl(function->impl, condition_flags,
212                                         midgard_nir_lower_algebraic_early_transforms,
213                                         midgard_nir_lower_algebraic_early_transform_counts,
214                                         midgard_nir_lower_algebraic_early_table);
215       }
216    }
217 
218    return progress;
219 }
220 
221 
222 #include "nir.h"
223 #include "nir_builder.h"
224 #include "nir_search.h"
225 #include "nir_search_helpers.h"
226 
227 /* What follows is NIR algebraic transform code for the following 51
228  * transforms:
229  *    ('ineg', 'a') => ('isub', 0, 'a')
230  *    ('fsub', 'a', 'b') => ('fadd', 'a', ('fneg', 'b'))
231  *    ('b32csel', 'a', 'b@32', 0) => ('iand', 'a', 'b')
232  *    ('b32csel', 'a', 0, 'b@32') => ('iand', ('inot', 'a'), 'b')
233  *    ('~fmin', ('fmax', 'a', -1.0), 1.0) => ('fsat_signed', 'a')
234  *    ('~fmax', ('fmin', 'a', 1.0), -1.0) => ('fsat_signed', 'a')
235  *    ('fmax', 'a', 0.0) => ('fclamp_pos', 'a')
236  *    ('ishl', 'a@16', 'b') => ('u2u16', ('ishl', ('u2u32', 'a'), 'b'))
237  *    ('ishr', 'a@16', 'b') => ('i2i16', ('ishr', ('i2i32', 'a'), 'b'))
238  *    ('ushr', 'a@16', 'b') => ('u2u16', ('ushr', ('u2u32', 'a'), 'b'))
239  *    ('ishl', 'a@8', 'b') => ('u2u8', ('u2u16', ('ishl', ('u2u32', ('u2u16', 'a')), 'b')))
240  *    ('ishr', 'a@8', 'b') => ('i2i8', ('i2i16', ('ishr', ('i2i32', ('i2i16', 'a')), 'b')))
241  *    ('ushr', 'a@8', 'b') => ('u2u8', ('u2u16', ('ushr', ('u2u32', ('u2u16', 'a')), 'b')))
242  *    ('fmul', 'a', 2.0) => ('fadd', 'a', 'a')
243  *    ('u2u8', 'a@32') => ('u2u8', ('u2u16', 'a'))
244  *    ('u2u8', 'a@64') => ('u2u8', ('u2u16', ('u2u32', 'a')))
245  *    ('u2u16', 'a@64') => ('u2u16', ('u2u32', 'a'))
246  *    ('u2u32', 'a@8') => ('u2u32', ('u2u16', 'a'))
247  *    ('u2u64', 'a@8') => ('u2u64', ('u2u32', ('u2u16', 'a')))
248  *    ('u2u64', 'a@16') => ('u2u64', ('u2u32', 'a'))
249  *    ('i2i8', 'a@32') => ('i2i8', ('i2i16', 'a'))
250  *    ('i2i8', 'a@64') => ('i2i8', ('i2i16', ('i2i32', 'a')))
251  *    ('i2i16', 'a@64') => ('i2i16', ('i2i32', 'a'))
252  *    ('i2i32', 'a@8') => ('i2i32', ('i2i16', 'a'))
253  *    ('i2i64', 'a@8') => ('i2i64', ('i2i32', ('i2i16', 'a')))
254  *    ('i2i64', 'a@16') => ('i2i64', ('i2i32', 'a'))
255  *    ('f2f16', 'a@64') => ('f2f16', ('f2f32', 'a'))
256  *    ('f2f64', 'a@16') => ('f2f64', ('f2f32', 'a'))
257  *    ('i2f16', 'a@64') => ('f2f16', ('f2f32', ('i2f64', 'a')))
258  *    ('i2f32', 'a@8') => ('i2f32', ('i2i32', ('i2i16', 'a')))
259  *    ('i2f64', 'a@8') => ('i2f64', ('i2i64', ('i2i32', ('i2i16', 'a'))))
260  *    ('i2f64', 'a@16') => ('i2f64', ('i2i64', ('i2i32', 'a')))
261  *    ('u2f16', 'a@64') => ('f2f16', ('f2f32', ('u2f64', 'a')))
262  *    ('u2f32', 'a@8') => ('u2f32', ('u2u32', ('u2u16', 'a')))
263  *    ('u2f64', 'a@8') => ('u2f64', ('u2u64', ('u2u32', ('u2u16', 'a'))))
264  *    ('u2f64', 'a@16') => ('u2f64', ('u2u64', ('u2u32', 'a')))
265  *    ('f2i8', 'a@32') => ('i2i8', ('i2i16', ('f2i32', 'a')))
266  *    ('f2i8', 'a@64') => ('i2i8', ('i2i16', ('i2i32', ('f2i64', 'a'))))
267  *    ('f2i16', 'a@64') => ('i2i16', ('i2i32', ('f2i64', 'a')))
268  *    ('f2i64', 'a@16') => ('f2i64', ('f2f64', ('f2f32', 'a')))
269  *    ('f2u8', 'a@32') => ('u2u8', ('u2u16', ('f2u32', 'a')))
270  *    ('f2u8', 'a@64') => ('u2u8', ('u2u16', ('u2u32', ('f2u64', 'a'))))
271  *    ('f2u16', 'a@64') => ('u2u16', ('u2u32', ('f2u64', 'a')))
272  *    ('f2u64', 'a@16') => ('f2u64', ('f2f64', ('f2f32', 'a')))
273  *    ('fge', 'a', '#b') => ('inot', ('flt', 'a', 'b'))
274  *    ('fge32', 'a', '#b') => ('inot', ('flt32', 'a', 'b'))
275  *    ('ige32', 'a', '#b') => ('inot', ('ilt32', 'a', 'b'))
276  *    ('uge32', 'a', '#b') => ('inot', ('ult32', 'a', 'b'))
277  *    ('flt32', '#a', 'b') => ('inot', ('fge32', 'a', 'b'))
278  *    ('ilt32', '#a', 'b') => ('inot', ('ige32', 'a', 'b'))
279  *    ('ult32', '#a', 'b') => ('inot', ('uge32', 'a', 'b'))
280  */
281 
282 
283    static const nir_search_variable search2_0 = {
284    { nir_search_value_variable, -1 },
285    0, /* a */
286    false,
287    nir_type_invalid,
288    NULL,
289    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
290 };
291 static const nir_search_expression search2 = {
292    { nir_search_value_expression, -1 },
293    false, false,
294    -1, 0,
295    nir_op_ineg,
296    { &search2_0.value },
297    NULL,
298 };
299 
300    static const nir_search_constant replace2_0 = {
301    { nir_search_value_constant, -1 },
302    nir_type_int, { 0x0 /* 0 */ },
303 };
304 
305 /* replace2_1 -> search2_0 in the cache */
306 static const nir_search_expression replace2 = {
307    { nir_search_value_expression, -1 },
308    false, false,
309    -1, 0,
310    nir_op_isub,
311    { &replace2_0.value, &search2_0.value },
312    NULL,
313 };
314 
315    static const nir_search_variable search3_0 = {
316    { nir_search_value_variable, -2 },
317    0, /* a */
318    false,
319    nir_type_invalid,
320    NULL,
321    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
322 };
323 
324 static const nir_search_variable search3_1 = {
325    { nir_search_value_variable, -2 },
326    1, /* b */
327    false,
328    nir_type_invalid,
329    NULL,
330    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
331 };
332 static const nir_search_expression search3 = {
333    { nir_search_value_expression, -2 },
334    false, false,
335    -1, 0,
336    nir_op_fsub,
337    { &search3_0.value, &search3_1.value },
338    NULL,
339 };
340 
341    /* replace3_0 -> search3_0 in the cache */
342 
343 /* replace3_1_0 -> search3_1 in the cache */
344 static const nir_search_expression replace3_1 = {
345    { nir_search_value_expression, -2 },
346    false, false,
347    -1, 0,
348    nir_op_fneg,
349    { &search3_1.value },
350    NULL,
351 };
352 static const nir_search_expression replace3 = {
353    { nir_search_value_expression, -2 },
354    false, false,
355    0, 1,
356    nir_op_fadd,
357    { &search3_0.value, &replace3_1.value },
358    NULL,
359 };
360 
361    static const nir_search_variable search4_0 = {
362    { nir_search_value_variable, 32 },
363    0, /* a */
364    false,
365    nir_type_invalid,
366    NULL,
367    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
368 };
369 
370 static const nir_search_variable search4_1 = {
371    { nir_search_value_variable, 32 },
372    1, /* b */
373    false,
374    nir_type_invalid,
375    NULL,
376    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
377 };
378 
379 static const nir_search_constant search4_2 = {
380    { nir_search_value_constant, 32 },
381    nir_type_int, { 0x0 /* 0 */ },
382 };
383 static const nir_search_expression search4 = {
384    { nir_search_value_expression, 32 },
385    false, false,
386    -1, 0,
387    nir_op_b32csel,
388    { &search4_0.value, &search4_1.value, &search4_2.value },
389    NULL,
390 };
391 
392    /* replace4_0 -> search4_0 in the cache */
393 
394 /* replace4_1 -> search4_1 in the cache */
395 static const nir_search_expression replace4 = {
396    { nir_search_value_expression, 32 },
397    false, false,
398    0, 1,
399    nir_op_iand,
400    { &search4_0.value, &search4_1.value },
401    NULL,
402 };
403 
404    /* search5_0 -> search4_0 in the cache */
405 
406 /* search5_1 -> search4_2 in the cache */
407 
408 /* search5_2 -> search4_1 in the cache */
409 static const nir_search_expression search5 = {
410    { nir_search_value_expression, 32 },
411    false, false,
412    -1, 0,
413    nir_op_b32csel,
414    { &search4_0.value, &search4_2.value, &search4_1.value },
415    NULL,
416 };
417 
418    /* replace5_0_0 -> search4_0 in the cache */
419 static const nir_search_expression replace5_0 = {
420    { nir_search_value_expression, 32 },
421    false, false,
422    -1, 0,
423    nir_op_inot,
424    { &search4_0.value },
425    NULL,
426 };
427 
428 /* replace5_1 -> search4_1 in the cache */
429 static const nir_search_expression replace5 = {
430    { nir_search_value_expression, 32 },
431    false, false,
432    0, 1,
433    nir_op_iand,
434    { &replace5_0.value, &search4_1.value },
435    NULL,
436 };
437 
438    /* search6_0_0 -> search2_0 in the cache */
439 
440 static const nir_search_constant search6_0_1 = {
441    { nir_search_value_constant, -1 },
442    nir_type_float, { 0xbff0000000000000L /* -1.0 */ },
443 };
444 static const nir_search_expression search6_0 = {
445    { nir_search_value_expression, -1 },
446    false, false,
447    1, 1,
448    nir_op_fmax,
449    { &search2_0.value, &search6_0_1.value },
450    NULL,
451 };
452 
453 static const nir_search_constant search6_1 = {
454    { nir_search_value_constant, -1 },
455    nir_type_float, { 0x3ff0000000000000 /* 1.0 */ },
456 };
457 static const nir_search_expression search6 = {
458    { nir_search_value_expression, -1 },
459    true, false,
460    0, 2,
461    nir_op_fmin,
462    { &search6_0.value, &search6_1.value },
463    NULL,
464 };
465 
466    /* replace6_0 -> search2_0 in the cache */
467 static const nir_search_expression replace6 = {
468    { nir_search_value_expression, -1 },
469    false, false,
470    -1, 0,
471    nir_op_fsat_signed,
472    { &search2_0.value },
473    NULL,
474 };
475 
476    /* search7_0_0 -> search2_0 in the cache */
477 
478 /* search7_0_1 -> search6_1 in the cache */
479 static const nir_search_expression search7_0 = {
480    { nir_search_value_expression, -1 },
481    false, false,
482    1, 1,
483    nir_op_fmin,
484    { &search2_0.value, &search6_1.value },
485    NULL,
486 };
487 
488 /* search7_1 -> search6_0_1 in the cache */
489 static const nir_search_expression search7 = {
490    { nir_search_value_expression, -1 },
491    true, false,
492    0, 2,
493    nir_op_fmax,
494    { &search7_0.value, &search6_0_1.value },
495    NULL,
496 };
497 
498    /* replace7_0 -> search2_0 in the cache */
499 /* replace7 -> replace6 in the cache */
500 
501    /* search8_0 -> search2_0 in the cache */
502 
503 static const nir_search_constant search8_1 = {
504    { nir_search_value_constant, -1 },
505    nir_type_float, { 0x0 /* 0.0 */ },
506 };
507 static const nir_search_expression search8 = {
508    { nir_search_value_expression, -1 },
509    false, false,
510    0, 1,
511    nir_op_fmax,
512    { &search2_0.value, &search8_1.value },
513    NULL,
514 };
515 
516    /* replace8_0 -> search2_0 in the cache */
517 static const nir_search_expression replace8 = {
518    { nir_search_value_expression, -1 },
519    false, false,
520    -1, 0,
521    nir_op_fclamp_pos,
522    { &search2_0.value },
523    NULL,
524 };
525 
526    static const nir_search_variable search9_0 = {
527    { nir_search_value_variable, 16 },
528    0, /* a */
529    false,
530    nir_type_invalid,
531    NULL,
532    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
533 };
534 
535 /* search9_1 -> search4_1 in the cache */
536 static const nir_search_expression search9 = {
537    { nir_search_value_expression, 16 },
538    false, false,
539    -1, 0,
540    nir_op_ishl,
541    { &search9_0.value, &search4_1.value },
542    NULL,
543 };
544 
545    /* replace9_0_0_0 -> search9_0 in the cache */
546 static const nir_search_expression replace9_0_0 = {
547    { nir_search_value_expression, 32 },
548    false, false,
549    -1, 0,
550    nir_op_u2u32,
551    { &search9_0.value },
552    NULL,
553 };
554 
555 /* replace9_0_1 -> search4_1 in the cache */
556 static const nir_search_expression replace9_0 = {
557    { nir_search_value_expression, 32 },
558    false, false,
559    -1, 0,
560    nir_op_ishl,
561    { &replace9_0_0.value, &search4_1.value },
562    NULL,
563 };
564 static const nir_search_expression replace9 = {
565    { nir_search_value_expression, 16 },
566    false, false,
567    -1, 0,
568    nir_op_u2u16,
569    { &replace9_0.value },
570    NULL,
571 };
572 
573    /* search10_0 -> search9_0 in the cache */
574 
575 /* search10_1 -> search4_1 in the cache */
576 static const nir_search_expression search10 = {
577    { nir_search_value_expression, 16 },
578    false, false,
579    -1, 0,
580    nir_op_ishr,
581    { &search9_0.value, &search4_1.value },
582    NULL,
583 };
584 
585    /* replace10_0_0_0 -> search9_0 in the cache */
586 static const nir_search_expression replace10_0_0 = {
587    { nir_search_value_expression, 32 },
588    false, false,
589    -1, 0,
590    nir_op_i2i32,
591    { &search9_0.value },
592    NULL,
593 };
594 
595 /* replace10_0_1 -> search4_1 in the cache */
596 static const nir_search_expression replace10_0 = {
597    { nir_search_value_expression, 32 },
598    false, false,
599    -1, 0,
600    nir_op_ishr,
601    { &replace10_0_0.value, &search4_1.value },
602    NULL,
603 };
604 static const nir_search_expression replace10 = {
605    { nir_search_value_expression, 16 },
606    false, false,
607    -1, 0,
608    nir_op_i2i16,
609    { &replace10_0.value },
610    NULL,
611 };
612 
613    /* search11_0 -> search9_0 in the cache */
614 
615 /* search11_1 -> search4_1 in the cache */
616 static const nir_search_expression search11 = {
617    { nir_search_value_expression, 16 },
618    false, false,
619    -1, 0,
620    nir_op_ushr,
621    { &search9_0.value, &search4_1.value },
622    NULL,
623 };
624 
625    /* replace11_0_0_0 -> search9_0 in the cache */
626 /* replace11_0_0 -> replace9_0_0 in the cache */
627 
628 /* replace11_0_1 -> search4_1 in the cache */
629 static const nir_search_expression replace11_0 = {
630    { nir_search_value_expression, 32 },
631    false, false,
632    -1, 0,
633    nir_op_ushr,
634    { &replace9_0_0.value, &search4_1.value },
635    NULL,
636 };
637 static const nir_search_expression replace11 = {
638    { nir_search_value_expression, 16 },
639    false, false,
640    -1, 0,
641    nir_op_u2u16,
642    { &replace11_0.value },
643    NULL,
644 };
645 
646    static const nir_search_variable search12_0 = {
647    { nir_search_value_variable, 8 },
648    0, /* a */
649    false,
650    nir_type_invalid,
651    NULL,
652    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
653 };
654 
655 /* search12_1 -> search4_1 in the cache */
656 static const nir_search_expression search12 = {
657    { nir_search_value_expression, 8 },
658    false, false,
659    -1, 0,
660    nir_op_ishl,
661    { &search12_0.value, &search4_1.value },
662    NULL,
663 };
664 
665    /* replace12_0_0_0_0_0 -> search12_0 in the cache */
666 static const nir_search_expression replace12_0_0_0_0 = {
667    { nir_search_value_expression, 16 },
668    false, false,
669    -1, 0,
670    nir_op_u2u16,
671    { &search12_0.value },
672    NULL,
673 };
674 static const nir_search_expression replace12_0_0_0 = {
675    { nir_search_value_expression, 32 },
676    false, false,
677    -1, 0,
678    nir_op_u2u32,
679    { &replace12_0_0_0_0.value },
680    NULL,
681 };
682 
683 /* replace12_0_0_1 -> search4_1 in the cache */
684 static const nir_search_expression replace12_0_0 = {
685    { nir_search_value_expression, 32 },
686    false, false,
687    -1, 0,
688    nir_op_ishl,
689    { &replace12_0_0_0.value, &search4_1.value },
690    NULL,
691 };
692 static const nir_search_expression replace12_0 = {
693    { nir_search_value_expression, 16 },
694    false, false,
695    -1, 0,
696    nir_op_u2u16,
697    { &replace12_0_0.value },
698    NULL,
699 };
700 static const nir_search_expression replace12 = {
701    { nir_search_value_expression, 8 },
702    false, false,
703    -1, 0,
704    nir_op_u2u8,
705    { &replace12_0.value },
706    NULL,
707 };
708 
709    /* search13_0 -> search12_0 in the cache */
710 
711 /* search13_1 -> search4_1 in the cache */
712 static const nir_search_expression search13 = {
713    { nir_search_value_expression, 8 },
714    false, false,
715    -1, 0,
716    nir_op_ishr,
717    { &search12_0.value, &search4_1.value },
718    NULL,
719 };
720 
721    /* replace13_0_0_0_0_0 -> search12_0 in the cache */
722 static const nir_search_expression replace13_0_0_0_0 = {
723    { nir_search_value_expression, 16 },
724    false, false,
725    -1, 0,
726    nir_op_i2i16,
727    { &search12_0.value },
728    NULL,
729 };
730 static const nir_search_expression replace13_0_0_0 = {
731    { nir_search_value_expression, 32 },
732    false, false,
733    -1, 0,
734    nir_op_i2i32,
735    { &replace13_0_0_0_0.value },
736    NULL,
737 };
738 
739 /* replace13_0_0_1 -> search4_1 in the cache */
740 static const nir_search_expression replace13_0_0 = {
741    { nir_search_value_expression, 32 },
742    false, false,
743    -1, 0,
744    nir_op_ishr,
745    { &replace13_0_0_0.value, &search4_1.value },
746    NULL,
747 };
748 static const nir_search_expression replace13_0 = {
749    { nir_search_value_expression, 16 },
750    false, false,
751    -1, 0,
752    nir_op_i2i16,
753    { &replace13_0_0.value },
754    NULL,
755 };
756 static const nir_search_expression replace13 = {
757    { nir_search_value_expression, 8 },
758    false, false,
759    -1, 0,
760    nir_op_i2i8,
761    { &replace13_0.value },
762    NULL,
763 };
764 
765    /* search14_0 -> search12_0 in the cache */
766 
767 /* search14_1 -> search4_1 in the cache */
768 static const nir_search_expression search14 = {
769    { nir_search_value_expression, 8 },
770    false, false,
771    -1, 0,
772    nir_op_ushr,
773    { &search12_0.value, &search4_1.value },
774    NULL,
775 };
776 
777    /* replace14_0_0_0_0_0 -> search12_0 in the cache */
778 /* replace14_0_0_0_0 -> replace12_0_0_0_0 in the cache */
779 /* replace14_0_0_0 -> replace12_0_0_0 in the cache */
780 
781 /* replace14_0_0_1 -> search4_1 in the cache */
782 static const nir_search_expression replace14_0_0 = {
783    { nir_search_value_expression, 32 },
784    false, false,
785    -1, 0,
786    nir_op_ushr,
787    { &replace12_0_0_0.value, &search4_1.value },
788    NULL,
789 };
790 static const nir_search_expression replace14_0 = {
791    { nir_search_value_expression, 16 },
792    false, false,
793    -1, 0,
794    nir_op_u2u16,
795    { &replace14_0_0.value },
796    NULL,
797 };
798 static const nir_search_expression replace14 = {
799    { nir_search_value_expression, 8 },
800    false, false,
801    -1, 0,
802    nir_op_u2u8,
803    { &replace14_0.value },
804    NULL,
805 };
806 
807    /* search15_0 -> search2_0 in the cache */
808 
809 static const nir_search_constant search15_1 = {
810    { nir_search_value_constant, -1 },
811    nir_type_float, { 0x4000000000000000 /* 2.0 */ },
812 };
813 static const nir_search_expression search15 = {
814    { nir_search_value_expression, -1 },
815    false, false,
816    0, 1,
817    nir_op_fmul,
818    { &search2_0.value, &search15_1.value },
819    NULL,
820 };
821 
822    /* replace15_0 -> search2_0 in the cache */
823 
824 /* replace15_1 -> search2_0 in the cache */
825 static const nir_search_expression replace15 = {
826    { nir_search_value_expression, -1 },
827    false, false,
828    -1, 0,
829    nir_op_fadd,
830    { &search2_0.value, &search2_0.value },
831    NULL,
832 };
833 
834    /* search16_0 -> search4_0 in the cache */
835 static const nir_search_expression search16 = {
836    { nir_search_value_expression, 8 },
837    false, false,
838    -1, 0,
839    nir_op_u2u8,
840    { &search4_0.value },
841    NULL,
842 };
843 
844    /* replace16_0_0 -> search4_0 in the cache */
845 static const nir_search_expression replace16_0 = {
846    { nir_search_value_expression, 16 },
847    false, false,
848    -1, 0,
849    nir_op_u2u16,
850    { &search4_0.value },
851    NULL,
852 };
853 static const nir_search_expression replace16 = {
854    { nir_search_value_expression, 8 },
855    false, false,
856    -1, 0,
857    nir_op_u2u8,
858    { &replace16_0.value },
859    NULL,
860 };
861 
862    static const nir_search_variable search17_0 = {
863    { nir_search_value_variable, 64 },
864    0, /* a */
865    false,
866    nir_type_invalid,
867    NULL,
868    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
869 };
870 static const nir_search_expression search17 = {
871    { nir_search_value_expression, 8 },
872    false, false,
873    -1, 0,
874    nir_op_u2u8,
875    { &search17_0.value },
876    NULL,
877 };
878 
879    /* replace17_0_0_0 -> search17_0 in the cache */
880 static const nir_search_expression replace17_0_0 = {
881    { nir_search_value_expression, 32 },
882    false, false,
883    -1, 0,
884    nir_op_u2u32,
885    { &search17_0.value },
886    NULL,
887 };
888 static const nir_search_expression replace17_0 = {
889    { nir_search_value_expression, 16 },
890    false, false,
891    -1, 0,
892    nir_op_u2u16,
893    { &replace17_0_0.value },
894    NULL,
895 };
896 static const nir_search_expression replace17 = {
897    { nir_search_value_expression, 8 },
898    false, false,
899    -1, 0,
900    nir_op_u2u8,
901    { &replace17_0.value },
902    NULL,
903 };
904 
905    /* search18_0 -> search17_0 in the cache */
906 static const nir_search_expression search18 = {
907    { nir_search_value_expression, 16 },
908    false, false,
909    -1, 0,
910    nir_op_u2u16,
911    { &search17_0.value },
912    NULL,
913 };
914 
915    /* replace18_0_0 -> search17_0 in the cache */
916 /* replace18_0 -> replace17_0_0 in the cache */
917 /* replace18 -> replace17_0 in the cache */
918 
919    /* search19_0 -> search12_0 in the cache */
920 static const nir_search_expression search19 = {
921    { nir_search_value_expression, 32 },
922    false, false,
923    -1, 0,
924    nir_op_u2u32,
925    { &search12_0.value },
926    NULL,
927 };
928 
929    /* replace19_0_0 -> search12_0 in the cache */
930 /* replace19_0 -> replace12_0_0_0_0 in the cache */
931 /* replace19 -> replace12_0_0_0 in the cache */
932 
933    /* search20_0 -> search12_0 in the cache */
934 static const nir_search_expression search20 = {
935    { nir_search_value_expression, 64 },
936    false, false,
937    -1, 0,
938    nir_op_u2u64,
939    { &search12_0.value },
940    NULL,
941 };
942 
943    /* replace20_0_0_0 -> search12_0 in the cache */
944 /* replace20_0_0 -> replace12_0_0_0_0 in the cache */
945 /* replace20_0 -> replace12_0_0_0 in the cache */
946 static const nir_search_expression replace20 = {
947    { nir_search_value_expression, 64 },
948    false, false,
949    -1, 0,
950    nir_op_u2u64,
951    { &replace12_0_0_0.value },
952    NULL,
953 };
954 
955    /* search21_0 -> search9_0 in the cache */
956 static const nir_search_expression search21 = {
957    { nir_search_value_expression, 64 },
958    false, false,
959    -1, 0,
960    nir_op_u2u64,
961    { &search9_0.value },
962    NULL,
963 };
964 
965    /* replace21_0_0 -> search9_0 in the cache */
966 /* replace21_0 -> replace9_0_0 in the cache */
967 static const nir_search_expression replace21 = {
968    { nir_search_value_expression, 64 },
969    false, false,
970    -1, 0,
971    nir_op_u2u64,
972    { &replace9_0_0.value },
973    NULL,
974 };
975 
976    /* search22_0 -> search4_0 in the cache */
977 static const nir_search_expression search22 = {
978    { nir_search_value_expression, 8 },
979    false, false,
980    -1, 0,
981    nir_op_i2i8,
982    { &search4_0.value },
983    NULL,
984 };
985 
986    /* replace22_0_0 -> search4_0 in the cache */
987 static const nir_search_expression replace22_0 = {
988    { nir_search_value_expression, 16 },
989    false, false,
990    -1, 0,
991    nir_op_i2i16,
992    { &search4_0.value },
993    NULL,
994 };
995 static const nir_search_expression replace22 = {
996    { nir_search_value_expression, 8 },
997    false, false,
998    -1, 0,
999    nir_op_i2i8,
1000    { &replace22_0.value },
1001    NULL,
1002 };
1003 
1004    /* search23_0 -> search17_0 in the cache */
1005 static const nir_search_expression search23 = {
1006    { nir_search_value_expression, 8 },
1007    false, false,
1008    -1, 0,
1009    nir_op_i2i8,
1010    { &search17_0.value },
1011    NULL,
1012 };
1013 
1014    /* replace23_0_0_0 -> search17_0 in the cache */
1015 static const nir_search_expression replace23_0_0 = {
1016    { nir_search_value_expression, 32 },
1017    false, false,
1018    -1, 0,
1019    nir_op_i2i32,
1020    { &search17_0.value },
1021    NULL,
1022 };
1023 static const nir_search_expression replace23_0 = {
1024    { nir_search_value_expression, 16 },
1025    false, false,
1026    -1, 0,
1027    nir_op_i2i16,
1028    { &replace23_0_0.value },
1029    NULL,
1030 };
1031 static const nir_search_expression replace23 = {
1032    { nir_search_value_expression, 8 },
1033    false, false,
1034    -1, 0,
1035    nir_op_i2i8,
1036    { &replace23_0.value },
1037    NULL,
1038 };
1039 
1040    /* search24_0 -> search17_0 in the cache */
1041 static const nir_search_expression search24 = {
1042    { nir_search_value_expression, 16 },
1043    false, false,
1044    -1, 0,
1045    nir_op_i2i16,
1046    { &search17_0.value },
1047    NULL,
1048 };
1049 
1050    /* replace24_0_0 -> search17_0 in the cache */
1051 /* replace24_0 -> replace23_0_0 in the cache */
1052 /* replace24 -> replace23_0 in the cache */
1053 
1054    /* search25_0 -> search12_0 in the cache */
1055 static const nir_search_expression search25 = {
1056    { nir_search_value_expression, 32 },
1057    false, false,
1058    -1, 0,
1059    nir_op_i2i32,
1060    { &search12_0.value },
1061    NULL,
1062 };
1063 
1064    /* replace25_0_0 -> search12_0 in the cache */
1065 /* replace25_0 -> replace13_0_0_0_0 in the cache */
1066 /* replace25 -> replace13_0_0_0 in the cache */
1067 
1068    /* search26_0 -> search12_0 in the cache */
1069 static const nir_search_expression search26 = {
1070    { nir_search_value_expression, 64 },
1071    false, false,
1072    -1, 0,
1073    nir_op_i2i64,
1074    { &search12_0.value },
1075    NULL,
1076 };
1077 
1078    /* replace26_0_0_0 -> search12_0 in the cache */
1079 /* replace26_0_0 -> replace13_0_0_0_0 in the cache */
1080 /* replace26_0 -> replace13_0_0_0 in the cache */
1081 static const nir_search_expression replace26 = {
1082    { nir_search_value_expression, 64 },
1083    false, false,
1084    -1, 0,
1085    nir_op_i2i64,
1086    { &replace13_0_0_0.value },
1087    NULL,
1088 };
1089 
1090    /* search27_0 -> search9_0 in the cache */
1091 static const nir_search_expression search27 = {
1092    { nir_search_value_expression, 64 },
1093    false, false,
1094    -1, 0,
1095    nir_op_i2i64,
1096    { &search9_0.value },
1097    NULL,
1098 };
1099 
1100    /* replace27_0_0 -> search9_0 in the cache */
1101 /* replace27_0 -> replace10_0_0 in the cache */
1102 static const nir_search_expression replace27 = {
1103    { nir_search_value_expression, 64 },
1104    false, false,
1105    -1, 0,
1106    nir_op_i2i64,
1107    { &replace10_0_0.value },
1108    NULL,
1109 };
1110 
1111    /* search28_0 -> search17_0 in the cache */
1112 static const nir_search_expression search28 = {
1113    { nir_search_value_expression, 16 },
1114    false, false,
1115    -1, 0,
1116    nir_op_f2f16,
1117    { &search17_0.value },
1118    NULL,
1119 };
1120 
1121    /* replace28_0_0 -> search17_0 in the cache */
1122 static const nir_search_expression replace28_0 = {
1123    { nir_search_value_expression, 32 },
1124    false, false,
1125    -1, 0,
1126    nir_op_f2f32,
1127    { &search17_0.value },
1128    NULL,
1129 };
1130 static const nir_search_expression replace28 = {
1131    { nir_search_value_expression, 16 },
1132    false, false,
1133    -1, 0,
1134    nir_op_f2f16,
1135    { &replace28_0.value },
1136    NULL,
1137 };
1138 
1139    /* search29_0 -> search9_0 in the cache */
1140 static const nir_search_expression search29 = {
1141    { nir_search_value_expression, 64 },
1142    false, false,
1143    -1, 0,
1144    nir_op_f2f64,
1145    { &search9_0.value },
1146    NULL,
1147 };
1148 
1149    /* replace29_0_0 -> search9_0 in the cache */
1150 static const nir_search_expression replace29_0 = {
1151    { nir_search_value_expression, 32 },
1152    false, false,
1153    -1, 0,
1154    nir_op_f2f32,
1155    { &search9_0.value },
1156    NULL,
1157 };
1158 static const nir_search_expression replace29 = {
1159    { nir_search_value_expression, 64 },
1160    false, false,
1161    -1, 0,
1162    nir_op_f2f64,
1163    { &replace29_0.value },
1164    NULL,
1165 };
1166 
1167    /* search30_0 -> search17_0 in the cache */
1168 static const nir_search_expression search30 = {
1169    { nir_search_value_expression, 16 },
1170    false, false,
1171    -1, 0,
1172    nir_op_i2f16,
1173    { &search17_0.value },
1174    NULL,
1175 };
1176 
1177    /* replace30_0_0_0 -> search17_0 in the cache */
1178 static const nir_search_expression replace30_0_0 = {
1179    { nir_search_value_expression, 64 },
1180    false, false,
1181    -1, 0,
1182    nir_op_i2f64,
1183    { &search17_0.value },
1184    NULL,
1185 };
1186 static const nir_search_expression replace30_0 = {
1187    { nir_search_value_expression, 32 },
1188    false, false,
1189    -1, 0,
1190    nir_op_f2f32,
1191    { &replace30_0_0.value },
1192    NULL,
1193 };
1194 static const nir_search_expression replace30 = {
1195    { nir_search_value_expression, 16 },
1196    false, false,
1197    -1, 0,
1198    nir_op_f2f16,
1199    { &replace30_0.value },
1200    NULL,
1201 };
1202 
1203    /* search31_0 -> search12_0 in the cache */
1204 static const nir_search_expression search31 = {
1205    { nir_search_value_expression, 32 },
1206    false, false,
1207    -1, 0,
1208    nir_op_i2f32,
1209    { &search12_0.value },
1210    NULL,
1211 };
1212 
1213    /* replace31_0_0_0 -> search12_0 in the cache */
1214 /* replace31_0_0 -> replace13_0_0_0_0 in the cache */
1215 /* replace31_0 -> replace13_0_0_0 in the cache */
1216 static const nir_search_expression replace31 = {
1217    { nir_search_value_expression, 32 },
1218    false, false,
1219    -1, 0,
1220    nir_op_i2f32,
1221    { &replace13_0_0_0.value },
1222    NULL,
1223 };
1224 
1225    /* search32_0 -> search12_0 in the cache */
1226 static const nir_search_expression search32 = {
1227    { nir_search_value_expression, 64 },
1228    false, false,
1229    -1, 0,
1230    nir_op_i2f64,
1231    { &search12_0.value },
1232    NULL,
1233 };
1234 
1235    /* replace32_0_0_0_0 -> search12_0 in the cache */
1236 /* replace32_0_0_0 -> replace13_0_0_0_0 in the cache */
1237 /* replace32_0_0 -> replace13_0_0_0 in the cache */
1238 /* replace32_0 -> replace26 in the cache */
1239 static const nir_search_expression replace32 = {
1240    { nir_search_value_expression, 64 },
1241    false, false,
1242    -1, 0,
1243    nir_op_i2f64,
1244    { &replace26.value },
1245    NULL,
1246 };
1247 
1248    /* search33_0 -> search9_0 in the cache */
1249 static const nir_search_expression search33 = {
1250    { nir_search_value_expression, 64 },
1251    false, false,
1252    -1, 0,
1253    nir_op_i2f64,
1254    { &search9_0.value },
1255    NULL,
1256 };
1257 
1258    /* replace33_0_0_0 -> search9_0 in the cache */
1259 /* replace33_0_0 -> replace10_0_0 in the cache */
1260 /* replace33_0 -> replace27 in the cache */
1261 static const nir_search_expression replace33 = {
1262    { nir_search_value_expression, 64 },
1263    false, false,
1264    -1, 0,
1265    nir_op_i2f64,
1266    { &replace27.value },
1267    NULL,
1268 };
1269 
1270    /* search34_0 -> search17_0 in the cache */
1271 static const nir_search_expression search34 = {
1272    { nir_search_value_expression, 16 },
1273    false, false,
1274    -1, 0,
1275    nir_op_u2f16,
1276    { &search17_0.value },
1277    NULL,
1278 };
1279 
1280    /* replace34_0_0_0 -> search17_0 in the cache */
1281 static const nir_search_expression replace34_0_0 = {
1282    { nir_search_value_expression, 64 },
1283    false, false,
1284    -1, 0,
1285    nir_op_u2f64,
1286    { &search17_0.value },
1287    NULL,
1288 };
1289 static const nir_search_expression replace34_0 = {
1290    { nir_search_value_expression, 32 },
1291    false, false,
1292    -1, 0,
1293    nir_op_f2f32,
1294    { &replace34_0_0.value },
1295    NULL,
1296 };
1297 static const nir_search_expression replace34 = {
1298    { nir_search_value_expression, 16 },
1299    false, false,
1300    -1, 0,
1301    nir_op_f2f16,
1302    { &replace34_0.value },
1303    NULL,
1304 };
1305 
1306    /* search35_0 -> search12_0 in the cache */
1307 static const nir_search_expression search35 = {
1308    { nir_search_value_expression, 32 },
1309    false, false,
1310    -1, 0,
1311    nir_op_u2f32,
1312    { &search12_0.value },
1313    NULL,
1314 };
1315 
1316    /* replace35_0_0_0 -> search12_0 in the cache */
1317 /* replace35_0_0 -> replace12_0_0_0_0 in the cache */
1318 /* replace35_0 -> replace12_0_0_0 in the cache */
1319 static const nir_search_expression replace35 = {
1320    { nir_search_value_expression, 32 },
1321    false, false,
1322    -1, 0,
1323    nir_op_u2f32,
1324    { &replace12_0_0_0.value },
1325    NULL,
1326 };
1327 
1328    /* search36_0 -> search12_0 in the cache */
1329 static const nir_search_expression search36 = {
1330    { nir_search_value_expression, 64 },
1331    false, false,
1332    -1, 0,
1333    nir_op_u2f64,
1334    { &search12_0.value },
1335    NULL,
1336 };
1337 
1338    /* replace36_0_0_0_0 -> search12_0 in the cache */
1339 /* replace36_0_0_0 -> replace12_0_0_0_0 in the cache */
1340 /* replace36_0_0 -> replace12_0_0_0 in the cache */
1341 /* replace36_0 -> replace20 in the cache */
1342 static const nir_search_expression replace36 = {
1343    { nir_search_value_expression, 64 },
1344    false, false,
1345    -1, 0,
1346    nir_op_u2f64,
1347    { &replace20.value },
1348    NULL,
1349 };
1350 
1351    /* search37_0 -> search9_0 in the cache */
1352 static const nir_search_expression search37 = {
1353    { nir_search_value_expression, 64 },
1354    false, false,
1355    -1, 0,
1356    nir_op_u2f64,
1357    { &search9_0.value },
1358    NULL,
1359 };
1360 
1361    /* replace37_0_0_0 -> search9_0 in the cache */
1362 /* replace37_0_0 -> replace9_0_0 in the cache */
1363 /* replace37_0 -> replace21 in the cache */
1364 static const nir_search_expression replace37 = {
1365    { nir_search_value_expression, 64 },
1366    false, false,
1367    -1, 0,
1368    nir_op_u2f64,
1369    { &replace21.value },
1370    NULL,
1371 };
1372 
1373    /* search38_0 -> search4_0 in the cache */
1374 static const nir_search_expression search38 = {
1375    { nir_search_value_expression, 8 },
1376    false, false,
1377    -1, 0,
1378    nir_op_f2i8,
1379    { &search4_0.value },
1380    NULL,
1381 };
1382 
1383    /* replace38_0_0_0 -> search4_0 in the cache */
1384 static const nir_search_expression replace38_0_0 = {
1385    { nir_search_value_expression, 32 },
1386    false, false,
1387    -1, 0,
1388    nir_op_f2i32,
1389    { &search4_0.value },
1390    NULL,
1391 };
1392 static const nir_search_expression replace38_0 = {
1393    { nir_search_value_expression, 16 },
1394    false, false,
1395    -1, 0,
1396    nir_op_i2i16,
1397    { &replace38_0_0.value },
1398    NULL,
1399 };
1400 static const nir_search_expression replace38 = {
1401    { nir_search_value_expression, 8 },
1402    false, false,
1403    -1, 0,
1404    nir_op_i2i8,
1405    { &replace38_0.value },
1406    NULL,
1407 };
1408 
1409    /* search39_0 -> search17_0 in the cache */
1410 static const nir_search_expression search39 = {
1411    { nir_search_value_expression, 8 },
1412    false, false,
1413    -1, 0,
1414    nir_op_f2i8,
1415    { &search17_0.value },
1416    NULL,
1417 };
1418 
1419    /* replace39_0_0_0_0 -> search17_0 in the cache */
1420 static const nir_search_expression replace39_0_0_0 = {
1421    { nir_search_value_expression, 64 },
1422    false, false,
1423    -1, 0,
1424    nir_op_f2i64,
1425    { &search17_0.value },
1426    NULL,
1427 };
1428 static const nir_search_expression replace39_0_0 = {
1429    { nir_search_value_expression, 32 },
1430    false, false,
1431    -1, 0,
1432    nir_op_i2i32,
1433    { &replace39_0_0_0.value },
1434    NULL,
1435 };
1436 static const nir_search_expression replace39_0 = {
1437    { nir_search_value_expression, 16 },
1438    false, false,
1439    -1, 0,
1440    nir_op_i2i16,
1441    { &replace39_0_0.value },
1442    NULL,
1443 };
1444 static const nir_search_expression replace39 = {
1445    { nir_search_value_expression, 8 },
1446    false, false,
1447    -1, 0,
1448    nir_op_i2i8,
1449    { &replace39_0.value },
1450    NULL,
1451 };
1452 
1453    /* search40_0 -> search17_0 in the cache */
1454 static const nir_search_expression search40 = {
1455    { nir_search_value_expression, 16 },
1456    false, false,
1457    -1, 0,
1458    nir_op_f2i16,
1459    { &search17_0.value },
1460    NULL,
1461 };
1462 
1463    /* replace40_0_0_0 -> search17_0 in the cache */
1464 /* replace40_0_0 -> replace39_0_0_0 in the cache */
1465 /* replace40_0 -> replace39_0_0 in the cache */
1466 /* replace40 -> replace39_0 in the cache */
1467 
1468    /* search41_0 -> search9_0 in the cache */
1469 static const nir_search_expression search41 = {
1470    { nir_search_value_expression, 64 },
1471    false, false,
1472    -1, 0,
1473    nir_op_f2i64,
1474    { &search9_0.value },
1475    NULL,
1476 };
1477 
1478    /* replace41_0_0_0 -> search9_0 in the cache */
1479 /* replace41_0_0 -> replace29_0 in the cache */
1480 /* replace41_0 -> replace29 in the cache */
1481 static const nir_search_expression replace41 = {
1482    { nir_search_value_expression, 64 },
1483    false, false,
1484    -1, 0,
1485    nir_op_f2i64,
1486    { &replace29.value },
1487    NULL,
1488 };
1489 
1490    /* search42_0 -> search4_0 in the cache */
1491 static const nir_search_expression search42 = {
1492    { nir_search_value_expression, 8 },
1493    false, false,
1494    -1, 0,
1495    nir_op_f2u8,
1496    { &search4_0.value },
1497    NULL,
1498 };
1499 
1500    /* replace42_0_0_0 -> search4_0 in the cache */
1501 static const nir_search_expression replace42_0_0 = {
1502    { nir_search_value_expression, 32 },
1503    false, false,
1504    -1, 0,
1505    nir_op_f2u32,
1506    { &search4_0.value },
1507    NULL,
1508 };
1509 static const nir_search_expression replace42_0 = {
1510    { nir_search_value_expression, 16 },
1511    false, false,
1512    -1, 0,
1513    nir_op_u2u16,
1514    { &replace42_0_0.value },
1515    NULL,
1516 };
1517 static const nir_search_expression replace42 = {
1518    { nir_search_value_expression, 8 },
1519    false, false,
1520    -1, 0,
1521    nir_op_u2u8,
1522    { &replace42_0.value },
1523    NULL,
1524 };
1525 
1526    /* search43_0 -> search17_0 in the cache */
1527 static const nir_search_expression search43 = {
1528    { nir_search_value_expression, 8 },
1529    false, false,
1530    -1, 0,
1531    nir_op_f2u8,
1532    { &search17_0.value },
1533    NULL,
1534 };
1535 
1536    /* replace43_0_0_0_0 -> search17_0 in the cache */
1537 static const nir_search_expression replace43_0_0_0 = {
1538    { nir_search_value_expression, 64 },
1539    false, false,
1540    -1, 0,
1541    nir_op_f2u64,
1542    { &search17_0.value },
1543    NULL,
1544 };
1545 static const nir_search_expression replace43_0_0 = {
1546    { nir_search_value_expression, 32 },
1547    false, false,
1548    -1, 0,
1549    nir_op_u2u32,
1550    { &replace43_0_0_0.value },
1551    NULL,
1552 };
1553 static const nir_search_expression replace43_0 = {
1554    { nir_search_value_expression, 16 },
1555    false, false,
1556    -1, 0,
1557    nir_op_u2u16,
1558    { &replace43_0_0.value },
1559    NULL,
1560 };
1561 static const nir_search_expression replace43 = {
1562    { nir_search_value_expression, 8 },
1563    false, false,
1564    -1, 0,
1565    nir_op_u2u8,
1566    { &replace43_0.value },
1567    NULL,
1568 };
1569 
1570    /* search44_0 -> search17_0 in the cache */
1571 static const nir_search_expression search44 = {
1572    { nir_search_value_expression, 16 },
1573    false, false,
1574    -1, 0,
1575    nir_op_f2u16,
1576    { &search17_0.value },
1577    NULL,
1578 };
1579 
1580    /* replace44_0_0_0 -> search17_0 in the cache */
1581 /* replace44_0_0 -> replace43_0_0_0 in the cache */
1582 /* replace44_0 -> replace43_0_0 in the cache */
1583 /* replace44 -> replace43_0 in the cache */
1584 
1585    /* search45_0 -> search9_0 in the cache */
1586 static const nir_search_expression search45 = {
1587    { nir_search_value_expression, 64 },
1588    false, false,
1589    -1, 0,
1590    nir_op_f2u64,
1591    { &search9_0.value },
1592    NULL,
1593 };
1594 
1595    /* replace45_0_0_0 -> search9_0 in the cache */
1596 /* replace45_0_0 -> replace29_0 in the cache */
1597 /* replace45_0 -> replace29 in the cache */
1598 static const nir_search_expression replace45 = {
1599    { nir_search_value_expression, 64 },
1600    false, false,
1601    -1, 0,
1602    nir_op_f2u64,
1603    { &replace29.value },
1604    NULL,
1605 };
1606 
1607    /* search46_0 -> search3_0 in the cache */
1608 
1609 static const nir_search_variable search46_1 = {
1610    { nir_search_value_variable, -2 },
1611    1, /* b */
1612    true,
1613    nir_type_invalid,
1614    NULL,
1615    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
1616 };
1617 static const nir_search_expression search46 = {
1618    { nir_search_value_expression, 1 },
1619    false, false,
1620    -1, 0,
1621    nir_op_fge,
1622    { &search3_0.value, &search46_1.value },
1623    NULL,
1624 };
1625 
1626    /* replace46_0_0 -> search3_0 in the cache */
1627 
1628 /* replace46_0_1 -> search3_1 in the cache */
1629 static const nir_search_expression replace46_0 = {
1630    { nir_search_value_expression, 1 },
1631    false, false,
1632    -1, 0,
1633    nir_op_flt,
1634    { &search3_0.value, &search3_1.value },
1635    NULL,
1636 };
1637 static const nir_search_expression replace46 = {
1638    { nir_search_value_expression, 1 },
1639    false, false,
1640    -1, 0,
1641    nir_op_inot,
1642    { &replace46_0.value },
1643    NULL,
1644 };
1645 
1646    /* search47_0 -> search3_0 in the cache */
1647 
1648 /* search47_1 -> search46_1 in the cache */
1649 static const nir_search_expression search47 = {
1650    { nir_search_value_expression, 32 },
1651    false, false,
1652    -1, 0,
1653    nir_op_fge32,
1654    { &search3_0.value, &search46_1.value },
1655    NULL,
1656 };
1657 
1658    /* replace47_0_0 -> search3_0 in the cache */
1659 
1660 /* replace47_0_1 -> search3_1 in the cache */
1661 static const nir_search_expression replace47_0 = {
1662    { nir_search_value_expression, 32 },
1663    false, false,
1664    -1, 0,
1665    nir_op_flt32,
1666    { &search3_0.value, &search3_1.value },
1667    NULL,
1668 };
1669 static const nir_search_expression replace47 = {
1670    { nir_search_value_expression, 32 },
1671    false, false,
1672    -1, 0,
1673    nir_op_inot,
1674    { &replace47_0.value },
1675    NULL,
1676 };
1677 
1678    /* search48_0 -> search3_0 in the cache */
1679 
1680 /* search48_1 -> search46_1 in the cache */
1681 static const nir_search_expression search48 = {
1682    { nir_search_value_expression, 32 },
1683    false, false,
1684    -1, 0,
1685    nir_op_ige32,
1686    { &search3_0.value, &search46_1.value },
1687    NULL,
1688 };
1689 
1690    /* replace48_0_0 -> search3_0 in the cache */
1691 
1692 /* replace48_0_1 -> search3_1 in the cache */
1693 static const nir_search_expression replace48_0 = {
1694    { nir_search_value_expression, 32 },
1695    false, false,
1696    -1, 0,
1697    nir_op_ilt32,
1698    { &search3_0.value, &search3_1.value },
1699    NULL,
1700 };
1701 static const nir_search_expression replace48 = {
1702    { nir_search_value_expression, 32 },
1703    false, false,
1704    -1, 0,
1705    nir_op_inot,
1706    { &replace48_0.value },
1707    NULL,
1708 };
1709 
1710    /* search49_0 -> search3_0 in the cache */
1711 
1712 /* search49_1 -> search46_1 in the cache */
1713 static const nir_search_expression search49 = {
1714    { nir_search_value_expression, 32 },
1715    false, false,
1716    -1, 0,
1717    nir_op_uge32,
1718    { &search3_0.value, &search46_1.value },
1719    NULL,
1720 };
1721 
1722    /* replace49_0_0 -> search3_0 in the cache */
1723 
1724 /* replace49_0_1 -> search3_1 in the cache */
1725 static const nir_search_expression replace49_0 = {
1726    { nir_search_value_expression, 32 },
1727    false, false,
1728    -1, 0,
1729    nir_op_ult32,
1730    { &search3_0.value, &search3_1.value },
1731    NULL,
1732 };
1733 static const nir_search_expression replace49 = {
1734    { nir_search_value_expression, 32 },
1735    false, false,
1736    -1, 0,
1737    nir_op_inot,
1738    { &replace49_0.value },
1739    NULL,
1740 };
1741 
1742    static const nir_search_variable search50_0 = {
1743    { nir_search_value_variable, -2 },
1744    0, /* a */
1745    true,
1746    nir_type_invalid,
1747    NULL,
1748    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
1749 };
1750 
1751 /* search50_1 -> search3_1 in the cache */
1752 static const nir_search_expression search50 = {
1753    { nir_search_value_expression, 32 },
1754    false, false,
1755    -1, 0,
1756    nir_op_flt32,
1757    { &search50_0.value, &search3_1.value },
1758    NULL,
1759 };
1760 
1761    /* replace50_0_0 -> search3_0 in the cache */
1762 
1763 /* replace50_0_1 -> search3_1 in the cache */
1764 static const nir_search_expression replace50_0 = {
1765    { nir_search_value_expression, 32 },
1766    false, false,
1767    -1, 0,
1768    nir_op_fge32,
1769    { &search3_0.value, &search3_1.value },
1770    NULL,
1771 };
1772 static const nir_search_expression replace50 = {
1773    { nir_search_value_expression, 32 },
1774    false, false,
1775    -1, 0,
1776    nir_op_inot,
1777    { &replace50_0.value },
1778    NULL,
1779 };
1780 
1781    /* search51_0 -> search50_0 in the cache */
1782 
1783 /* search51_1 -> search3_1 in the cache */
1784 static const nir_search_expression search51 = {
1785    { nir_search_value_expression, 32 },
1786    false, false,
1787    -1, 0,
1788    nir_op_ilt32,
1789    { &search50_0.value, &search3_1.value },
1790    NULL,
1791 };
1792 
1793    /* replace51_0_0 -> search3_0 in the cache */
1794 
1795 /* replace51_0_1 -> search3_1 in the cache */
1796 static const nir_search_expression replace51_0 = {
1797    { nir_search_value_expression, 32 },
1798    false, false,
1799    -1, 0,
1800    nir_op_ige32,
1801    { &search3_0.value, &search3_1.value },
1802    NULL,
1803 };
1804 static const nir_search_expression replace51 = {
1805    { nir_search_value_expression, 32 },
1806    false, false,
1807    -1, 0,
1808    nir_op_inot,
1809    { &replace51_0.value },
1810    NULL,
1811 };
1812 
1813    /* search52_0 -> search50_0 in the cache */
1814 
1815 /* search52_1 -> search3_1 in the cache */
1816 static const nir_search_expression search52 = {
1817    { nir_search_value_expression, 32 },
1818    false, false,
1819    -1, 0,
1820    nir_op_ult32,
1821    { &search50_0.value, &search3_1.value },
1822    NULL,
1823 };
1824 
1825    /* replace52_0_0 -> search3_0 in the cache */
1826 
1827 /* replace52_0_1 -> search3_1 in the cache */
1828 static const nir_search_expression replace52_0 = {
1829    { nir_search_value_expression, 32 },
1830    false, false,
1831    -1, 0,
1832    nir_op_uge32,
1833    { &search3_0.value, &search3_1.value },
1834    NULL,
1835 };
1836 static const nir_search_expression replace52 = {
1837    { nir_search_value_expression, 32 },
1838    false, false,
1839    -1, 0,
1840    nir_op_inot,
1841    { &replace52_0.value },
1842    NULL,
1843 };
1844 
1845 
1846 static const struct transform midgard_nir_lower_algebraic_late_state2_xforms[] = {
1847   { &search2, &replace2.value, 0 },
1848 };
1849 static const struct transform midgard_nir_lower_algebraic_late_state3_xforms[] = {
1850   { &search3, &replace3.value, 0 },
1851 };
1852 static const struct transform midgard_nir_lower_algebraic_late_state4_xforms[] = {
1853   { &search4, &replace4.value, 0 },
1854 };
1855 static const struct transform midgard_nir_lower_algebraic_late_state5_xforms[] = {
1856   { &search5, &replace5.value, 0 },
1857 };
1858 static const struct transform midgard_nir_lower_algebraic_late_state6_xforms[] = {
1859   { &search4, &replace4.value, 0 },
1860   { &search5, &replace5.value, 0 },
1861 };
1862 static const struct transform midgard_nir_lower_algebraic_late_state8_xforms[] = {
1863   { &search8, &replace8.value, 0 },
1864 };
1865 static const struct transform midgard_nir_lower_algebraic_late_state9_xforms[] = {
1866   { &search9, &replace9.value, 0 },
1867   { &search12, &replace12.value, 0 },
1868 };
1869 static const struct transform midgard_nir_lower_algebraic_late_state10_xforms[] = {
1870   { &search10, &replace10.value, 0 },
1871   { &search13, &replace13.value, 0 },
1872 };
1873 static const struct transform midgard_nir_lower_algebraic_late_state11_xforms[] = {
1874   { &search11, &replace11.value, 0 },
1875   { &search14, &replace14.value, 0 },
1876 };
1877 static const struct transform midgard_nir_lower_algebraic_late_state12_xforms[] = {
1878   { &search15, &replace15.value, 0 },
1879 };
1880 static const struct transform midgard_nir_lower_algebraic_late_state13_xforms[] = {
1881   { &search16, &replace16.value, 0 },
1882   { &search17, &replace17.value, 0 },
1883   { &search18, &replace17_0.value, 0 },
1884   { &search19, &replace12_0_0_0.value, 0 },
1885   { &search20, &replace20.value, 0 },
1886   { &search21, &replace21.value, 0 },
1887 };
1888 static const struct transform midgard_nir_lower_algebraic_late_state14_xforms[] = {
1889   { &search22, &replace22.value, 0 },
1890   { &search23, &replace23.value, 0 },
1891   { &search24, &replace23_0.value, 0 },
1892   { &search25, &replace13_0_0_0.value, 0 },
1893   { &search26, &replace26.value, 0 },
1894   { &search27, &replace27.value, 0 },
1895 };
1896 static const struct transform midgard_nir_lower_algebraic_late_state15_xforms[] = {
1897   { &search28, &replace28.value, 0 },
1898   { &search29, &replace29.value, 0 },
1899 };
1900 static const struct transform midgard_nir_lower_algebraic_late_state16_xforms[] = {
1901   { &search30, &replace30.value, 0 },
1902   { &search31, &replace31.value, 0 },
1903   { &search32, &replace32.value, 0 },
1904   { &search33, &replace33.value, 0 },
1905 };
1906 static const struct transform midgard_nir_lower_algebraic_late_state17_xforms[] = {
1907   { &search34, &replace34.value, 0 },
1908   { &search35, &replace35.value, 0 },
1909   { &search36, &replace36.value, 0 },
1910   { &search37, &replace37.value, 0 },
1911 };
1912 static const struct transform midgard_nir_lower_algebraic_late_state18_xforms[] = {
1913   { &search38, &replace38.value, 0 },
1914   { &search39, &replace39.value, 0 },
1915   { &search40, &replace39_0.value, 0 },
1916   { &search41, &replace41.value, 0 },
1917 };
1918 static const struct transform midgard_nir_lower_algebraic_late_state19_xforms[] = {
1919   { &search42, &replace42.value, 0 },
1920   { &search43, &replace43.value, 0 },
1921   { &search44, &replace43_0.value, 0 },
1922   { &search45, &replace45.value, 0 },
1923 };
1924 static const struct transform midgard_nir_lower_algebraic_late_state20_xforms[] = {
1925   { &search46, &replace46.value, 0 },
1926 };
1927 static const struct transform midgard_nir_lower_algebraic_late_state21_xforms[] = {
1928   { &search47, &replace47.value, 0 },
1929 };
1930 static const struct transform midgard_nir_lower_algebraic_late_state22_xforms[] = {
1931   { &search48, &replace48.value, 0 },
1932 };
1933 static const struct transform midgard_nir_lower_algebraic_late_state23_xforms[] = {
1934   { &search49, &replace49.value, 0 },
1935 };
1936 static const struct transform midgard_nir_lower_algebraic_late_state24_xforms[] = {
1937   { &search50, &replace50.value, 0 },
1938 };
1939 static const struct transform midgard_nir_lower_algebraic_late_state25_xforms[] = {
1940   { &search51, &replace51.value, 0 },
1941 };
1942 static const struct transform midgard_nir_lower_algebraic_late_state26_xforms[] = {
1943   { &search52, &replace52.value, 0 },
1944 };
1945 static const struct transform midgard_nir_lower_algebraic_late_state27_xforms[] = {
1946   { &search7, &replace6.value, 0 },
1947   { &search8, &replace8.value, 0 },
1948 };
1949 static const struct transform midgard_nir_lower_algebraic_late_state28_xforms[] = {
1950   { &search6, &replace6.value, 0 },
1951 };
1952 
1953 static const struct per_op_table midgard_nir_lower_algebraic_late_table[nir_num_search_ops] = {
1954    [nir_op_ineg] = {
1955       .filter = (uint16_t []) {
1956          0,
1957          0,
1958          0,
1959          0,
1960          0,
1961          0,
1962          0,
1963          0,
1964          0,
1965          0,
1966          0,
1967          0,
1968          0,
1969          0,
1970          0,
1971          0,
1972          0,
1973          0,
1974          0,
1975          0,
1976          0,
1977          0,
1978          0,
1979          0,
1980          0,
1981          0,
1982          0,
1983          0,
1984          0,
1985       },
1986 
1987       .num_filtered_states = 1,
1988       .table = (uint16_t []) {
1989 
1990          2,
1991       },
1992    },
1993    [nir_op_fsub] = {
1994       .filter = (uint16_t []) {
1995          0,
1996          0,
1997          0,
1998          0,
1999          0,
2000          0,
2001          0,
2002          0,
2003          0,
2004          0,
2005          0,
2006          0,
2007          0,
2008          0,
2009          0,
2010          0,
2011          0,
2012          0,
2013          0,
2014          0,
2015          0,
2016          0,
2017          0,
2018          0,
2019          0,
2020          0,
2021          0,
2022          0,
2023          0,
2024       },
2025 
2026       .num_filtered_states = 1,
2027       .table = (uint16_t []) {
2028 
2029          3,
2030       },
2031    },
2032    [nir_op_b32csel] = {
2033       .filter = (uint16_t []) {
2034          0,
2035          1,
2036          0,
2037          0,
2038          0,
2039          0,
2040          0,
2041          0,
2042          0,
2043          0,
2044          0,
2045          0,
2046          0,
2047          0,
2048          0,
2049          0,
2050          0,
2051          0,
2052          0,
2053          0,
2054          0,
2055          0,
2056          0,
2057          0,
2058          0,
2059          0,
2060          0,
2061          0,
2062          0,
2063       },
2064 
2065       .num_filtered_states = 2,
2066       .table = (uint16_t []) {
2067 
2068          0,
2069          4,
2070          5,
2071          6,
2072          0,
2073          4,
2074          5,
2075          6,
2076       },
2077    },
2078    [nir_op_fmin] = {
2079       .filter = (uint16_t []) {
2080          0,
2081          1,
2082          0,
2083          0,
2084          0,
2085          0,
2086          0,
2087          0,
2088          2,
2089          0,
2090          0,
2091          0,
2092          0,
2093          0,
2094          0,
2095          0,
2096          0,
2097          0,
2098          0,
2099          0,
2100          0,
2101          0,
2102          0,
2103          0,
2104          0,
2105          0,
2106          0,
2107          2,
2108          0,
2109       },
2110 
2111       .num_filtered_states = 3,
2112       .table = (uint16_t []) {
2113 
2114          0,
2115          7,
2116          0,
2117          7,
2118          7,
2119          28,
2120          0,
2121          28,
2122          0,
2123       },
2124    },
2125    [nir_op_fmax] = {
2126       .filter = (uint16_t []) {
2127          0,
2128          1,
2129          0,
2130          0,
2131          0,
2132          0,
2133          0,
2134          2,
2135          0,
2136          0,
2137          0,
2138          0,
2139          0,
2140          0,
2141          0,
2142          0,
2143          0,
2144          0,
2145          0,
2146          0,
2147          0,
2148          0,
2149          0,
2150          0,
2151          0,
2152          0,
2153          0,
2154          0,
2155          2,
2156       },
2157 
2158       .num_filtered_states = 3,
2159       .table = (uint16_t []) {
2160 
2161          0,
2162          8,
2163          0,
2164          8,
2165          8,
2166          27,
2167          0,
2168          27,
2169          0,
2170       },
2171    },
2172    [nir_op_ishl] = {
2173       .filter = (uint16_t []) {
2174          0,
2175          0,
2176          0,
2177          0,
2178          0,
2179          0,
2180          0,
2181          0,
2182          0,
2183          0,
2184          0,
2185          0,
2186          0,
2187          0,
2188          0,
2189          0,
2190          0,
2191          0,
2192          0,
2193          0,
2194          0,
2195          0,
2196          0,
2197          0,
2198          0,
2199          0,
2200          0,
2201          0,
2202          0,
2203       },
2204 
2205       .num_filtered_states = 1,
2206       .table = (uint16_t []) {
2207 
2208          9,
2209       },
2210    },
2211    [nir_op_ishr] = {
2212       .filter = (uint16_t []) {
2213          0,
2214          0,
2215          0,
2216          0,
2217          0,
2218          0,
2219          0,
2220          0,
2221          0,
2222          0,
2223          0,
2224          0,
2225          0,
2226          0,
2227          0,
2228          0,
2229          0,
2230          0,
2231          0,
2232          0,
2233          0,
2234          0,
2235          0,
2236          0,
2237          0,
2238          0,
2239          0,
2240          0,
2241          0,
2242       },
2243 
2244       .num_filtered_states = 1,
2245       .table = (uint16_t []) {
2246 
2247          10,
2248       },
2249    },
2250    [nir_op_ushr] = {
2251       .filter = (uint16_t []) {
2252          0,
2253          0,
2254          0,
2255          0,
2256          0,
2257          0,
2258          0,
2259          0,
2260          0,
2261          0,
2262          0,
2263          0,
2264          0,
2265          0,
2266          0,
2267          0,
2268          0,
2269          0,
2270          0,
2271          0,
2272          0,
2273          0,
2274          0,
2275          0,
2276          0,
2277          0,
2278          0,
2279          0,
2280          0,
2281       },
2282 
2283       .num_filtered_states = 1,
2284       .table = (uint16_t []) {
2285 
2286          11,
2287       },
2288    },
2289    [nir_op_fmul] = {
2290       .filter = (uint16_t []) {
2291          0,
2292          1,
2293          0,
2294          0,
2295          0,
2296          0,
2297          0,
2298          0,
2299          0,
2300          0,
2301          0,
2302          0,
2303          0,
2304          0,
2305          0,
2306          0,
2307          0,
2308          0,
2309          0,
2310          0,
2311          0,
2312          0,
2313          0,
2314          0,
2315          0,
2316          0,
2317          0,
2318          0,
2319          0,
2320       },
2321 
2322       .num_filtered_states = 2,
2323       .table = (uint16_t []) {
2324 
2325          0,
2326          12,
2327          12,
2328          12,
2329       },
2330    },
2331    [nir_search_op_u2u] = {
2332       .filter = (uint16_t []) {
2333          0,
2334          0,
2335          0,
2336          0,
2337          0,
2338          0,
2339          0,
2340          0,
2341          0,
2342          0,
2343          0,
2344          0,
2345          0,
2346          0,
2347          0,
2348          0,
2349          0,
2350          0,
2351          0,
2352          0,
2353          0,
2354          0,
2355          0,
2356          0,
2357          0,
2358          0,
2359          0,
2360          0,
2361          0,
2362       },
2363 
2364       .num_filtered_states = 1,
2365       .table = (uint16_t []) {
2366 
2367          13,
2368       },
2369    },
2370    [nir_search_op_i2i] = {
2371       .filter = (uint16_t []) {
2372          0,
2373          0,
2374          0,
2375          0,
2376          0,
2377          0,
2378          0,
2379          0,
2380          0,
2381          0,
2382          0,
2383          0,
2384          0,
2385          0,
2386          0,
2387          0,
2388          0,
2389          0,
2390          0,
2391          0,
2392          0,
2393          0,
2394          0,
2395          0,
2396          0,
2397          0,
2398          0,
2399          0,
2400          0,
2401       },
2402 
2403       .num_filtered_states = 1,
2404       .table = (uint16_t []) {
2405 
2406          14,
2407       },
2408    },
2409    [nir_search_op_f2f] = {
2410       .filter = (uint16_t []) {
2411          0,
2412          0,
2413          0,
2414          0,
2415          0,
2416          0,
2417          0,
2418          0,
2419          0,
2420          0,
2421          0,
2422          0,
2423          0,
2424          0,
2425          0,
2426          0,
2427          0,
2428          0,
2429          0,
2430          0,
2431          0,
2432          0,
2433          0,
2434          0,
2435          0,
2436          0,
2437          0,
2438          0,
2439          0,
2440       },
2441 
2442       .num_filtered_states = 1,
2443       .table = (uint16_t []) {
2444 
2445          15,
2446       },
2447    },
2448    [nir_search_op_i2f] = {
2449       .filter = (uint16_t []) {
2450          0,
2451          0,
2452          0,
2453          0,
2454          0,
2455          0,
2456          0,
2457          0,
2458          0,
2459          0,
2460          0,
2461          0,
2462          0,
2463          0,
2464          0,
2465          0,
2466          0,
2467          0,
2468          0,
2469          0,
2470          0,
2471          0,
2472          0,
2473          0,
2474          0,
2475          0,
2476          0,
2477          0,
2478          0,
2479       },
2480 
2481       .num_filtered_states = 1,
2482       .table = (uint16_t []) {
2483 
2484          16,
2485       },
2486    },
2487    [nir_search_op_u2f] = {
2488       .filter = (uint16_t []) {
2489          0,
2490          0,
2491          0,
2492          0,
2493          0,
2494          0,
2495          0,
2496          0,
2497          0,
2498          0,
2499          0,
2500          0,
2501          0,
2502          0,
2503          0,
2504          0,
2505          0,
2506          0,
2507          0,
2508          0,
2509          0,
2510          0,
2511          0,
2512          0,
2513          0,
2514          0,
2515          0,
2516          0,
2517          0,
2518       },
2519 
2520       .num_filtered_states = 1,
2521       .table = (uint16_t []) {
2522 
2523          17,
2524       },
2525    },
2526    [nir_search_op_f2i] = {
2527       .filter = (uint16_t []) {
2528          0,
2529          0,
2530          0,
2531          0,
2532          0,
2533          0,
2534          0,
2535          0,
2536          0,
2537          0,
2538          0,
2539          0,
2540          0,
2541          0,
2542          0,
2543          0,
2544          0,
2545          0,
2546          0,
2547          0,
2548          0,
2549          0,
2550          0,
2551          0,
2552          0,
2553          0,
2554          0,
2555          0,
2556          0,
2557       },
2558 
2559       .num_filtered_states = 1,
2560       .table = (uint16_t []) {
2561 
2562          18,
2563       },
2564    },
2565    [nir_search_op_f2u] = {
2566       .filter = (uint16_t []) {
2567          0,
2568          0,
2569          0,
2570          0,
2571          0,
2572          0,
2573          0,
2574          0,
2575          0,
2576          0,
2577          0,
2578          0,
2579          0,
2580          0,
2581          0,
2582          0,
2583          0,
2584          0,
2585          0,
2586          0,
2587          0,
2588          0,
2589          0,
2590          0,
2591          0,
2592          0,
2593          0,
2594          0,
2595          0,
2596       },
2597 
2598       .num_filtered_states = 1,
2599       .table = (uint16_t []) {
2600 
2601          19,
2602       },
2603    },
2604    [nir_op_fge] = {
2605       .filter = (uint16_t []) {
2606          0,
2607          1,
2608          0,
2609          0,
2610          0,
2611          0,
2612          0,
2613          0,
2614          0,
2615          0,
2616          0,
2617          0,
2618          0,
2619          0,
2620          0,
2621          0,
2622          0,
2623          0,
2624          0,
2625          0,
2626          0,
2627          0,
2628          0,
2629          0,
2630          0,
2631          0,
2632          0,
2633          0,
2634          0,
2635       },
2636 
2637       .num_filtered_states = 2,
2638       .table = (uint16_t []) {
2639 
2640          0,
2641          20,
2642          0,
2643          20,
2644       },
2645    },
2646    [nir_op_fge32] = {
2647       .filter = (uint16_t []) {
2648          0,
2649          1,
2650          0,
2651          0,
2652          0,
2653          0,
2654          0,
2655          0,
2656          0,
2657          0,
2658          0,
2659          0,
2660          0,
2661          0,
2662          0,
2663          0,
2664          0,
2665          0,
2666          0,
2667          0,
2668          0,
2669          0,
2670          0,
2671          0,
2672          0,
2673          0,
2674          0,
2675          0,
2676          0,
2677       },
2678 
2679       .num_filtered_states = 2,
2680       .table = (uint16_t []) {
2681 
2682          0,
2683          21,
2684          0,
2685          21,
2686       },
2687    },
2688    [nir_op_ige32] = {
2689       .filter = (uint16_t []) {
2690          0,
2691          1,
2692          0,
2693          0,
2694          0,
2695          0,
2696          0,
2697          0,
2698          0,
2699          0,
2700          0,
2701          0,
2702          0,
2703          0,
2704          0,
2705          0,
2706          0,
2707          0,
2708          0,
2709          0,
2710          0,
2711          0,
2712          0,
2713          0,
2714          0,
2715          0,
2716          0,
2717          0,
2718          0,
2719       },
2720 
2721       .num_filtered_states = 2,
2722       .table = (uint16_t []) {
2723 
2724          0,
2725          22,
2726          0,
2727          22,
2728       },
2729    },
2730    [nir_op_uge32] = {
2731       .filter = (uint16_t []) {
2732          0,
2733          1,
2734          0,
2735          0,
2736          0,
2737          0,
2738          0,
2739          0,
2740          0,
2741          0,
2742          0,
2743          0,
2744          0,
2745          0,
2746          0,
2747          0,
2748          0,
2749          0,
2750          0,
2751          0,
2752          0,
2753          0,
2754          0,
2755          0,
2756          0,
2757          0,
2758          0,
2759          0,
2760          0,
2761       },
2762 
2763       .num_filtered_states = 2,
2764       .table = (uint16_t []) {
2765 
2766          0,
2767          23,
2768          0,
2769          23,
2770       },
2771    },
2772    [nir_op_flt32] = {
2773       .filter = (uint16_t []) {
2774          0,
2775          1,
2776          0,
2777          0,
2778          0,
2779          0,
2780          0,
2781          0,
2782          0,
2783          0,
2784          0,
2785          0,
2786          0,
2787          0,
2788          0,
2789          0,
2790          0,
2791          0,
2792          0,
2793          0,
2794          0,
2795          0,
2796          0,
2797          0,
2798          0,
2799          0,
2800          0,
2801          0,
2802          0,
2803       },
2804 
2805       .num_filtered_states = 2,
2806       .table = (uint16_t []) {
2807 
2808          0,
2809          0,
2810          24,
2811          24,
2812       },
2813    },
2814    [nir_op_ilt32] = {
2815       .filter = (uint16_t []) {
2816          0,
2817          1,
2818          0,
2819          0,
2820          0,
2821          0,
2822          0,
2823          0,
2824          0,
2825          0,
2826          0,
2827          0,
2828          0,
2829          0,
2830          0,
2831          0,
2832          0,
2833          0,
2834          0,
2835          0,
2836          0,
2837          0,
2838          0,
2839          0,
2840          0,
2841          0,
2842          0,
2843          0,
2844          0,
2845       },
2846 
2847       .num_filtered_states = 2,
2848       .table = (uint16_t []) {
2849 
2850          0,
2851          0,
2852          25,
2853          25,
2854       },
2855    },
2856    [nir_op_ult32] = {
2857       .filter = (uint16_t []) {
2858          0,
2859          1,
2860          0,
2861          0,
2862          0,
2863          0,
2864          0,
2865          0,
2866          0,
2867          0,
2868          0,
2869          0,
2870          0,
2871          0,
2872          0,
2873          0,
2874          0,
2875          0,
2876          0,
2877          0,
2878          0,
2879          0,
2880          0,
2881          0,
2882          0,
2883          0,
2884          0,
2885          0,
2886          0,
2887       },
2888 
2889       .num_filtered_states = 2,
2890       .table = (uint16_t []) {
2891 
2892          0,
2893          0,
2894          26,
2895          26,
2896       },
2897    },
2898 };
2899 
2900 const struct transform *midgard_nir_lower_algebraic_late_transforms[] = {
2901    NULL,
2902    NULL,
2903    midgard_nir_lower_algebraic_late_state2_xforms,
2904    midgard_nir_lower_algebraic_late_state3_xforms,
2905    midgard_nir_lower_algebraic_late_state4_xforms,
2906    midgard_nir_lower_algebraic_late_state5_xforms,
2907    midgard_nir_lower_algebraic_late_state6_xforms,
2908    NULL,
2909    midgard_nir_lower_algebraic_late_state8_xforms,
2910    midgard_nir_lower_algebraic_late_state9_xforms,
2911    midgard_nir_lower_algebraic_late_state10_xforms,
2912    midgard_nir_lower_algebraic_late_state11_xforms,
2913    midgard_nir_lower_algebraic_late_state12_xforms,
2914    midgard_nir_lower_algebraic_late_state13_xforms,
2915    midgard_nir_lower_algebraic_late_state14_xforms,
2916    midgard_nir_lower_algebraic_late_state15_xforms,
2917    midgard_nir_lower_algebraic_late_state16_xforms,
2918    midgard_nir_lower_algebraic_late_state17_xforms,
2919    midgard_nir_lower_algebraic_late_state18_xforms,
2920    midgard_nir_lower_algebraic_late_state19_xforms,
2921    midgard_nir_lower_algebraic_late_state20_xforms,
2922    midgard_nir_lower_algebraic_late_state21_xforms,
2923    midgard_nir_lower_algebraic_late_state22_xforms,
2924    midgard_nir_lower_algebraic_late_state23_xforms,
2925    midgard_nir_lower_algebraic_late_state24_xforms,
2926    midgard_nir_lower_algebraic_late_state25_xforms,
2927    midgard_nir_lower_algebraic_late_state26_xforms,
2928    midgard_nir_lower_algebraic_late_state27_xforms,
2929    midgard_nir_lower_algebraic_late_state28_xforms,
2930 };
2931 
2932 const uint16_t midgard_nir_lower_algebraic_late_transform_counts[] = {
2933    0,
2934    0,
2935    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state2_xforms),
2936    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state3_xforms),
2937    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state4_xforms),
2938    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state5_xforms),
2939    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state6_xforms),
2940    0,
2941    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state8_xforms),
2942    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state9_xforms),
2943    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state10_xforms),
2944    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state11_xforms),
2945    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state12_xforms),
2946    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state13_xforms),
2947    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state14_xforms),
2948    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state15_xforms),
2949    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state16_xforms),
2950    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state17_xforms),
2951    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state18_xforms),
2952    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state19_xforms),
2953    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state20_xforms),
2954    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state21_xforms),
2955    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state22_xforms),
2956    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state23_xforms),
2957    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state24_xforms),
2958    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state25_xforms),
2959    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state26_xforms),
2960    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state27_xforms),
2961    (uint16_t)ARRAY_SIZE(midgard_nir_lower_algebraic_late_state28_xforms),
2962 };
2963 
2964 bool
midgard_nir_lower_algebraic_late(nir_shader * shader)2965 midgard_nir_lower_algebraic_late(nir_shader *shader)
2966 {
2967    bool progress = false;
2968    bool condition_flags[1];
2969    const nir_shader_compiler_options *options = shader->options;
2970    const shader_info *info = &shader->info;
2971    (void) options;
2972    (void) info;
2973 
2974    condition_flags[0] = true;
2975 
2976    nir_foreach_function(function, shader) {
2977       if (function->impl) {
2978          progress |= nir_algebraic_impl(function->impl, condition_flags,
2979                                         midgard_nir_lower_algebraic_late_transforms,
2980                                         midgard_nir_lower_algebraic_late_transform_counts,
2981                                         midgard_nir_lower_algebraic_late_table);
2982       }
2983    }
2984 
2985    return progress;
2986 }
2987 
2988 
2989 #include "nir.h"
2990 #include "nir_builder.h"
2991 #include "nir_search.h"
2992 #include "nir_search_helpers.h"
2993 
2994 /* What follows is NIR algebraic transform code for the following 2
2995  * transforms:
2996  *    ('fsin', 'a') => ('fsin', ('fdiv', 'a', 3.141592653589793))
2997  *    ('fcos', 'a') => ('fcos', ('fdiv', 'a', 3.141592653589793))
2998  */
2999 
3000 
3001    static const nir_search_variable search53_0 = {
3002    { nir_search_value_variable, -1 },
3003    0, /* a */
3004    false,
3005    nir_type_invalid,
3006    NULL,
3007    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
3008 };
3009 static const nir_search_expression search53 = {
3010    { nir_search_value_expression, -1 },
3011    false, false,
3012    -1, 0,
3013    nir_op_fsin,
3014    { &search53_0.value },
3015    NULL,
3016 };
3017 
3018    /* replace53_0_0 -> search53_0 in the cache */
3019 
3020 static const nir_search_constant replace53_0_1 = {
3021    { nir_search_value_constant, -1 },
3022    nir_type_float, { 0x400921fb54442d18 /* 3.14159265359 */ },
3023 };
3024 static const nir_search_expression replace53_0 = {
3025    { nir_search_value_expression, -1 },
3026    false, false,
3027    -1, 0,
3028    nir_op_fdiv,
3029    { &search53_0.value, &replace53_0_1.value },
3030    NULL,
3031 };
3032 static const nir_search_expression replace53 = {
3033    { nir_search_value_expression, -1 },
3034    false, false,
3035    -1, 0,
3036    nir_op_fsin,
3037    { &replace53_0.value },
3038    NULL,
3039 };
3040 
3041    /* search54_0 -> search53_0 in the cache */
3042 static const nir_search_expression search54 = {
3043    { nir_search_value_expression, -1 },
3044    false, false,
3045    -1, 0,
3046    nir_op_fcos,
3047    { &search53_0.value },
3048    NULL,
3049 };
3050 
3051    /* replace54_0_0 -> search53_0 in the cache */
3052 
3053 /* replace54_0_1 -> replace53_0_1 in the cache */
3054 /* replace54_0 -> replace53_0 in the cache */
3055 static const nir_search_expression replace54 = {
3056    { nir_search_value_expression, -1 },
3057    false, false,
3058    -1, 0,
3059    nir_op_fcos,
3060    { &replace53_0.value },
3061    NULL,
3062 };
3063 
3064 
3065 static const struct transform midgard_nir_scale_trig_state2_xforms[] = {
3066   { &search53, &replace53.value, 0 },
3067 };
3068 static const struct transform midgard_nir_scale_trig_state3_xforms[] = {
3069   { &search54, &replace54.value, 0 },
3070 };
3071 
3072 static const struct per_op_table midgard_nir_scale_trig_table[nir_num_search_ops] = {
3073    [nir_op_fsin] = {
3074       .filter = (uint16_t []) {
3075          0,
3076          0,
3077          0,
3078          0,
3079       },
3080 
3081       .num_filtered_states = 1,
3082       .table = (uint16_t []) {
3083 
3084          2,
3085       },
3086    },
3087    [nir_op_fcos] = {
3088       .filter = (uint16_t []) {
3089          0,
3090          0,
3091          0,
3092          0,
3093       },
3094 
3095       .num_filtered_states = 1,
3096       .table = (uint16_t []) {
3097 
3098          3,
3099       },
3100    },
3101 };
3102 
3103 const struct transform *midgard_nir_scale_trig_transforms[] = {
3104    NULL,
3105    NULL,
3106    midgard_nir_scale_trig_state2_xforms,
3107    midgard_nir_scale_trig_state3_xforms,
3108 };
3109 
3110 const uint16_t midgard_nir_scale_trig_transform_counts[] = {
3111    0,
3112    0,
3113    (uint16_t)ARRAY_SIZE(midgard_nir_scale_trig_state2_xforms),
3114    (uint16_t)ARRAY_SIZE(midgard_nir_scale_trig_state3_xforms),
3115 };
3116 
3117 bool
midgard_nir_scale_trig(nir_shader * shader)3118 midgard_nir_scale_trig(nir_shader *shader)
3119 {
3120    bool progress = false;
3121    bool condition_flags[1];
3122    const nir_shader_compiler_options *options = shader->options;
3123    const shader_info *info = &shader->info;
3124    (void) options;
3125    (void) info;
3126 
3127    condition_flags[0] = true;
3128 
3129    nir_foreach_function(function, shader) {
3130       if (function->impl) {
3131          progress |= nir_algebraic_impl(function->impl, condition_flags,
3132                                         midgard_nir_scale_trig_transforms,
3133                                         midgard_nir_scale_trig_transform_counts,
3134                                         midgard_nir_scale_trig_table);
3135       }
3136    }
3137 
3138    return progress;
3139 }
3140 
3141 
3142 #include "nir.h"
3143 #include "nir_builder.h"
3144 #include "nir_search.h"
3145 #include "nir_search_helpers.h"
3146 
3147 /* What follows is NIR algebraic transform code for the following 1
3148  * transforms:
3149  *    ('inot', ('inot', 'a')) => a
3150  */
3151 
3152 
3153    static const nir_search_variable search55_0_0 = {
3154    { nir_search_value_variable, -1 },
3155    0, /* a */
3156    false,
3157    nir_type_invalid,
3158    NULL,
3159    {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
3160 };
3161 static const nir_search_expression search55_0 = {
3162    { nir_search_value_expression, -1 },
3163    false, false,
3164    -1, 0,
3165    nir_op_inot,
3166    { &search55_0_0.value },
3167    NULL,
3168 };
3169 static const nir_search_expression search55 = {
3170    { nir_search_value_expression, -1 },
3171    false, false,
3172    -1, 0,
3173    nir_op_inot,
3174    { &search55_0.value },
3175    NULL,
3176 };
3177 
3178    /* replace55 -> search55_0_0 in the cache */
3179 
3180 
3181 static const struct transform midgard_nir_cancel_inot_state3_xforms[] = {
3182   { &search55, &search55_0_0.value, 0 },
3183 };
3184 
3185 static const struct per_op_table midgard_nir_cancel_inot_table[nir_num_search_ops] = {
3186    [nir_op_inot] = {
3187       .filter = (uint16_t []) {
3188          0,
3189          0,
3190          1,
3191          1,
3192       },
3193 
3194       .num_filtered_states = 2,
3195       .table = (uint16_t []) {
3196 
3197          2,
3198          3,
3199       },
3200    },
3201 };
3202 
3203 const struct transform *midgard_nir_cancel_inot_transforms[] = {
3204    NULL,
3205    NULL,
3206    NULL,
3207    midgard_nir_cancel_inot_state3_xforms,
3208 };
3209 
3210 const uint16_t midgard_nir_cancel_inot_transform_counts[] = {
3211    0,
3212    0,
3213    0,
3214    (uint16_t)ARRAY_SIZE(midgard_nir_cancel_inot_state3_xforms),
3215 };
3216 
3217 bool
midgard_nir_cancel_inot(nir_shader * shader)3218 midgard_nir_cancel_inot(nir_shader *shader)
3219 {
3220    bool progress = false;
3221    bool condition_flags[1];
3222    const nir_shader_compiler_options *options = shader->options;
3223    const shader_info *info = &shader->info;
3224    (void) options;
3225    (void) info;
3226 
3227    condition_flags[0] = true;
3228 
3229    nir_foreach_function(function, shader) {
3230       if (function->impl) {
3231          progress |= nir_algebraic_impl(function->impl, condition_flags,
3232                                         midgard_nir_cancel_inot_transforms,
3233                                         midgard_nir_cancel_inot_transform_counts,
3234                                         midgard_nir_cancel_inot_table);
3235       }
3236    }
3237 
3238    return progress;
3239 }
3240 
3241