From cde9ca616d7bd2ecdf3281f087e9c7acccc85192 Mon Sep 17 00:00:00 2001 From: Sagar Ghuge Date: Wed, 7 Jul 2021 18:10:19 -0700 Subject: [PATCH] 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 Signed-off-by: Sagar Ghuge Reviewed-by: Jason Ekstrand Part-of: --- .../compiler/brw_fs_combine_constants.cpp | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/intel/compiler/brw_fs_combine_constants.cpp b/src/intel/compiler/brw_fs_combine_constants.cpp index 50ddb7e645f..ff5f1ec9d18 100644 --- a/src/intel/compiler/brw_fs_combine_constants.cpp +++ b/src/intel/compiler/brw_fs_combine_constants.cpp @@ -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;