intel/compiler: Make decision based on source type instead of opcode

This patch restructure code a little bit to check if source can be
represented as immediate operand. This is a foundation for next patch
which add checks for integer operand as well.

Suggested-by: Jason Ekstrand <jason@jlekstrand.net>
Signed-off-by: Sagar Ghuge <sagar.ghuge@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11596>
This commit is contained in:
Sagar Ghuge
2021-07-07 18:10:19 -07:00
committed by Marge Bot
parent 705285b9f4
commit cde9ca616d

View File

@@ -336,20 +336,41 @@ representable_as_hf(float f, uint16_t *hf)
}
static bool
represent_src_as_imm(const struct intel_device_info *devinfo,
fs_reg *src)
supports_src_as_imm(const struct intel_device_info *devinfo, enum opcode op)
{
switch (op) {
case BRW_OPCODE_MAD:
return devinfo->ver == 12 && devinfo->verx10 < 125;
default:
return false;
}
}
static bool
can_promote_src_as_imm(const struct intel_device_info *devinfo, fs_inst *inst,
unsigned src_idx)
{
/* Experiment shows that we can only support src0 as immediate */
if (src_idx != 0)
return false;
if (!supports_src_as_imm(devinfo, inst->opcode))
return false;
/* TODO - Fix the codepath below to use a bfloat16 immediate on XeHP,
* since HF/F mixed mode has been removed from the hardware.
*/
if (devinfo->ver == 12 && devinfo->verx10 < 125) {
switch(inst->src[src_idx].type) {
case BRW_REGISTER_TYPE_F: {
uint16_t hf;
if (representable_as_hf(src->f, &hf)) {
*src = retype(brw_imm_uw(hf), BRW_REGISTER_TYPE_HF);
if (representable_as_hf(inst->src[src_idx].f, &hf)) {
inst->src[src_idx] = retype(brw_imm_uw(hf), BRW_REGISTER_TYPE_HF);
return true;
}
}
return false;
default:
return false;
}
}
bool
@@ -375,17 +396,12 @@ 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;
if (can_promote_src_as_imm(devinfo, inst, i))
continue;
}
char data[8];
brw_reg_type type;