if (is_vec_zero(op_const[1]))
return ir->operands[0];
+ /* Replace (x + (-x)) with constant 0 */
+ for (int i = 0; i < 2; i++) {
+ if (op_expr[i]) {
+ if (op_expr[i]->operation == ir_unop_neg) {
+ ir_rvalue *other = ir->operands[(i + 1) % 2];
+ if (other && op_expr[i]->operands[0]->equals(other)) {
+ return ir_constant::zero(ir, ir->type);
+ }
+ }
+ }
+ }
+
/* Reassociate addition of constants so that we can do constant
* folding.
*/
ir_rvalue *y_operand = inner_add->operands[1 - neg_pos];
ir_rvalue *a_operand = mul->operands[1 - inner_add_pos];
- if (x_operand->type != y_operand->type ||
+ if (!x_operand->type->is_float_16_32_64() ||
+ x_operand->type != y_operand->type ||
x_operand->type != a_operand->type)
continue;
ir_constant *one;
switch (ir->type->base_type) {
+ case GLSL_TYPE_FLOAT16:
+ one = new(mem_ctx) ir_constant(float16_t::one(), op2_components);
+ break;
case GLSL_TYPE_FLOAT:
one = new(mem_ctx) ir_constant(1.0f, op2_components);
break;