2 * Copyright (C) 2020 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * Authors (Collabora):
24 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
27 /* Fuses f2f16 modifiers into loads */
29 #include "compiler/nir/nir.h"
30 #include "compiler/nir/nir_builder.h"
31 #include "panfrost/util/pan_ir.h"
33 bool nir_fuse_io_16(nir_shader
*shader
);
36 nir_src_is_f2fmp(nir_src
*use
)
38 nir_instr
*parent
= use
->parent_instr
;
40 if (parent
->type
!= nir_instr_type_alu
)
43 nir_alu_instr
*alu
= nir_instr_as_alu(parent
);
44 return (alu
->op
== nir_op_f2fmp
);
48 nir_fuse_io_16(nir_shader
*shader
)
50 bool progress
= false;
52 nir_foreach_function(function
, shader
) {
53 if (!function
->impl
) continue;
56 nir_builder_init(&b
, function
->impl
);
58 nir_foreach_block(block
, function
->impl
) {
59 nir_foreach_instr_safe(instr
, block
) {
60 if (instr
->type
!= nir_instr_type_intrinsic
) continue;
62 nir_intrinsic_instr
*intr
= nir_instr_as_intrinsic(instr
);
64 if (intr
->intrinsic
!= nir_intrinsic_load_interpolated_input
)
67 if (nir_dest_bit_size(intr
->dest
) != 32)
70 /* We swizzle at a 32-bit level so need a multiple of 2. We could
71 * do a bit better and handle even components though */
72 if (nir_intrinsic_component(intr
))
75 if (!intr
->dest
.is_ssa
)
78 if (!list_is_empty(&intr
->dest
.ssa
.if_uses
))
83 nir_foreach_use(src
, &intr
->dest
.ssa
)
84 valid
&= nir_src_is_f2fmp(src
);
89 intr
->dest
.ssa
.bit_size
= 16;
94 nir_metadata_preserve(function
->impl
, nir_metadata_block_index
| nir_metadata_dominance
);