nir/vtn: ImageSizeLod op can be applied to images
[mesa.git] / src / compiler / glsl / ir_validate.cpp
index 2ec5a3f73f73adcca33bbfe6db354e3eaf5a3fcd..c9d5ca1e3567f5671334c1e43e82eae4af0c93af 100644 (file)
@@ -35,7 +35,9 @@
 
 #include "ir.h"
 #include "ir_hierarchical_visitor.h"
+#include "util/debug.h"
 #include "util/hash_table.h"
+#include "util/macros.h"
 #include "util/set.h"
 #include "compiler/glsl_types.h"
 
@@ -45,8 +47,7 @@ class ir_validate : public ir_hierarchical_visitor {
 public:
    ir_validate()
    {
-      this->ir_set = _mesa_set_create(NULL, _mesa_hash_pointer,
-                                      _mesa_key_pointer_equal);
+      this->ir_set = _mesa_pointer_set_create(NULL);
 
       this->current_function = NULL;
 
@@ -68,11 +69,13 @@ public:
    virtual ir_visitor_status visit_enter(ir_function *ir);
    virtual ir_visitor_status visit_leave(ir_function *ir);
    virtual ir_visitor_status visit_enter(ir_function_signature *ir);
+   virtual ir_visitor_status visit_enter(ir_return *ir);
 
    virtual ir_visitor_status visit_leave(ir_expression *ir);
    virtual ir_visitor_status visit_leave(ir_swizzle *ir);
 
    virtual ir_visitor_status visit_enter(class ir_dereference_array *);
+   virtual ir_visitor_status visit_enter(class ir_dereference_record *);
 
    virtual ir_visitor_status visit_enter(ir_assignment *ir);
    virtual ir_visitor_status visit_enter(ir_call *ir);
@@ -95,6 +98,16 @@ ir_validate::visit(ir_dereference_variable *ir)
       abort();
    }
 
+   /* Compare types without arrays, because one side can be sized and
+    * the other unsized.
+    */
+   if (ir->var->type->without_array() != ir->type->without_array()) {
+      printf("ir_dereference_variable type is not equal to variable type: ");
+      ir->print();
+      printf("\n");
+      abort();
+   }
+
    if (_mesa_set_search(ir_set, ir->var) == NULL) {
       printf("ir_dereference_variable @ %p specifies undeclared variable "
             "`%s' @ %p\n",
@@ -120,13 +133,28 @@ ir_validate::visit_enter(class ir_dereference_array *ir)
       abort();
    }
 
+   if (ir->array->type->is_array()) {
+      if (ir->array->type->fields.array != ir->type) {
+         printf("ir_dereference_array type is not equal to the array "
+                "element type: ");
+         ir->print();
+         printf("\n");
+         abort();
+      }
+   } else if (ir->array->type->base_type != ir->type->base_type) {
+      printf("ir_dereference_array base types are not equal: ");
+      ir->print();
+      printf("\n");
+      abort();
+   }
+
    if (!ir->array_index->type->is_scalar()) {
       printf("ir_dereference_array @ %p does not have scalar index: %s\n",
              (void *) ir, ir->array_index->type->name);
       abort();
    }
 
-   if (!ir->array_index->type->is_integer()) {
+   if (!ir->array_index->type->is_integer_16_32()) {
       printf("ir_dereference_array @ %p does not have integer index: %s\n",
              (void *) ir, ir->array_index->type->name);
       abort();
@@ -135,6 +163,28 @@ ir_validate::visit_enter(class ir_dereference_array *ir)
    return visit_continue;
 }
 
+ir_visitor_status
+ir_validate::visit_enter(class ir_dereference_record *ir)
+{
+   if (!ir->record->type->is_struct() && !ir->record->type->is_interface()) {
+      printf("ir_dereference_record @ %p does not specify a record\n",
+             (void *) ir);
+      ir->print();
+      printf("\n");
+      abort();
+   }
+
+   if (ir->record->type->fields.structure[ir->field_idx].type != ir->type) {
+      printf("ir_dereference_record type is not equal to the record "
+             "field type: ");
+      ir->print();
+      printf("\n");
+      abort();
+   }
+
+   return visit_continue;
+}
+
 ir_visitor_status
 ir_validate::visit_enter(ir_discard *ir)
 {
@@ -233,24 +283,52 @@ ir_validate::visit_enter(ir_function_signature *ir)
    return visit_continue;
 }
 
+ir_visitor_status
+ir_validate::visit_enter(ir_return *ir)
+{
+   if (!this->current_function) {
+      printf("Return statement outside of a function\n");
+      abort();
+   }
+
+   return visit_continue;
+}
+
 ir_visitor_status
 ir_validate::visit_leave(ir_expression *ir)
 {
+   for (unsigned i = ir->num_operands; i < 4; i++) {
+      assert(ir->operands[i] == NULL);
+   }
+
+   for (unsigned i = 0; i < ir->num_operands; i++) {
+      assert(ir->operands[i] != NULL);
+   }
+
    switch (ir->operation) {
    case ir_unop_bit_not:
       assert(ir->operands[0]->type == ir->type);
       break;
    case ir_unop_logic_not:
-      assert(ir->type->base_type == GLSL_TYPE_BOOL);
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
+      assert(ir->type->is_boolean());
+      assert(ir->operands[0]->type->is_boolean());
       break;
 
    case ir_unop_neg:
+      assert(ir->type == ir->operands[0]->type);
+      break;
+
    case ir_unop_abs:
    case ir_unop_sign:
+      assert(ir->operands[0]->type->is_int_16_32_64() ||
+             ir->operands[0]->type->is_float_16_32_64());
+      assert(ir->type == ir->operands[0]->type);
+      break;
+
    case ir_unop_rcp:
    case ir_unop_rsq:
    case ir_unop_sqrt:
+      assert(ir->type->is_float_16_32_64());
       assert(ir->type == ir->operands[0]->type);
       break;
 
@@ -259,49 +337,58 @@ ir_validate::visit_leave(ir_expression *ir)
    case ir_unop_exp2:
    case ir_unop_log2:
    case ir_unop_saturate:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+      assert(ir->operands[0]->type->is_float_16_32());
       assert(ir->type == ir->operands[0]->type);
       break;
 
    case ir_unop_f2i:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
-      assert(ir->type->base_type == GLSL_TYPE_INT);
+      assert(ir->operands[0]->type->is_float_16_32());
+      assert(ir->type->is_int_16_32());
       break;
    case ir_unop_f2u:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
-      assert(ir->type->base_type == GLSL_TYPE_UINT);
+      assert(ir->operands[0]->type->is_float_16_32());
+      assert(ir->type->is_uint_16_32());
       break;
    case ir_unop_i2f:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
-      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+      assert(ir->operands[0]->type->is_int_16_32());
+      assert(ir->type->is_float_16_32());
       break;
    case ir_unop_f2b:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
-      assert(ir->type->base_type == GLSL_TYPE_BOOL);
+      assert(ir->operands[0]->type->is_float_16_32());
+      assert(ir->type->is_boolean());
+      break;
+   case ir_unop_f162b:
+      assert(ir->operands[0]->type->base_type ==
+             GLSL_TYPE_FLOAT16);
+      assert(ir->type->is_boolean());
       break;
    case ir_unop_b2f:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
-      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+      assert(ir->operands[0]->type->is_boolean());
+      assert(ir->type->is_float_16_32());
+      break;
+   case ir_unop_b2f16:
+      assert(ir->operands[0]->type->is_boolean());
+      assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
       break;
    case ir_unop_i2b:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
-      assert(ir->type->base_type == GLSL_TYPE_BOOL);
+      assert(ir->operands[0]->type->is_int_16_32());
+      assert(ir->type->is_boolean());
       break;
    case ir_unop_b2i:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
-      assert(ir->type->base_type == GLSL_TYPE_INT);
+      assert(ir->operands[0]->type->is_boolean());
+      assert(ir->type->is_int_16_32());
       break;
    case ir_unop_u2f:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
-      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+      assert(ir->operands[0]->type->is_uint_16_32());
+      assert(ir->type->is_float_16_32());
       break;
    case ir_unop_i2u:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
-      assert(ir->type->base_type == GLSL_TYPE_UINT);
+      assert(ir->operands[0]->type->is_int_16_32());
+      assert(ir->type->is_uint_16_32());
       break;
    case ir_unop_u2i:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
-      assert(ir->type->base_type == GLSL_TYPE_INT);
+      assert(ir->operands[0]->type->is_uint_16_32());
+      assert(ir->type->is_int_16_32());
       break;
    case ir_unop_bitcast_i2f:
       assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
@@ -320,13 +407,108 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->type->base_type == GLSL_TYPE_UINT);
       break;
 
+   case ir_unop_bitcast_u642d:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->is_double());
+      break;
+   case ir_unop_bitcast_i642d:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->is_double());
+      break;
+   case ir_unop_bitcast_d2u64:
+      assert(ir->operands[0]->type->is_double());
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_bitcast_d2i64:
+      assert(ir->operands[0]->type->is_double());
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_i642i:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->is_int_16_32());
+      break;
+   case ir_unop_u642i:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->is_int_16_32());
+      break;
+   case ir_unop_i642u:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->is_uint_16_32());
+      break;
+   case ir_unop_u642u:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->is_uint_16_32());
+      break;
+   case ir_unop_i642b:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->is_boolean());
+      break;
+   case ir_unop_i642f:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->is_float());
+      break;
+   case ir_unop_u642f:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->is_float());
+      break;
+   case ir_unop_i642d:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->is_double());
+      break;
+   case ir_unop_u642d:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->is_double());
+      break;
+   case ir_unop_i2i64:
+      assert(ir->operands[0]->type->is_int_16_32());
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_u2i64:
+      assert(ir->operands[0]->type->is_uint_16_32());
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_b2i64:
+      assert(ir->operands[0]->type->is_boolean());
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_f2i64:
+      assert(ir->operands[0]->type->is_float());
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_d2i64:
+      assert(ir->operands[0]->type->is_double());
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_i2u64:
+      assert(ir->operands[0]->type->is_int_16_32());
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_u2u64:
+      assert(ir->operands[0]->type->is_uint_16_32());
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_f2u64:
+      assert(ir->operands[0]->type->is_float());
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_d2u64:
+      assert(ir->operands[0]->type->is_double());
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
+   case ir_unop_u642i64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT64);
+      assert(ir->type->base_type == GLSL_TYPE_INT64);
+      break;
+   case ir_unop_i642u64:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT64);
+      assert(ir->type->base_type == GLSL_TYPE_UINT64);
+      break;
    case ir_unop_trunc:
    case ir_unop_round_even:
    case ir_unop_ceil:
    case ir_unop_floor:
    case ir_unop_fract:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT ||
-             ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->operands[0]->type->is_float_16_32_64());
       assert(ir->operands[0]->type == ir->type);
       break;
    case ir_unop_sin:
@@ -337,7 +519,7 @@ ir_validate::visit_leave(ir_expression *ir)
    case ir_unop_dFdy:
    case ir_unop_dFdy_coarse:
    case ir_unop_dFdy_fine:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
+      assert(ir->operands[0]->type->is_float_16_32());
       assert(ir->operands[0]->type == ir->type);
       break;
 
@@ -359,6 +541,26 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[0]->type == glsl_type::uvec2_type);
       break;
 
+   case ir_unop_pack_int_2x32:
+      assert(ir->type == glsl_type::int64_t_type);
+      assert(ir->operands[0]->type == glsl_type::ivec2_type);
+      break;
+
+   case ir_unop_pack_uint_2x32:
+      assert(ir->type == glsl_type::uint64_t_type);
+      assert(ir->operands[0]->type == glsl_type::uvec2_type);
+      break;
+
+   case ir_unop_pack_sampler_2x32:
+      assert(ir->type->is_sampler());
+      assert(ir->operands[0]->type == glsl_type::uvec2_type);
+      break;
+
+   case ir_unop_pack_image_2x32:
+      assert(ir->type->is_image());
+      assert(ir->operands[0]->type == glsl_type::uvec2_type);
+      break;
+
    case ir_unop_unpack_snorm_2x16:
    case ir_unop_unpack_unorm_2x16:
    case ir_unop_unpack_half_2x16:
@@ -377,26 +579,47 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[0]->type == glsl_type::double_type);
       break;
 
+   case ir_unop_unpack_int_2x32:
+      assert(ir->type == glsl_type::ivec2_type);
+      assert(ir->operands[0]->type == glsl_type::int64_t_type);
+      break;
+
+   case ir_unop_unpack_uint_2x32:
+      assert(ir->type == glsl_type::uvec2_type);
+      assert(ir->operands[0]->type == glsl_type::uint64_t_type);
+      break;
+
+   case ir_unop_unpack_sampler_2x32:
+      assert(ir->type == glsl_type::uvec2_type);
+      assert(ir->operands[0]->type->is_sampler());
+      break;
+
+   case ir_unop_unpack_image_2x32:
+      assert(ir->type == glsl_type::uvec2_type);
+      assert(ir->operands[0]->type->is_image());
+      break;
+
    case ir_unop_bitfield_reverse:
       assert(ir->operands[0]->type == ir->type);
-      assert(ir->type->is_integer());
+      assert(ir->type->is_integer_32());
       break;
 
    case ir_unop_bit_count:
    case ir_unop_find_msb:
    case ir_unop_find_lsb:
       assert(ir->operands[0]->type->vector_elements == ir->type->vector_elements);
-      assert(ir->operands[0]->type->is_integer());
-      assert(ir->type->base_type == GLSL_TYPE_INT);
+      assert(ir->operands[0]->type->is_integer_16_32());
+      assert(ir->type->is_int_16_32());
       break;
 
-   case ir_unop_noise:
-      /* XXX what can we assert here? */
+   case ir_unop_clz:
+      assert(ir->operands[0]->type == ir->type);
+      assert(ir->type->is_uint_16_32());
       break;
 
    case ir_unop_interpolate_at_centroid:
       assert(ir->operands[0]->type == ir->type);
-      assert(ir->operands[0]->type->is_float());
+      assert(ir->operands[0]->type->is_float_16_32());
       break;
 
    case ir_unop_get_buffer_size:
@@ -411,48 +634,79 @@ ir_validate::visit_leave(ir_expression *ir)
       break;
 
    case ir_unop_d2f:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
-      assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+      assert(ir->operands[0]->type->is_double());
+      assert(ir->type->is_float());
       break;
    case ir_unop_f2d:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT);
-      assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->operands[0]->type->is_float());
+      assert(ir->type->is_double());
+      break;
+   case ir_unop_f162f:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT16);
+      assert(ir->type->is_float());
+      break;
+   case ir_unop_f2f16:
+   case ir_unop_f2fmp:
+      assert(ir->operands[0]->type->is_float());
+      assert(ir->type->base_type == GLSL_TYPE_FLOAT16);
+      break;
+   case ir_unop_i2i:
+      assert(ir->operands[0]->type->is_int_16_32());
+      assert(ir->type->is_int_16_32());
+      assert(ir->type->base_type != ir->operands[0]->type->base_type);
+      break;
+   case ir_unop_u2u:
+      assert(ir->operands[0]->type->is_uint_16_32());
+      assert(ir->type->is_uint_16_32());
+      assert(ir->type->base_type != ir->operands[0]->type->base_type);
+      break;
+   case ir_unop_i2imp:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
+      assert(ir->type->base_type == GLSL_TYPE_INT16);
+      break;
+   case ir_unop_u2ump:
+      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
+      assert(ir->type->base_type == GLSL_TYPE_UINT16);
       break;
    case ir_unop_d2i:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
-      assert(ir->type->base_type == GLSL_TYPE_INT);
+      assert(ir->operands[0]->type->is_double());
+      assert(ir->type->is_int_16_32());
       break;
    case ir_unop_i2d:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT);
-      assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->operands[0]->type->is_int_16_32());
+      assert(ir->type->is_double());
       break;
    case ir_unop_d2u:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
-      assert(ir->type->base_type == GLSL_TYPE_UINT);
+      assert(ir->operands[0]->type->is_double());
+      assert(ir->type->is_uint_16_32());
       break;
    case ir_unop_u2d:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT);
-      assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->operands[0]->type->is_uint_16_32());
+      assert(ir->type->is_double());
       break;
    case ir_unop_d2b:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
-      assert(ir->type->base_type == GLSL_TYPE_BOOL);
+      assert(ir->operands[0]->type->is_double());
+      assert(ir->type->is_boolean());
       break;
 
    case ir_unop_frexp_sig:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT ||
-             ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
-      assert(ir->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->operands[0]->type->is_float_32_64());
+      assert(ir->type->is_double());
       break;
    case ir_unop_frexp_exp:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT ||
-             ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->operands[0]->type->is_float_32_64());
       assert(ir->type->base_type == GLSL_TYPE_INT);
       break;
    case ir_unop_subroutine_to_int:
       assert(ir->operands[0]->type->base_type == GLSL_TYPE_SUBROUTINE);
       assert(ir->type->base_type == GLSL_TYPE_INT);
       break;
+
+   case ir_unop_atan:
+      assert(ir->operands[0]->type->is_float_16_32_64());
+      assert(ir->type == ir->operands[0]->type);
+      break;
+
    case ir_binop_add:
    case ir_binop_sub:
    case ir_binop_mul:
@@ -464,6 +718,17 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[0]->type->base_type ==
              ir->operands[1]->type->base_type);
 
+      if (ir->operation == ir_binop_mul &&
+          (ir->type->base_type == GLSL_TYPE_UINT64 ||
+           ir->type->base_type == GLSL_TYPE_INT64) &&
+          (ir->operands[0]->type->is_int_16_32()||
+           ir->operands[1]->type->is_int_16_32()||
+           ir->operands[0]->type->is_uint_16_32() ||
+           ir->operands[1]->type->is_uint_16_32())) {
+         assert(ir->operands[0]->type == ir->operands[1]->type);
+         break;
+      }
+
       if (ir->operands[0]->type->is_scalar())
         assert(ir->operands[1]->type == ir->type);
       else if (ir->operands[1]->type->is_scalar())
@@ -475,10 +740,28 @@ ir_validate::visit_leave(ir_expression *ir)
       }
       break;
 
+   case ir_binop_abs_sub:
+      assert(ir->operands[0]->type == ir->operands[1]->type);
+      assert(ir->operands[0]->type->is_integer_16_32_64());
+      assert(ir->operands[0]->type->vector_elements ==
+             ir->type->vector_elements);
+      assert(ir->type->is_uint_16_32_64());
+      break;
+
+   case ir_binop_add_sat:
+   case ir_binop_sub_sat:
+   case ir_binop_avg:
+   case ir_binop_avg_round:
+      assert(ir->type == ir->operands[0]->type);
+      assert(ir->type == ir->operands[1]->type);
+      assert(ir->type->is_integer_16_32_64());
+      break;
+
+   case ir_binop_mul_32x16:
    case ir_binop_imul_high:
       assert(ir->type == ir->operands[0]->type);
       assert(ir->type == ir->operands[1]->type);
-      assert(ir->type->is_integer());
+      assert(ir->type->is_integer_32());
       break;
 
    case ir_binop_carry:
@@ -489,8 +772,6 @@ ir_validate::visit_leave(ir_expression *ir)
       break;
 
    case ir_binop_less:
-   case ir_binop_greater:
-   case ir_binop_lequal:
    case ir_binop_gequal:
    case ir_binop_equal:
    case ir_binop_nequal:
@@ -499,7 +780,7 @@ ir_validate::visit_leave(ir_expression *ir)
        * comparison on scalar or vector types and return a boolean scalar or
        * vector type of the same size.
        */
-      assert(ir->type->base_type == GLSL_TYPE_BOOL);
+      assert(ir->type->is_boolean());
       assert(ir->operands[0]->type == ir->operands[1]->type);
       assert(ir->operands[0]->type->is_vector()
             || ir->operands[0]->type->is_scalar());
@@ -518,8 +799,8 @@ ir_validate::visit_leave(ir_expression *ir)
 
    case ir_binop_lshift:
    case ir_binop_rshift:
-      assert(ir->operands[0]->type->is_integer() &&
-             ir->operands[1]->type->is_integer());
+      assert(ir->operands[0]->type->is_integer_16_32_64() &&
+             ir->operands[1]->type->is_integer_16_32());
       if (ir->operands[0]->type->is_scalar()) {
           assert(ir->operands[1]->type->is_scalar());
       }
@@ -536,7 +817,7 @@ ir_validate::visit_leave(ir_expression *ir)
    case ir_binop_bit_or:
        assert(ir->operands[0]->type->base_type ==
               ir->operands[1]->type->base_type);
-       assert(ir->type->is_integer());
+       assert(ir->type->is_integer_16_32_64());
        if (ir->operands[0]->type->is_vector() &&
            ir->operands[1]->type->is_vector()) {
            assert(ir->operands[0]->type->vector_elements ==
@@ -547,16 +828,16 @@ ir_validate::visit_leave(ir_expression *ir)
    case ir_binop_logic_and:
    case ir_binop_logic_xor:
    case ir_binop_logic_or:
-      assert(ir->type->base_type == GLSL_TYPE_BOOL);
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
-      assert(ir->operands[1]->type->base_type == GLSL_TYPE_BOOL);
+      assert(ir->type->is_boolean());
+      assert(ir->operands[0]->type->is_boolean());
+      assert(ir->operands[1]->type->is_boolean());
       break;
 
    case ir_binop_dot:
       assert(ir->type == glsl_type::float_type ||
-             ir->type == glsl_type::double_type);
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT ||
-             ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+             ir->type == glsl_type::double_type ||
+             ir->type == glsl_type::float16_t_type);
+      assert(ir->operands[0]->type->is_float_16_32_64());
       assert(ir->operands[0]->type->is_vector());
       assert(ir->operands[0]->type == ir->operands[1]->type);
       break;
@@ -569,8 +850,7 @@ ir_validate::visit_leave(ir_expression *ir)
 
    case ir_binop_ldexp:
       assert(ir->operands[0]->type == ir->type);
-      assert(ir->operands[0]->type->is_float() ||
-             ir->operands[0]->type->is_double());
+      assert(ir->operands[0]->type->is_float_32_64());
       assert(ir->operands[1]->type->base_type == GLSL_TYPE_INT);
       assert(ir->operands[0]->type->components() ==
              ir->operands[1]->type->components());
@@ -579,48 +859,54 @@ ir_validate::visit_leave(ir_expression *ir)
    case ir_binop_vector_extract:
       assert(ir->operands[0]->type->is_vector());
       assert(ir->operands[1]->type->is_scalar()
-             && ir->operands[1]->type->is_integer());
+             && ir->operands[1]->type->is_integer_16_32());
       break;
 
    case ir_binop_interpolate_at_offset:
       assert(ir->operands[0]->type == ir->type);
-      assert(ir->operands[0]->type->is_float());
+      assert(ir->operands[0]->type->is_float_16_32());
       assert(ir->operands[1]->type->components() == 2);
-      assert(ir->operands[1]->type->is_float());
+      assert(ir->operands[1]->type->is_float_16_32());
       break;
 
    case ir_binop_interpolate_at_sample:
       assert(ir->operands[0]->type == ir->type);
-      assert(ir->operands[0]->type->is_float());
-      assert(ir->operands[1]->type == glsl_type::int_type);
+      assert(ir->operands[0]->type->is_float_16_32());
+      assert(ir->operands[1]->type == glsl_type::int_type ||
+             ir->operands[1]->type == glsl_type::int16_t_type);
+      break;
+
+   case ir_binop_atan2:
+      assert(ir->operands[0]->type->is_float_16_32_64());
+      assert(ir->operands[1]->type == ir->operands[0]->type);
+      assert(ir->type == ir->operands[0]->type);
       break;
 
    case ir_triop_fma:
-      assert(ir->type->base_type == GLSL_TYPE_FLOAT ||
-             ir->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->type->is_float_16_32_64());
       assert(ir->type == ir->operands[0]->type);
       assert(ir->type == ir->operands[1]->type);
       assert(ir->type == ir->operands[2]->type);
       break;
 
    case ir_triop_lrp:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_FLOAT ||
-             ir->operands[0]->type->base_type == GLSL_TYPE_DOUBLE);
+      assert(ir->operands[0]->type->is_float_16_32_64());
       assert(ir->operands[0]->type == ir->operands[1]->type);
       assert(ir->operands[2]->type == ir->operands[0]->type ||
              ir->operands[2]->type == glsl_type::float_type ||
-             ir->operands[2]->type == glsl_type::double_type);
+             ir->operands[2]->type == glsl_type::double_type ||
+             ir->operands[2]->type == glsl_type::float16_t_type);
       break;
 
    case ir_triop_csel:
-      assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
+      assert(ir->operands[0]->type->is_boolean());
       assert(ir->type->vector_elements == ir->operands[0]->type->vector_elements);
       assert(ir->type == ir->operands[1]->type);
       assert(ir->type == ir->operands[2]->type);
       break;
 
    case ir_triop_bitfield_extract:
-      assert(ir->type->is_integer());
+      assert(ir->type->is_integer_16_32());
       assert(ir->operands[0]->type == ir->type);
       assert(ir->operands[1]->type == ir->type);
       assert(ir->operands[2]->type == ir->type);
@@ -631,12 +917,12 @@ ir_validate::visit_leave(ir_expression *ir)
       assert(ir->operands[1]->type->is_scalar());
       assert(ir->operands[0]->type->base_type == ir->operands[1]->type->base_type);
       assert(ir->operands[2]->type->is_scalar()
-             && ir->operands[2]->type->is_integer());
+             && ir->operands[2]->type->is_integer_16_32());
       assert(ir->type == ir->operands[0]->type);
       break;
 
    case ir_quadop_bitfield_insert:
-      assert(ir->type->is_integer());
+      assert(ir->type->is_integer_16_32());
       assert(ir->operands[0]->type == ir->type);
       assert(ir->operands[1]->type == ir->type);
       assert(ir->operands[2]->type == ir->type);
@@ -727,7 +1013,7 @@ ir_validate::visit(ir_variable *ir)
     * to be out of bounds.
     */
    if (ir->type->array_size() > 0) {
-      if (ir->data.max_array_access >= ir->type->length) {
+      if (ir->data.max_array_access >= (int)ir->type->length) {
         printf("ir_variable has maximum access out of bounds (%d vs %d)\n",
                ir->data.max_array_access, ir->type->length - 1);
         ir->print();
@@ -743,13 +1029,14 @@ ir_validate::visit(ir_variable *ir)
       const glsl_struct_field *fields =
          ir->get_interface_type()->fields.structure;
       for (unsigned i = 0; i < ir->get_interface_type()->length; i++) {
-         if (fields[i].type->array_size() > 0) {
-            const unsigned *const max_ifc_array_access =
+         if (fields[i].type->array_size() > 0 &&
+             !fields[i].implicit_sized_array) {
+            const int *const max_ifc_array_access =
                ir->get_max_ifc_array_access();
 
             assert(max_ifc_array_access != NULL);
 
-            if (max_ifc_array_access[i] >= fields[i].type->length) {
+            if (max_ifc_array_access[i] >= (int)fields[i].type->length) {
                printf("ir_variable has maximum access out of bounds for "
                       "field %s (%d vs %d)\n", fields[i].name,
                       max_ifc_array_access[i], fields[i].type->length);
@@ -805,6 +1092,15 @@ ir_validate::visit_enter(ir_assignment *ir)
       }
    }
 
+   if (lhs->type->base_type != ir->rhs->type->base_type) {
+      printf("Assignment LHS and RHS base types are different:\n");
+      lhs->print();
+      printf("\n");
+      ir->rhs->print();
+      printf("\n");
+      abort();
+   }
+
    this->validate_ir(ir, this->data_enter);
 
    return visit_continue;
@@ -831,8 +1127,8 @@ ir_validate::visit_enter(ir_call *ir)
       abort();
    }
 
-   const exec_node *formal_param_node = callee->parameters.head;
-   const exec_node *actual_param_node = ir->actual_parameters.head;
+   const exec_node *formal_param_node = callee->parameters.get_head_raw();
+   const exec_node *actual_param_node = ir->actual_parameters.get_head_raw();
    while (true) {
       if (formal_param_node->is_tail_sentinel()
           != actual_param_node->is_tail_sentinel()) {
@@ -885,7 +1181,7 @@ ir_validate::validate_ir(ir_instruction *ir, void *data)
    _mesa_set_add(ir_set, ir);
 }
 
-void
+static void
 check_node_type(ir_instruction *ir, void *data)
 {
    (void) data;
@@ -906,7 +1202,10 @@ validate_ir_tree(exec_list *instructions)
     * and it's half composed of assert()s anyway which wouldn't do
     * anything.
     */
-#ifdef DEBUG
+#ifndef DEBUG
+   if (!env_var_as_boolean("GLSL_VALIDATE", false))
+      return;
+#endif
    ir_validate v;
 
    v.run(instructions);
@@ -914,5 +1213,4 @@ validate_ir_tree(exec_list *instructions)
    foreach_in_list(ir_instruction, ir, instructions) {
       visit_tree(ir, check_node_type, NULL);
    }
-#endif
 }