diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp index 020a5cb5023..3aaac3c8cb8 100644 --- a/src/intel/compiler/brw_fs.cpp +++ b/src/intel/compiler/brw_fs.cpp @@ -2822,6 +2822,39 @@ fs_visitor::opt_algebraic() progress = true; } break; + case BRW_OPCODE_SHL: + if (inst->src[0].file == IMM && inst->src[1].file == IMM) { + /* It's not currently possible to generate this, and this constant + * folding does not handle it. + */ + assert(!inst->saturate); + + fs_reg result; + + switch (type_sz(inst->src[0].type)) { + case 2: + result = brw_imm_uw(0x0ffff & (inst->src[0].ud << (inst->src[1].ud & 0x1f))); + break; + case 4: + result = brw_imm_ud(inst->src[0].ud << (inst->src[1].ud & 0x1f)); + break; + case 8: + result = brw_imm_uq(inst->src[0].u64 << (inst->src[1].ud & 0x3f)); + break; + default: + /* Just in case a future platform re-enables B or UB types. */ + unreachable("Invalid source size."); + } + + inst->opcode = BRW_OPCODE_MOV; + inst->src[0] = retype(result, inst->dst.type); + inst->src[1] = reg_undef; + inst->sources = 1; + + progress = true; + } + break; + case SHADER_OPCODE_BROADCAST: if (is_uniform(inst->src[0])) { inst->opcode = BRW_OPCODE_MOV; diff --git a/src/intel/compiler/brw_fs_copy_propagation.cpp b/src/intel/compiler/brw_fs_copy_propagation.cpp index 9b14b255e10..d16077c3c13 100644 --- a/src/intel/compiler/brw_fs_copy_propagation.cpp +++ b/src/intel/compiler/brw_fs_copy_propagation.cpp @@ -912,7 +912,6 @@ fs_visitor::try_constant_propagate(fs_inst *inst, acp_entry *entry) FALLTHROUGH; case BRW_OPCODE_BFI1: case BRW_OPCODE_ASR: - case BRW_OPCODE_SHL: case BRW_OPCODE_SHR: case BRW_OPCODE_SUBB: if (i == 1) { @@ -921,6 +920,17 @@ fs_visitor::try_constant_propagate(fs_inst *inst, acp_entry *entry) } break; + case BRW_OPCODE_SHL: + /* Only constant propagate into src0 if src1 is also constant. In that + * specific case, constant folding will eliminate the instruction. + */ + if ((i == 0 && inst->src[1].file == IMM) || + i == 1) { + inst->src[i] = val; + progress = true; + } + break; + case BRW_OPCODE_MACH: case BRW_OPCODE_MUL: case SHADER_OPCODE_MULH: