f88a5c17d2ad7fc1eccc386cf2ee47d1067ca84c
2 * Copyright © 2014 Broadcom
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
25 * @file vc4_opt_algebraic.c
27 * This is the optimization pass for miscellaneous changes to instructions
28 * where we can simplify the operation by some knowledge about the specific
31 * Mostly this will be a matter of turning things into MOVs so that they can
32 * later be copy-propagated out.
40 dump_from(struct vc4_compile
*c
, struct qinst
*inst
)
45 fprintf(stderr
, "optimizing: ");
46 qir_dump_inst(c
, inst
);
47 fprintf(stderr
, "\n");
51 dump_to(struct vc4_compile
*c
, struct qinst
*inst
)
56 fprintf(stderr
, "to: ");
57 qir_dump_inst(c
, inst
);
58 fprintf(stderr
, "\n");
62 follow_movs(struct qinst
**defs
, struct qreg reg
)
64 while (reg
.file
== QFILE_TEMP
&& defs
[reg
.index
]->op
== QOP_MOV
)
65 reg
= defs
[reg
.index
]->src
[0];
71 is_zero(struct vc4_compile
*c
, struct qinst
**defs
, struct qreg reg
)
73 reg
= follow_movs(defs
, reg
);
75 return (reg
.file
== QFILE_UNIF
&&
76 c
->uniform_contents
[reg
.index
] == QUNIFORM_CONSTANT
&&
77 c
->uniform_data
[reg
.index
] == 0);
81 qir_opt_algebraic(struct vc4_compile
*c
)
83 bool progress
= false;
84 struct simple_node
*node
;
85 struct qinst
*defs
[c
->num_temps
];
87 foreach(node
, &c
->instructions
) {
88 struct qinst
*inst
= (struct qinst
*)node
;
90 if (inst
->dst
.file
== QFILE_TEMP
)
91 defs
[inst
->dst
.index
] = inst
;
98 if (qir_reg_equals(inst
->src
[0], inst
->src
[1])) {
99 /* Turn "dst = (sf == x) ? a : a)" into
104 inst
->src
[0] = inst
->src
[1];
105 inst
->src
[1] = c
->undef
;
108 } else if (is_zero(c
, defs
, inst
->src
[1])) {
109 /* Replace references to a 0 uniform value
110 * with the SEL_X_0 equivalent.
113 inst
->op
-= (QOP_SEL_X_Y_ZS
- QOP_SEL_X_0_ZS
);
114 inst
->src
[1] = c
->undef
;
122 if (is_zero(c
, defs
, inst
->src
[1])) {
125 inst
->src
[1] = c
->undef
;