glsl: make use of glsl_type::is_double()
[mesa.git] / src / compiler / glsl / opt_algebraic.cpp
index 2829a78251427afa9f0c775bd0d1081066cac1ef..3662e8b26996aa32c4be11f68d2566fe57e816be 100644 (file)
@@ -472,6 +472,34 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       }
       break;
 
+      /* This macro CANNOT use the do { } while(true) mechanism because
+       * then the breaks apply to the loop instead of the switch!
+       */
+#define HANDLE_PACK_UNPACK_INVERSE(inverse_operation)                   \
+      {                                                                 \
+         ir_expression *const op = ir->operands[0]->as_expression();    \
+         if (op == NULL)                                                \
+            break;                                                      \
+         if (op->operation == (inverse_operation))                      \
+            return op->operands[0];                                     \
+         break;                                                         \
+      }
+
+   case ir_unop_unpack_uint_2x32:
+      HANDLE_PACK_UNPACK_INVERSE(ir_unop_pack_uint_2x32);
+   case ir_unop_pack_uint_2x32:
+      HANDLE_PACK_UNPACK_INVERSE(ir_unop_unpack_uint_2x32);
+   case ir_unop_unpack_int_2x32:
+      HANDLE_PACK_UNPACK_INVERSE(ir_unop_pack_int_2x32);
+   case ir_unop_pack_int_2x32:
+      HANDLE_PACK_UNPACK_INVERSE(ir_unop_unpack_int_2x32);
+   case ir_unop_unpack_double_2x32:
+      HANDLE_PACK_UNPACK_INVERSE(ir_unop_pack_double_2x32);
+   case ir_unop_pack_double_2x32:
+      HANDLE_PACK_UNPACK_INVERSE(ir_unop_unpack_double_2x32);
+
+#undef HANDLE_PACK_UNPACK_INVERSE
+
    case ir_binop_add:
       if (is_vec_zero(op_const[0]))
         return ir->operands[1];
@@ -622,7 +650,7 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
    case ir_binop_div:
       if (is_vec_one(op_const[0]) && (
                 ir->type->base_type == GLSL_TYPE_FLOAT ||
-                ir->type->base_type == GLSL_TYPE_DOUBLE)) {
+                ir->type->is_double())) {
         return new(mem_ctx) ir_expression(ir_unop_rcp,
                                           ir->operands[1]->type,
                                           ir->operands[1],