2 * Copyright © 2010 Intel Corporation
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
21 * DEALINGS IN THE SOFTWARE.
25 * \file opt_algebraic.cpp
27 * Takes advantage of association, commutivity, and other algebraic
28 * properties to simplify expressions.
32 #include "ir_visitor.h"
33 #include "ir_rvalue_visitor.h"
34 #include "ir_optimization.h"
35 #include "ir_builder.h"
36 #include "glsl_types.h"
38 using namespace ir_builder
;
43 * Visitor class for replacing expressions with ir_constant values.
46 class ir_algebraic_visitor
: public ir_rvalue_visitor
{
48 ir_algebraic_visitor(bool native_integers
,
49 const struct gl_shader_compiler_options
*options
)
52 this->progress
= false;
54 this->native_integers
= native_integers
;
57 virtual ~ir_algebraic_visitor()
61 ir_rvalue
*handle_expression(ir_expression
*ir
);
62 void handle_rvalue(ir_rvalue
**rvalue
);
63 bool reassociate_constant(ir_expression
*ir1
,
65 ir_constant
*constant
,
67 void reassociate_operands(ir_expression
*ir1
,
71 ir_rvalue
*swizzle_if_required(ir_expression
*expr
,
74 const struct gl_shader_compiler_options
*options
;
81 } /* unnamed namespace */
84 is_vec_zero(ir_constant
*ir
)
86 return (ir
== NULL
) ? false : ir
->is_zero();
90 is_vec_one(ir_constant
*ir
)
92 return (ir
== NULL
) ? false : ir
->is_one();
96 is_vec_two(ir_constant
*ir
)
98 return (ir
== NULL
) ? false : ir
->is_value(2.0, 2);
102 is_vec_negative_one(ir_constant
*ir
)
104 return (ir
== NULL
) ? false : ir
->is_negative_one();
108 is_valid_vec_const(ir_constant
*ir
)
113 if (!ir
->type
->is_scalar() && !ir
->type
->is_vector())
120 is_less_than_one(ir_constant
*ir
)
122 if (!is_valid_vec_const(ir
))
125 unsigned component
= 0;
126 for (int c
= 0; c
< ir
->type
->vector_elements
; c
++) {
127 if (ir
->get_float_component(c
) < 1.0f
)
131 return (component
== ir
->type
->vector_elements
);
135 is_greater_than_zero(ir_constant
*ir
)
137 if (!is_valid_vec_const(ir
))
140 unsigned component
= 0;
141 for (int c
= 0; c
< ir
->type
->vector_elements
; c
++) {
142 if (ir
->get_float_component(c
) > 0.0f
)
146 return (component
== ir
->type
->vector_elements
);
150 update_type(ir_expression
*ir
)
152 if (ir
->operands
[0]->type
->is_vector())
153 ir
->type
= ir
->operands
[0]->type
;
155 ir
->type
= ir
->operands
[1]->type
;
158 /* Recognize (v.x + v.y) + (v.z + v.w) as dot(v, 1.0) */
159 static ir_expression
*
160 try_replace_with_dot(ir_expression
*expr0
, ir_expression
*expr1
, void *mem_ctx
)
162 if (expr0
&& expr0
->operation
== ir_binop_add
&&
163 expr0
->type
->is_float() &&
164 expr1
&& expr1
->operation
== ir_binop_add
&&
165 expr1
->type
->is_float()) {
166 ir_swizzle
*x
= expr0
->operands
[0]->as_swizzle();
167 ir_swizzle
*y
= expr0
->operands
[1]->as_swizzle();
168 ir_swizzle
*z
= expr1
->operands
[0]->as_swizzle();
169 ir_swizzle
*w
= expr1
->operands
[1]->as_swizzle();
171 if (!x
|| x
->mask
.num_components
!= 1 ||
172 !y
|| y
->mask
.num_components
!= 1 ||
173 !z
|| z
->mask
.num_components
!= 1 ||
174 !w
|| w
->mask
.num_components
!= 1) {
178 bool swiz_seen
[4] = {false, false, false, false};
179 swiz_seen
[x
->mask
.x
] = true;
180 swiz_seen
[y
->mask
.x
] = true;
181 swiz_seen
[z
->mask
.x
] = true;
182 swiz_seen
[w
->mask
.x
] = true;
184 if (!swiz_seen
[0] || !swiz_seen
[1] ||
185 !swiz_seen
[2] || !swiz_seen
[3]) {
189 if (x
->val
->equals(y
->val
) &&
190 x
->val
->equals(z
->val
) &&
191 x
->val
->equals(w
->val
)) {
192 return dot(x
->val
, new(mem_ctx
) ir_constant(1.0f
, 4));
199 ir_algebraic_visitor::reassociate_operands(ir_expression
*ir1
,
204 ir_rvalue
*temp
= ir2
->operands
[op2
];
205 ir2
->operands
[op2
] = ir1
->operands
[op1
];
206 ir1
->operands
[op1
] = temp
;
208 /* Update the type of ir2. The type of ir1 won't have changed --
209 * base types matched, and at least one of the operands of the 2
210 * binops is still a vector if any of them were.
214 this->progress
= true;
218 * Reassociates a constant down a tree of adds or multiplies.
220 * Consider (2 * (a * (b * 0.5))). We want to send up with a * b.
223 ir_algebraic_visitor::reassociate_constant(ir_expression
*ir1
, int const_index
,
224 ir_constant
*constant
,
227 if (!ir2
|| ir1
->operation
!= ir2
->operation
)
230 /* Don't want to even think about matrices. */
231 if (ir1
->operands
[0]->type
->is_matrix() ||
232 ir1
->operands
[1]->type
->is_matrix() ||
233 ir2
->operands
[0]->type
->is_matrix() ||
234 ir2
->operands
[1]->type
->is_matrix())
237 ir_constant
*ir2_const
[2];
238 ir2_const
[0] = ir2
->operands
[0]->constant_expression_value();
239 ir2_const
[1] = ir2
->operands
[1]->constant_expression_value();
241 if (ir2_const
[0] && ir2_const
[1])
245 reassociate_operands(ir1
, const_index
, ir2
, 1);
247 } else if (ir2_const
[1]) {
248 reassociate_operands(ir1
, const_index
, ir2
, 0);
252 if (reassociate_constant(ir1
, const_index
, constant
,
253 ir2
->operands
[0]->as_expression())) {
258 if (reassociate_constant(ir1
, const_index
, constant
,
259 ir2
->operands
[1]->as_expression())) {
267 /* When eliminating an expression and just returning one of its operands,
268 * we may need to swizzle that operand out to a vector if the expression was
272 ir_algebraic_visitor::swizzle_if_required(ir_expression
*expr
,
275 if (expr
->type
->is_vector() && operand
->type
->is_scalar()) {
276 return new(mem_ctx
) ir_swizzle(operand
, 0, 0, 0, 0,
277 expr
->type
->vector_elements
);
283 ir_algebraic_visitor::handle_expression(ir_expression
*ir
)
285 ir_constant
*op_const
[4] = {NULL
, NULL
, NULL
, NULL
};
286 ir_expression
*op_expr
[4] = {NULL
, NULL
, NULL
, NULL
};
289 assert(ir
->get_num_operands() <= 4);
290 for (i
= 0; i
< ir
->get_num_operands(); i
++) {
291 if (ir
->operands
[i
]->type
->is_matrix())
294 op_const
[i
] = ir
->operands
[i
]->constant_expression_value();
295 op_expr
[i
] = ir
->operands
[i
]->as_expression();
298 if (this->mem_ctx
== NULL
)
299 this->mem_ctx
= ralloc_parent(ir
);
301 switch (ir
->operation
) {
302 case ir_unop_bit_not
:
303 if (op_expr
[0] && op_expr
[0]->operation
== ir_unop_bit_not
)
304 return op_expr
[0]->operands
[0];
308 if (op_expr
[0] == NULL
)
311 switch (op_expr
[0]->operation
) {
314 return abs(op_expr
[0]->operands
[0]);
321 if (op_expr
[0] == NULL
)
324 if (op_expr
[0]->operation
== ir_unop_neg
) {
325 return op_expr
[0]->operands
[0];
330 if (op_expr
[0] == NULL
)
333 if (op_expr
[0]->operation
== ir_unop_log
) {
334 return op_expr
[0]->operands
[0];
339 if (op_expr
[0] == NULL
)
342 if (op_expr
[0]->operation
== ir_unop_exp
) {
343 return op_expr
[0]->operands
[0];
348 if (op_expr
[0] == NULL
)
351 if (op_expr
[0]->operation
== ir_unop_log2
) {
352 return op_expr
[0]->operands
[0];
355 if (!options
->EmitNoPow
&& op_expr
[0]->operation
== ir_binop_mul
) {
356 for (int log2_pos
= 0; log2_pos
< 2; log2_pos
++) {
357 ir_expression
*log2_expr
=
358 op_expr
[0]->operands
[log2_pos
]->as_expression();
360 if (log2_expr
&& log2_expr
->operation
== ir_unop_log2
) {
361 return new(mem_ctx
) ir_expression(ir_binop_pow
,
363 log2_expr
->operands
[0],
364 op_expr
[0]->operands
[1 - log2_pos
]);
371 if (op_expr
[0] == NULL
)
374 if (op_expr
[0]->operation
== ir_unop_exp2
) {
375 return op_expr
[0]->operands
[0];
379 case ir_unop_logic_not
: {
380 enum ir_expression_operation new_op
= ir_unop_logic_not
;
382 if (op_expr
[0] == NULL
)
385 switch (op_expr
[0]->operation
) {
386 case ir_binop_less
: new_op
= ir_binop_gequal
; break;
387 case ir_binop_greater
: new_op
= ir_binop_lequal
; break;
388 case ir_binop_lequal
: new_op
= ir_binop_greater
; break;
389 case ir_binop_gequal
: new_op
= ir_binop_less
; break;
390 case ir_binop_equal
: new_op
= ir_binop_nequal
; break;
391 case ir_binop_nequal
: new_op
= ir_binop_equal
; break;
392 case ir_binop_all_equal
: new_op
= ir_binop_any_nequal
; break;
393 case ir_binop_any_nequal
: new_op
= ir_binop_all_equal
; break;
396 /* The default case handler is here to silence a warning from GCC.
401 if (new_op
!= ir_unop_logic_not
) {
402 return new(mem_ctx
) ir_expression(new_op
,
404 op_expr
[0]->operands
[0],
405 op_expr
[0]->operands
[1]);
412 if (is_vec_zero(op_const
[0]))
413 return ir
->operands
[1];
414 if (is_vec_zero(op_const
[1]))
415 return ir
->operands
[0];
417 /* Reassociate addition of constants so that we can do constant
420 if (op_const
[0] && !op_const
[1])
421 reassociate_constant(ir
, 0, op_const
[0], op_expr
[1]);
422 if (op_const
[1] && !op_const
[0])
423 reassociate_constant(ir
, 1, op_const
[1], op_expr
[0]);
425 /* Recognize (v.x + v.y) + (v.z + v.w) as dot(v, 1.0) */
426 if (options
->OptimizeForAOS
) {
427 ir_expression
*expr
= try_replace_with_dot(op_expr
[0], op_expr
[1],
433 /* Replace (-x + y) * a + x and commutative variations with lrp(x, y, a).
436 * (x * -a) + (y * a) + x
437 * x + (x * -a) + (y * a)
438 * x * (1 - a) + y * a
441 for (int mul_pos
= 0; mul_pos
< 2; mul_pos
++) {
442 ir_expression
*mul
= op_expr
[mul_pos
];
444 if (!mul
|| mul
->operation
!= ir_binop_mul
)
447 /* Multiply found on one of the operands. Now check for an
448 * inner addition operation.
450 for (int inner_add_pos
= 0; inner_add_pos
< 2; inner_add_pos
++) {
451 ir_expression
*inner_add
=
452 mul
->operands
[inner_add_pos
]->as_expression();
454 if (!inner_add
|| inner_add
->operation
!= ir_binop_add
)
457 /* Inner addition found on one of the operands. Now check for
458 * one of the operands of the inner addition to be the negative
461 for (int neg_pos
= 0; neg_pos
< 2; neg_pos
++) {
463 inner_add
->operands
[neg_pos
]->as_expression();
465 if (!neg
|| neg
->operation
!= ir_unop_neg
)
468 ir_rvalue
*x_operand
= ir
->operands
[1 - mul_pos
];
470 if (!neg
->operands
[0]->equals(x_operand
))
473 ir_rvalue
*y_operand
= inner_add
->operands
[1 - neg_pos
];
474 ir_rvalue
*a_operand
= mul
->operands
[1 - inner_add_pos
];
476 if (x_operand
->type
!= y_operand
->type
||
477 x_operand
->type
!= a_operand
->type
)
480 return lrp(x_operand
, y_operand
, a_operand
);
488 if (is_vec_zero(op_const
[0]))
489 return neg(ir
->operands
[1]);
490 if (is_vec_zero(op_const
[1]))
491 return ir
->operands
[0];
495 if (is_vec_one(op_const
[0]))
496 return ir
->operands
[1];
497 if (is_vec_one(op_const
[1]))
498 return ir
->operands
[0];
500 if (is_vec_zero(op_const
[0]) || is_vec_zero(op_const
[1]))
501 return ir_constant::zero(ir
, ir
->type
);
503 if (is_vec_negative_one(op_const
[0]))
504 return neg(ir
->operands
[1]);
505 if (is_vec_negative_one(op_const
[1]))
506 return neg(ir
->operands
[0]);
509 /* Reassociate multiplication of constants so that we can do
512 if (op_const
[0] && !op_const
[1])
513 reassociate_constant(ir
, 0, op_const
[0], op_expr
[1]);
514 if (op_const
[1] && !op_const
[0])
515 reassociate_constant(ir
, 1, op_const
[1], op_expr
[0]);
520 if (is_vec_one(op_const
[0]) && ir
->type
->base_type
== GLSL_TYPE_FLOAT
) {
521 return new(mem_ctx
) ir_expression(ir_unop_rcp
,
522 ir
->operands
[1]->type
,
526 if (is_vec_one(op_const
[1]))
527 return ir
->operands
[0];
531 if (is_vec_zero(op_const
[0]) || is_vec_zero(op_const
[1]))
532 return ir_constant::zero(mem_ctx
, ir
->type
);
534 for (int i
= 0; i
< 2; i
++) {
538 unsigned components
[4] = { 0 }, count
= 0;
540 for (unsigned c
= 0; c
< op_const
[i
]->type
->vector_elements
; c
++) {
541 if (op_const
[i
]->value
.f
[c
] == 0.0)
544 components
[count
] = c
;
548 /* No channels had zero values; bail. */
549 if (count
>= op_const
[i
]->type
->vector_elements
)
552 ir_expression_operation op
= count
== 1 ?
553 ir_binop_mul
: ir_binop_dot
;
555 /* Swizzle both operands to remove the channels that were zero. */
557 ir_expression(op
, glsl_type::float_type
,
558 new(mem_ctx
) ir_swizzle(ir
->operands
[0],
560 new(mem_ctx
) ir_swizzle(ir
->operands
[1],
566 case ir_binop_lequal
:
567 case ir_binop_greater
:
568 case ir_binop_gequal
:
570 case ir_binop_nequal
:
571 for (int add_pos
= 0; add_pos
< 2; add_pos
++) {
572 ir_expression
*add
= op_expr
[add_pos
];
574 if (!add
|| add
->operation
!= ir_binop_add
)
577 ir_constant
*zero
= op_const
[1 - add_pos
];
578 if (!is_vec_zero(zero
))
581 return new(mem_ctx
) ir_expression(ir
->operation
,
583 neg(add
->operands
[1]));
587 case ir_binop_all_equal
:
588 case ir_binop_any_nequal
:
589 if (ir
->operands
[0]->type
->is_scalar() &&
590 ir
->operands
[1]->type
->is_scalar())
591 return new(mem_ctx
) ir_expression(ir
->operation
== ir_binop_all_equal
592 ? ir_binop_equal
: ir_binop_nequal
,
597 case ir_binop_rshift
:
598 case ir_binop_lshift
:
600 if (is_vec_zero(op_const
[0]))
601 return ir
->operands
[0];
603 if (is_vec_zero(op_const
[1]))
604 return ir
->operands
[0];
607 case ir_binop_logic_and
:
608 if (is_vec_one(op_const
[0])) {
609 return ir
->operands
[1];
610 } else if (is_vec_one(op_const
[1])) {
611 return ir
->operands
[0];
612 } else if (is_vec_zero(op_const
[0]) || is_vec_zero(op_const
[1])) {
613 return ir_constant::zero(mem_ctx
, ir
->type
);
614 } else if (op_expr
[0] && op_expr
[0]->operation
== ir_unop_logic_not
&&
615 op_expr
[1] && op_expr
[1]->operation
== ir_unop_logic_not
) {
617 * (not A) and (not B) === not (A or B)
619 return logic_not(logic_or(op_expr
[0]->operands
[0],
620 op_expr
[1]->operands
[0]));
621 } else if (ir
->operands
[0]->equals(ir
->operands
[1])) {
623 return ir
->operands
[0];
627 case ir_binop_logic_xor
:
628 if (is_vec_zero(op_const
[0])) {
629 return ir
->operands
[1];
630 } else if (is_vec_zero(op_const
[1])) {
631 return ir
->operands
[0];
632 } else if (is_vec_one(op_const
[0])) {
633 return logic_not(ir
->operands
[1]);
634 } else if (is_vec_one(op_const
[1])) {
635 return logic_not(ir
->operands
[0]);
636 } else if (ir
->operands
[0]->equals(ir
->operands
[1])) {
637 /* (a ^^ a) == false */
638 return ir_constant::zero(mem_ctx
, ir
->type
);
642 case ir_binop_logic_or
:
643 if (is_vec_zero(op_const
[0])) {
644 return ir
->operands
[1];
645 } else if (is_vec_zero(op_const
[1])) {
646 return ir
->operands
[0];
647 } else if (is_vec_one(op_const
[0]) || is_vec_one(op_const
[1])) {
648 ir_constant_data data
;
650 for (unsigned i
= 0; i
< 16; i
++)
653 return new(mem_ctx
) ir_constant(ir
->type
, &data
);
654 } else if (op_expr
[0] && op_expr
[0]->operation
== ir_unop_logic_not
&&
655 op_expr
[1] && op_expr
[1]->operation
== ir_unop_logic_not
) {
657 * (not A) or (not B) === not (A and B)
659 return logic_not(logic_and(op_expr
[0]->operands
[0],
660 op_expr
[1]->operands
[0]));
661 } else if (ir
->operands
[0]->equals(ir
->operands
[1])) {
663 return ir
->operands
[0];
669 if (is_vec_one(op_const
[0]))
673 if (is_vec_one(op_const
[1]))
674 return ir
->operands
[0];
676 /* pow(2,x) == exp2(x) */
677 if (is_vec_two(op_const
[0]))
678 return expr(ir_unop_exp2
, ir
->operands
[1]);
680 if (is_vec_two(op_const
[1])) {
681 ir_variable
*x
= new(ir
) ir_variable(ir
->operands
[1]->type
, "x",
683 base_ir
->insert_before(x
);
684 base_ir
->insert_before(assign(x
, ir
->operands
[0]));
692 if (ir
->type
->base_type
!= GLSL_TYPE_FLOAT
|| options
->EmitNoSat
)
695 /* Replace min(max) operations and its commutative combinations with
696 * a saturate operation
698 for (int op
= 0; op
< 2; op
++) {
699 ir_expression
*minmax
= op_expr
[op
];
700 ir_constant
*outer_const
= op_const
[1 - op
];
701 ir_expression_operation op_cond
= (ir
->operation
== ir_binop_max
) ?
702 ir_binop_min
: ir_binop_max
;
704 if (!minmax
|| !outer_const
|| (minmax
->operation
!= op_cond
))
707 /* Found a min(max) combination. Now try to see if its operands
708 * meet our conditions that we can do just a single saturate operation
710 for (int minmax_op
= 0; minmax_op
< 2; minmax_op
++) {
711 ir_rvalue
*inner_val_a
= minmax
->operands
[minmax_op
];
712 ir_rvalue
*inner_val_b
= minmax
->operands
[1 - minmax_op
];
714 if (!inner_val_a
|| !inner_val_b
)
717 /* Found a {min|max} ({max|min} (x, 0.0), 1.0) operation and its variations */
718 if ((outer_const
->is_one() && inner_val_a
->is_zero()) ||
719 (inner_val_a
->is_one() && outer_const
->is_zero()))
720 return saturate(inner_val_b
);
722 /* Found a {min|max} ({max|min} (x, 0.0), b) where b < 1.0
725 if (is_less_than_one(outer_const
) && inner_val_b
->is_zero())
726 return expr(ir_binop_min
, saturate(inner_val_a
), outer_const
);
728 if (!inner_val_b
->as_constant())
731 if (is_less_than_one(inner_val_b
->as_constant()) && outer_const
->is_zero())
732 return expr(ir_binop_min
, saturate(inner_val_a
), inner_val_b
);
734 /* Found a {min|max} ({max|min} (x, b), 1.0), where b > 0.0
737 if (outer_const
->is_one() && is_greater_than_zero(inner_val_b
->as_constant()))
738 return expr(ir_binop_max
, saturate(inner_val_a
), inner_val_b
);
739 if (inner_val_b
->as_constant()->is_one() && is_greater_than_zero(outer_const
))
740 return expr(ir_binop_max
, saturate(inner_val_a
), outer_const
);
747 if (op_expr
[0] && op_expr
[0]->operation
== ir_unop_rcp
)
748 return op_expr
[0]->operands
[0];
750 /* While ir_to_mesa.cpp will lower sqrt(x) to rcp(rsq(x)), it does so at
751 * its IR level, so we can always apply this transformation.
753 if (op_expr
[0] && op_expr
[0]->operation
== ir_unop_rsq
)
754 return sqrt(op_expr
[0]->operands
[0]);
756 /* As far as we know, all backends are OK with rsq. */
757 if (op_expr
[0] && op_expr
[0]->operation
== ir_unop_sqrt
) {
758 return rsq(op_expr
[0]->operands
[0]);
764 /* Operands are op0 * op1 + op2. */
765 if (is_vec_zero(op_const
[0]) || is_vec_zero(op_const
[1])) {
766 return ir
->operands
[2];
767 } else if (is_vec_zero(op_const
[2])) {
768 return mul(ir
->operands
[0], ir
->operands
[1]);
769 } else if (is_vec_one(op_const
[0])) {
770 return add(ir
->operands
[1], ir
->operands
[2]);
771 } else if (is_vec_one(op_const
[1])) {
772 return add(ir
->operands
[0], ir
->operands
[2]);
777 /* Operands are (x, y, a). */
778 if (is_vec_zero(op_const
[2])) {
779 return ir
->operands
[0];
780 } else if (is_vec_one(op_const
[2])) {
781 return ir
->operands
[1];
782 } else if (ir
->operands
[0]->equals(ir
->operands
[1])) {
783 return ir
->operands
[0];
784 } else if (is_vec_zero(op_const
[0])) {
785 return mul(ir
->operands
[1], ir
->operands
[2]);
786 } else if (is_vec_zero(op_const
[1])) {
787 unsigned op2_components
= ir
->operands
[2]->type
->vector_elements
;
788 ir_constant
*one
= new(mem_ctx
) ir_constant(1.0f
, op2_components
);
789 return mul(ir
->operands
[0], add(one
, neg(ir
->operands
[2])));
794 if (is_vec_one(op_const
[0]))
795 return ir
->operands
[1];
796 if (is_vec_zero(op_const
[0]))
797 return ir
->operands
[2];
808 ir_algebraic_visitor::handle_rvalue(ir_rvalue
**rvalue
)
813 ir_expression
*expr
= (*rvalue
)->as_expression();
814 if (!expr
|| expr
->operation
== ir_quadop_vector
)
817 ir_rvalue
*new_rvalue
= handle_expression(expr
);
818 if (new_rvalue
== *rvalue
)
821 /* If the expr used to be some vec OP scalar returning a vector, and the
822 * optimization gave us back a scalar, we still need to turn it into a
825 *rvalue
= swizzle_if_required(expr
, new_rvalue
);
827 this->progress
= true;
831 do_algebraic(exec_list
*instructions
, bool native_integers
,
832 const struct gl_shader_compiler_options
*options
)
834 ir_algebraic_visitor
v(native_integers
, options
);
836 visit_list_elements(&v
, instructions
);