intel/compiler: Don't left-shift by >= the number of bits of the type
[mesa.git] / src / intel / compiler / brw_fs_combine_constants.cpp
index 8d16be4c4bb44cf95e7ba5665bc3d58aafb7224e..2a28351beef7ff18295f570be90713aabebdc2bf 100644 (file)
@@ -232,7 +232,7 @@ get_constant_value(const struct gen_device_info *devinfo,
       break;
    }
    case BRW_REGISTER_TYPE_Q: {
-      int64_t val = !can_do_source_mods ? src->d64 : abs(src->d64);
+      int64_t val = !can_do_source_mods ? src->d64 : llabs(src->d64);
       memcpy(out, &val, 8);
       break;
    }
@@ -289,7 +289,7 @@ get_alignment_for_imm(const struct imm *imm)
 }
 
 static bool
-needs_negate(const struct fs_reg *reg, const struct imm *imm)
+needs_negate(const fs_reg *reg, const struct imm *imm)
 {
    switch (reg->type) {
    case BRW_REGISTER_TYPE_DF:
@@ -313,6 +313,36 @@ needs_negate(const struct fs_reg *reg, const struct imm *imm)
    };
 }
 
+static bool
+representable_as_hf(float f, uint16_t *hf)
+{
+   union fi u;
+   uint16_t h = _mesa_float_to_half(f);
+   u.f = _mesa_half_to_float(h);
+
+   if (u.f == f) {
+      *hf = h;
+      return true;
+   }
+
+   return false;
+}
+
+static bool
+represent_src_as_imm(const struct gen_device_info *devinfo,
+                     fs_reg *src)
+{
+   /* TODO : consider specific platforms also */
+   if (devinfo->gen == 12) {
+      uint16_t hf;
+      if (representable_as_hf(src->f, &hf)) {
+         *src = retype(brw_imm_uw(hf), BRW_REGISTER_TYPE_HF);
+         return true;
+      }
+   }
+   return false;
+}
+
 bool
 fs_visitor::opt_combine_constants()
 {
@@ -336,10 +366,18 @@ fs_visitor::opt_combine_constants()
       if (!could_coissue(devinfo, inst) && !must_promote_imm(devinfo, inst))
          continue;
 
+      bool represented_as_imm = false;
       for (int i = 0; i < inst->sources; i++) {
          if (inst->src[i].file != IMM)
             continue;
 
+         if (!represented_as_imm && i == 0 &&
+             inst->opcode == BRW_OPCODE_MAD &&
+             represent_src_as_imm(devinfo, &inst->src[i])) {
+            represented_as_imm = true;
+            continue;
+         }
+
          char data[8];
          brw_reg_type type;
          if (!get_constant_value(devinfo, inst, i, data, &type))
@@ -442,7 +480,7 @@ fs_visitor::opt_combine_constants()
 
       reg.offset += imm->size * width;
    }
-   promoted_constants = table.len;
+   shader_stats.promoted_constants = table.len;
 
    /* Rewrite the immediate sources to refer to the new GRFs. */
    for (int i = 0; i < table.len; i++) {