2 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Rob Clark <robclark@freedesktop.org>
28 #include "util/half_float.h"
29 #include "util/u_math.h"
32 #include "ir3_compiler.h"
33 #include "ir3_shader.h"
36 do { __typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
44 struct ir3_shader_variant
*so
;
48 /* is it a type preserving mov, with ok flags?
50 * @instr: the mov to consider removing
51 * @dst_instr: the instruction consuming the mov (instr)
53 * TODO maybe drop allow_flags since this is only false when dst is
56 static bool is_eligible_mov(struct ir3_instruction
*instr
,
57 struct ir3_instruction
*dst_instr
, bool allow_flags
)
59 if (is_same_type_mov(instr
)) {
60 struct ir3_register
*dst
= instr
->regs
[0];
61 struct ir3_register
*src
= instr
->regs
[1];
62 struct ir3_instruction
*src_instr
= ssa(src
);
64 /* only if mov src is SSA (not const/immed): */
69 if (dst
->flags
& IR3_REG_RELATIV
)
71 if (src
->flags
& IR3_REG_RELATIV
)
74 if (src
->flags
& IR3_REG_ARRAY
)
78 if (src
->flags
& (IR3_REG_FABS
| IR3_REG_FNEG
|
79 IR3_REG_SABS
| IR3_REG_SNEG
| IR3_REG_BNOT
))
82 /* If src is coming from fanout/split (ie. one component of a
83 * texture fetch, etc) and we have constraints on swizzle of
84 * destination, then skip it.
86 * We could possibly do a bit better, and copy-propagation if
87 * we can CP all components that are being fanned out.
89 if (src_instr
->opc
== OPC_META_SPLIT
) {
92 if (dst_instr
->opc
== OPC_META_COLLECT
)
94 if (dst_instr
->cp
.left
|| dst_instr
->cp
.right
)
103 static unsigned cp_flags(unsigned flags
)
105 /* only considering these flags (at least for now): */
106 flags
&= (IR3_REG_CONST
| IR3_REG_IMMED
|
107 IR3_REG_FNEG
| IR3_REG_FABS
|
108 IR3_REG_SNEG
| IR3_REG_SABS
|
109 IR3_REG_BNOT
| IR3_REG_RELATIV
);
113 static bool valid_flags(struct ir3_instruction
*instr
, unsigned n
,
116 struct ir3_compiler
*compiler
= instr
->block
->shader
->compiler
;
117 unsigned valid_flags
;
119 if ((flags
& IR3_REG_HIGH
) &&
120 (opc_cat(instr
->opc
) > 1) &&
121 (compiler
->gpu_id
>= 600))
124 flags
= cp_flags(flags
);
126 /* If destination is indirect, then source cannot be.. at least
129 if ((instr
->regs
[0]->flags
& IR3_REG_RELATIV
) &&
130 (flags
& IR3_REG_RELATIV
))
133 if (flags
& IR3_REG_RELATIV
) {
134 /* TODO need to test on earlier gens.. pretty sure the earlier
135 * problem was just that we didn't check that the src was from
136 * same block (since we can't propagate address register values
137 * across blocks currently)
139 if (compiler
->gpu_id
< 600)
142 /* NOTE in the special try_swap_mad_two_srcs() case we can be
143 * called on a src that has already had an indirect load folded
144 * in, in which case ssa() returns NULL
146 if (instr
->regs
[n
+1]->flags
& IR3_REG_SSA
) {
147 struct ir3_instruction
*src
= ssa(instr
->regs
[n
+1]);
148 if (src
->address
->block
!= instr
->block
)
153 switch (opc_cat(instr
->opc
)) {
155 valid_flags
= IR3_REG_IMMED
| IR3_REG_CONST
| IR3_REG_RELATIV
;
156 if (flags
& ~valid_flags
)
160 valid_flags
= ir3_cat2_absneg(instr
->opc
) |
161 IR3_REG_CONST
| IR3_REG_RELATIV
;
163 if (ir3_cat2_int(instr
->opc
))
164 valid_flags
|= IR3_REG_IMMED
;
166 if (flags
& ~valid_flags
)
169 if (flags
& (IR3_REG_CONST
| IR3_REG_IMMED
)) {
170 unsigned m
= (n
^ 1) + 1;
171 /* cannot deal w/ const in both srcs:
172 * (note that some cat2 actually only have a single src)
174 if (m
< instr
->regs_count
) {
175 struct ir3_register
*reg
= instr
->regs
[m
];
176 if ((flags
& IR3_REG_CONST
) && (reg
->flags
& IR3_REG_CONST
))
178 if ((flags
& IR3_REG_IMMED
) && (reg
->flags
& IR3_REG_IMMED
))
184 valid_flags
= ir3_cat3_absneg(instr
->opc
) |
185 IR3_REG_CONST
| IR3_REG_RELATIV
;
187 if (flags
& ~valid_flags
)
190 if (flags
& (IR3_REG_CONST
| IR3_REG_RELATIV
)) {
191 /* cannot deal w/ const/relativ in 2nd src: */
198 /* seems like blob compiler avoids const as src.. */
199 /* TODO double check if this is still the case on a4xx */
200 if (flags
& (IR3_REG_CONST
| IR3_REG_IMMED
))
202 if (flags
& (IR3_REG_SABS
| IR3_REG_SNEG
))
206 /* no flags allowed */
211 valid_flags
= IR3_REG_IMMED
;
212 if (flags
& ~valid_flags
)
215 if (flags
& IR3_REG_IMMED
) {
216 /* doesn't seem like we can have immediate src for store
219 * TODO this restriction could also apply to load instructions,
220 * but for load instructions this arg is the address (and not
221 * really sure any good way to test a hard-coded immed addr src)
223 if (is_store(instr
) && (n
== 1))
226 if ((instr
->opc
== OPC_LDL
) && (n
== 0))
229 if ((instr
->opc
== OPC_STL
) && (n
!= 2))
232 if (instr
->opc
== OPC_STLW
&& n
== 0)
235 if (instr
->opc
== OPC_LDLW
&& n
== 0)
238 /* disallow immediates in anything but the SSBO slot argument for
241 if (is_atomic(instr
->opc
) && (n
!= 0))
244 if (is_atomic(instr
->opc
) && !(instr
->flags
& IR3_INSTR_G
))
247 if (instr
->opc
== OPC_STG
&& (instr
->flags
& IR3_INSTR_G
) && (n
!= 2))
250 /* as with atomics, these cat6 instrs can only have an immediate
251 * for SSBO/IBO slot argument
253 switch (instr
->opc
) {
271 /* propagate register flags from src to dst.. negates need special
272 * handling to cancel each other out.
274 static void combine_flags(unsigned *dstflags
, struct ir3_instruction
*src
)
276 unsigned srcflags
= src
->regs
[1]->flags
;
278 /* if what we are combining into already has (abs) flags,
279 * we can drop (neg) from src:
281 if (*dstflags
& IR3_REG_FABS
)
282 srcflags
&= ~IR3_REG_FNEG
;
283 if (*dstflags
& IR3_REG_SABS
)
284 srcflags
&= ~IR3_REG_SNEG
;
286 if (srcflags
& IR3_REG_FABS
)
287 *dstflags
|= IR3_REG_FABS
;
288 if (srcflags
& IR3_REG_SABS
)
289 *dstflags
|= IR3_REG_SABS
;
290 if (srcflags
& IR3_REG_FNEG
)
291 *dstflags
^= IR3_REG_FNEG
;
292 if (srcflags
& IR3_REG_SNEG
)
293 *dstflags
^= IR3_REG_SNEG
;
294 if (srcflags
& IR3_REG_BNOT
)
295 *dstflags
^= IR3_REG_BNOT
;
297 *dstflags
&= ~IR3_REG_SSA
;
298 *dstflags
|= srcflags
& IR3_REG_SSA
;
299 *dstflags
|= srcflags
& IR3_REG_CONST
;
300 *dstflags
|= srcflags
& IR3_REG_IMMED
;
301 *dstflags
|= srcflags
& IR3_REG_RELATIV
;
302 *dstflags
|= srcflags
& IR3_REG_ARRAY
;
303 *dstflags
|= srcflags
& IR3_REG_HIGH
;
305 /* if src of the src is boolean we can drop the (abs) since we know
306 * the source value is already a postitive integer. This cleans
307 * up the absnegs that get inserted when converting between nir and
308 * native boolean (see ir3_b2n/n2b)
310 struct ir3_instruction
*srcsrc
= ssa(src
->regs
[1]);
311 if (srcsrc
&& is_bool(srcsrc
))
312 *dstflags
&= ~IR3_REG_SABS
;
315 /* Tries lowering an immediate register argument to a const buffer access by
316 * adding to the list of immediates to be pushed to the const buffer when
317 * switching to this shader.
320 lower_immed(struct ir3_cp_ctx
*ctx
, struct ir3_instruction
*instr
, unsigned n
,
321 struct ir3_register
*reg
, unsigned new_flags
)
323 if (!(new_flags
& IR3_REG_IMMED
))
326 new_flags
&= ~IR3_REG_IMMED
;
327 new_flags
|= IR3_REG_CONST
;
329 if (!valid_flags(instr
, n
, new_flags
))
332 unsigned swiz
, idx
, i
;
334 reg
= ir3_reg_clone(ctx
->shader
, reg
);
336 /* Half constant registers seems to handle only 32-bit values
337 * within floating-point opcodes. So convert back to 32-bit values.
339 bool f_opcode
= (is_cat2_float(instr
->opc
) ||
340 is_cat3_float(instr
->opc
)) ? true : false;
341 if (f_opcode
&& (new_flags
& IR3_REG_HALF
))
342 reg
->uim_val
= fui(_mesa_half_to_float(reg
->uim_val
));
344 /* in some cases, there are restrictions on (abs)/(neg) plus const..
345 * so just evaluate those and clear the flags:
347 if (new_flags
& IR3_REG_SABS
) {
348 reg
->iim_val
= abs(reg
->iim_val
);
349 new_flags
&= ~IR3_REG_SABS
;
352 if (new_flags
& IR3_REG_FABS
) {
353 reg
->fim_val
= fabs(reg
->fim_val
);
354 new_flags
&= ~IR3_REG_FABS
;
357 if (new_flags
& IR3_REG_SNEG
) {
358 reg
->iim_val
= -reg
->iim_val
;
359 new_flags
&= ~IR3_REG_SNEG
;
362 if (new_flags
& IR3_REG_FNEG
) {
363 reg
->fim_val
= -reg
->fim_val
;
364 new_flags
&= ~IR3_REG_FNEG
;
367 /* Reallocate for 4 more elements whenever it's necessary */
368 struct ir3_const_state
*const_state
= &ctx
->so
->shader
->const_state
;
369 if (const_state
->immediate_idx
== const_state
->immediates_size
* 4) {
370 const_state
->immediates_size
+= 4;
371 const_state
->immediates
= realloc (const_state
->immediates
,
372 const_state
->immediates_size
* sizeof(const_state
->immediates
[0]));
374 for (int i
= const_state
->immediate_idx
; i
< const_state
->immediates_size
* 4; i
++)
375 const_state
->immediates
[i
/ 4].val
[i
% 4] = 0xd0d0d0d0;
378 for (i
= 0; i
< const_state
->immediate_idx
; i
++) {
382 if (const_state
->immediates
[idx
].val
[swiz
] == reg
->uim_val
) {
387 if (i
== const_state
->immediate_idx
) {
388 struct ir3_compiler
*compiler
= instr
->block
->shader
->compiler
;
389 /* Add on a new immediate to be pushed, if we have space left in the
392 if (const_state
->offsets
.immediate
+ const_state
->immediate_idx
/ 4 >=
399 const_state
->immediates
[idx
].val
[swiz
] = reg
->uim_val
;
400 const_state
->immediates_count
= idx
+ 1;
401 const_state
->immediate_idx
++;
404 reg
->flags
= new_flags
;
405 reg
->num
= i
+ (4 * const_state
->offsets
.immediate
);
407 instr
->regs
[n
+ 1] = reg
;
413 unuse(struct ir3_instruction
*instr
)
415 debug_assert(instr
->use_count
> 0);
417 if (--instr
->use_count
== 0) {
418 struct ir3_block
*block
= instr
->block
;
420 instr
->barrier_class
= 0;
421 instr
->barrier_conflict
= 0;
423 /* we don't want to remove anything in keeps (which could
424 * be things like array store's)
426 for (unsigned i
= 0; i
< block
->keeps_count
; i
++) {
427 debug_assert(block
->keeps
[i
] != instr
);
433 * Handles the special case of the 2nd src (n == 1) to "normal" mad
434 * instructions, which cannot reference a constant. See if it is
435 * possible to swap the 1st and 2nd sources.
438 try_swap_mad_two_srcs(struct ir3_instruction
*instr
, unsigned new_flags
)
440 if (!is_mad(instr
->opc
))
443 /* NOTE: pre-swap first two src's before valid_flags(),
444 * which might try to dereference the n'th src:
446 swap(instr
->regs
[0 + 1], instr
->regs
[1 + 1]);
448 /* cat3 doesn't encode immediate, but we can lower immediate
449 * to const if that helps:
451 if (new_flags
& IR3_REG_IMMED
) {
452 new_flags
&= ~IR3_REG_IMMED
;
453 new_flags
|= IR3_REG_CONST
;
457 /* can we propagate mov if we move 2nd src to first? */
458 valid_flags(instr
, 0, new_flags
) &&
459 /* and does first src fit in second slot? */
460 valid_flags(instr
, 1, instr
->regs
[1 + 1]->flags
);
463 /* put things back the way they were: */
464 swap(instr
->regs
[0 + 1], instr
->regs
[1 + 1]);
465 } /* otherwise leave things swapped */
471 * Handle cp for a given src register. This additionally handles
472 * the cases of collapsing immedate/const (which replace the src
473 * register with a non-ssa src) or collapsing mov's from relative
474 * src (which needs to also fixup the address src reference by the
478 reg_cp(struct ir3_cp_ctx
*ctx
, struct ir3_instruction
*instr
,
479 struct ir3_register
*reg
, unsigned n
)
481 struct ir3_instruction
*src
= ssa(reg
);
483 if (is_eligible_mov(src
, instr
, true)) {
484 /* simple case, no immed/const/relativ, only mov's w/ ssa src: */
485 struct ir3_register
*src_reg
= src
->regs
[1];
486 unsigned new_flags
= reg
->flags
;
488 combine_flags(&new_flags
, src
);
490 if (valid_flags(instr
, n
, new_flags
)) {
491 if (new_flags
& IR3_REG_ARRAY
) {
492 debug_assert(!(reg
->flags
& IR3_REG_ARRAY
));
493 reg
->array
= src_reg
->array
;
495 reg
->flags
= new_flags
;
496 reg
->instr
= ssa(src_reg
);
498 instr
->barrier_class
|= src
->barrier_class
;
499 instr
->barrier_conflict
|= src
->barrier_conflict
;
502 reg
->instr
->use_count
++;
506 } else if ((is_same_type_mov(src
) || is_const_mov(src
)) &&
507 /* cannot collapse const/immed/etc into meta instrs: */
509 /* immed/const/etc cases, which require some special handling: */
510 struct ir3_register
*src_reg
= src
->regs
[1];
511 unsigned new_flags
= reg
->flags
;
513 combine_flags(&new_flags
, src
);
515 if (!valid_flags(instr
, n
, new_flags
)) {
516 /* See if lowering an immediate to const would help. */
517 if (lower_immed(ctx
, instr
, n
, src_reg
, new_flags
))
520 /* special case for "normal" mad instructions, we can
521 * try swapping the first two args if that fits better.
523 * the "plain" MAD's (ie. the ones that don't shift first
524 * src prior to multiply) can swap their first two srcs if
525 * src[0] is !CONST and src[1] is CONST:
527 if ((n
== 1) && try_swap_mad_two_srcs(instr
, new_flags
)) {
534 /* Here we handle the special case of mov from
535 * CONST and/or RELATIV. These need to be handled
536 * specially, because in the case of move from CONST
537 * there is no src ir3_instruction so we need to
538 * replace the ir3_register. And in the case of
539 * RELATIV we need to handle the address register
542 if (src_reg
->flags
& IR3_REG_CONST
) {
543 /* an instruction cannot reference two different
546 if ((src_reg
->flags
& IR3_REG_RELATIV
) &&
547 conflicts(instr
->address
, reg
->instr
->address
))
550 /* This seems to be a hw bug, or something where the timings
551 * just somehow don't work out. This restriction may only
552 * apply if the first src is also CONST.
554 if ((opc_cat(instr
->opc
) == 3) && (n
== 2) &&
555 (src_reg
->flags
& IR3_REG_RELATIV
) &&
556 (src_reg
->array
.offset
== 0))
559 /* When narrowing constant from 32b to 16b, it seems
560 * to work only for float. So we should do this only with
563 if (src
->cat1
.dst_type
== TYPE_F16
) {
564 if (instr
->opc
== OPC_MOV
&& !type_float(instr
->cat1
.src_type
))
566 if (!is_cat2_float(instr
->opc
) && !is_cat3_float(instr
->opc
))
570 src_reg
= ir3_reg_clone(instr
->block
->shader
, src_reg
);
571 src_reg
->flags
= new_flags
;
572 instr
->regs
[n
+1] = src_reg
;
574 if (src_reg
->flags
& IR3_REG_RELATIV
)
575 ir3_instr_set_address(instr
, reg
->instr
->address
);
580 if ((src_reg
->flags
& IR3_REG_RELATIV
) &&
581 !conflicts(instr
->address
, reg
->instr
->address
)) {
582 src_reg
= ir3_reg_clone(instr
->block
->shader
, src_reg
);
583 src_reg
->flags
= new_flags
;
584 instr
->regs
[n
+1] = src_reg
;
585 ir3_instr_set_address(instr
, reg
->instr
->address
);
590 /* NOTE: seems we can only do immed integers, so don't
591 * need to care about float. But we do need to handle
592 * abs/neg *before* checking that the immediate requires
593 * few enough bits to encode:
595 * TODO: do we need to do something to avoid accidentally
596 * catching a float immed?
598 if (src_reg
->flags
& IR3_REG_IMMED
) {
599 int32_t iim_val
= src_reg
->iim_val
;
601 debug_assert((opc_cat(instr
->opc
) == 1) ||
602 (opc_cat(instr
->opc
) == 6) ||
603 ir3_cat2_int(instr
->opc
) ||
604 (is_mad(instr
->opc
) && (n
== 0)));
606 if (new_flags
& IR3_REG_SABS
)
607 iim_val
= abs(iim_val
);
609 if (new_flags
& IR3_REG_SNEG
)
612 if (new_flags
& IR3_REG_BNOT
)
615 /* other than category 1 (mov) we can only encode up to 10 bits: */
616 if (valid_flags(instr
, n
, new_flags
) &&
617 ((instr
->opc
== OPC_MOV
) ||
618 !((iim_val
& ~0x3ff) && (-iim_val
& ~0x3ff)))) {
619 new_flags
&= ~(IR3_REG_SABS
| IR3_REG_SNEG
| IR3_REG_BNOT
);
620 src_reg
= ir3_reg_clone(instr
->block
->shader
, src_reg
);
621 src_reg
->flags
= new_flags
;
622 src_reg
->iim_val
= iim_val
;
623 instr
->regs
[n
+1] = src_reg
;
626 } else if (lower_immed(ctx
, instr
, n
, src_reg
, new_flags
)) {
627 /* Fell back to loading the immediate as a const */
636 /* Handle special case of eliminating output mov, and similar cases where
637 * there isn't a normal "consuming" instruction. In this case we cannot
638 * collapse flags (ie. output mov from const, or w/ abs/neg flags, cannot
641 static struct ir3_instruction
*
642 eliminate_output_mov(struct ir3_cp_ctx
*ctx
, struct ir3_instruction
*instr
)
644 if (is_eligible_mov(instr
, NULL
, false)) {
645 struct ir3_register
*reg
= instr
->regs
[1];
646 if (!(reg
->flags
& IR3_REG_ARRAY
)) {
647 struct ir3_instruction
*src_instr
= ssa(reg
);
648 debug_assert(src_instr
);
649 ctx
->progress
= true;
657 * Find instruction src's which are mov's that can be collapsed, replacing
658 * the mov dst with the mov src
661 instr_cp(struct ir3_cp_ctx
*ctx
, struct ir3_instruction
*instr
)
663 if (instr
->regs_count
== 0)
666 if (ir3_instr_check_mark(instr
))
669 /* walk down the graph from each src: */
673 foreach_src_n (reg
, n
, instr
) {
674 struct ir3_instruction
*src
= ssa(reg
);
681 /* TODO non-indirect access we could figure out which register
682 * we actually want and allow cp..
684 if (reg
->flags
& IR3_REG_ARRAY
)
687 /* Don't CP absneg into meta instructions, that won't end well: */
688 if (is_meta(instr
) && (src
->opc
!= OPC_MOV
))
691 progress
|= reg_cp(ctx
, instr
, reg
, n
);
692 ctx
->progress
|= progress
;
696 if (instr
->regs
[0]->flags
& IR3_REG_ARRAY
) {
697 struct ir3_instruction
*src
= ssa(instr
->regs
[0]);
702 if (instr
->address
) {
703 instr_cp(ctx
, instr
->address
);
704 ir3_instr_set_address(instr
, eliminate_output_mov(ctx
, instr
->address
));
707 /* we can end up with extra cmps.s from frontend, which uses a
709 * cmps.s p0.x, cond, 0
711 * as a way to mov into the predicate register. But frequently 'cond'
712 * is itself a cmps.s/cmps.f/cmps.u. So detect this special case and
713 * just re-write the instruction writing predicate register to get rid
714 * of the double cmps.
716 if ((instr
->opc
== OPC_CMPS_S
) &&
717 (instr
->regs
[0]->num
== regid(REG_P0
, 0)) &&
718 ssa(instr
->regs
[1]) &&
719 (instr
->regs
[2]->flags
& IR3_REG_IMMED
) &&
720 (instr
->regs
[2]->iim_val
== 0) &&
721 (instr
->cat2
.condition
== IR3_COND_NE
)) {
722 struct ir3_instruction
*cond
= ssa(instr
->regs
[1]);
727 instr
->opc
= cond
->opc
;
728 instr
->flags
= cond
->flags
;
729 instr
->cat2
= cond
->cat2
;
730 ir3_instr_set_address(instr
, cond
->address
);
731 instr
->regs
[1] = cond
->regs
[1];
732 instr
->regs
[2] = cond
->regs
[2];
733 instr
->barrier_class
|= cond
->barrier_class
;
734 instr
->barrier_conflict
|= cond
->barrier_conflict
;
736 ctx
->progress
= true;
743 /* Handle converting a sam.s2en (taking samp/tex idx params via register)
744 * into a normal sam (encoding immediate samp/tex idx) if they are
745 * immediate. This saves some instructions and regs in the common case
746 * where we know samp/tex at compile time. This needs to be done in the
747 * frontend for bindless tex, though, so don't replicate it here.
749 if (is_tex(instr
) && (instr
->flags
& IR3_INSTR_S2EN
) &&
750 !(instr
->flags
& IR3_INSTR_B
) &&
751 !(ir3_shader_debug
& IR3_DBG_FORCES2EN
)) {
752 /* The first src will be a collect, if both of it's
753 * two sources are mov from imm, then we can
755 struct ir3_instruction
*samp_tex
= ssa(instr
->regs
[1]);
757 debug_assert(samp_tex
->opc
== OPC_META_COLLECT
);
759 struct ir3_instruction
*samp
= ssa(samp_tex
->regs
[1]);
760 struct ir3_instruction
*tex
= ssa(samp_tex
->regs
[2]);
762 if ((samp
->opc
== OPC_MOV
) &&
763 (samp
->regs
[1]->flags
& IR3_REG_IMMED
) &&
764 (tex
->opc
== OPC_MOV
) &&
765 (tex
->regs
[1]->flags
& IR3_REG_IMMED
)) {
766 instr
->flags
&= ~IR3_INSTR_S2EN
;
767 instr
->cat5
.samp
= samp
->regs
[1]->iim_val
;
768 instr
->cat5
.tex
= tex
->regs
[1]->iim_val
;
770 /* shuffle around the regs to remove the first src: */
772 for (unsigned i
= 1; i
< instr
->regs_count
; i
++) {
773 instr
->regs
[i
] = instr
->regs
[i
+ 1];
776 ctx
->progress
= true;
782 ir3_cp(struct ir3
*ir
, struct ir3_shader_variant
*so
)
784 struct ir3_cp_ctx ctx
= {
789 /* This is a bit annoying, and probably wouldn't be necessary if we
790 * tracked a reverse link from producing instruction to consumer.
791 * But we need to know when we've eliminated the last consumer of
792 * a mov, so we need to do a pass to first count consumers of a
795 foreach_block (block
, &ir
->block_list
) {
796 foreach_instr (instr
, &block
->instr_list
) {
798 /* by the way, we don't account for false-dep's, so the CP
799 * pass should always happen before false-dep's are inserted
801 debug_assert(instr
->deps_count
== 0);
803 foreach_ssa_src (src
, instr
) {
811 foreach_output_n (out
, n
, ir
) {
813 ir
->outputs
[n
] = eliminate_output_mov(&ctx
, out
);
816 foreach_block (block
, &ir
->block_list
) {
817 if (block
->condition
) {
818 instr_cp(&ctx
, block
->condition
);
819 block
->condition
= eliminate_output_mov(&ctx
, block
->condition
);
822 for (unsigned i
= 0; i
< block
->keeps_count
; i
++) {
823 instr_cp(&ctx
, block
->keeps
[i
]);
824 block
->keeps
[i
] = eliminate_output_mov(&ctx
, block
->keeps
[i
]);