mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 09:38:07 +02:00
brw/algebraic: Fix ADD constant folding
Some callers of brw_constant_fold_instruction depend on the result being
a MOV of immediate when progress is made. Previously `ADD dst:D src0:D
0:D` would be converted to `MOV dst:D src0:D`. There was also no
handling for `ADD dst:D imm0:D imm1:D`.
Reviewed-by: Caio Oliveira <caio.oliveira@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Fixes: 2cc1575a31 ("brw/algebraic: Refactor constant folding out of brw_fs_opt_algebraic")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32436>
This commit is contained in:
parent
191d7c6cb6
commit
086e83ccd9
1 changed files with 21 additions and 14 deletions
|
|
@ -71,26 +71,22 @@ brw_constant_fold_instruction(const intel_device_info *devinfo, fs_inst *inst)
|
|||
|
||||
switch (inst->opcode) {
|
||||
case BRW_OPCODE_ADD:
|
||||
if (inst->src[1].file != IMM)
|
||||
if (inst->src[0].file != IMM || inst->src[1].file != IMM)
|
||||
break;
|
||||
|
||||
if (brw_type_is_int(inst->src[1].type) &&
|
||||
inst->src[1].is_zero()) {
|
||||
inst->opcode = BRW_OPCODE_MOV;
|
||||
inst->resize_sources(1);
|
||||
progress = true;
|
||||
break;
|
||||
}
|
||||
if (brw_type_is_int(inst->src[0].type)) {
|
||||
const uint64_t src0 = src_as_uint(inst->src[0]);
|
||||
const uint64_t src1 = src_as_uint(inst->src[1]);
|
||||
|
||||
if (inst->src[0].file == IMM) {
|
||||
inst->src[0] = brw_imm_for_type(src0 + src1, inst->dst.type);
|
||||
} else {
|
||||
assert(inst->src[0].type == BRW_TYPE_F);
|
||||
inst->opcode = BRW_OPCODE_MOV;
|
||||
inst->src[0].f += inst->src[1].f;
|
||||
inst->resize_sources(1);
|
||||
progress = true;
|
||||
break;
|
||||
}
|
||||
|
||||
inst->opcode = BRW_OPCODE_MOV;
|
||||
inst->resize_sources(1);
|
||||
progress = true;
|
||||
break;
|
||||
|
||||
|
||||
|
|
@ -242,6 +238,18 @@ brw_fs_opt_algebraic(fs_visitor &s)
|
|||
|
||||
foreach_block_and_inst_safe(block, fs_inst, inst, s.cfg) {
|
||||
switch (inst->opcode) {
|
||||
case BRW_OPCODE_ADD:
|
||||
if (brw_constant_fold_instruction(devinfo, inst)) {
|
||||
progress = true;
|
||||
} else if (brw_type_is_int(inst->src[1].type) &&
|
||||
inst->src[1].is_zero()) {
|
||||
inst->opcode = BRW_OPCODE_MOV;
|
||||
inst->resize_sources(1);
|
||||
progress = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BRW_OPCODE_MOV:
|
||||
if ((inst->conditional_mod == BRW_CONDITIONAL_Z ||
|
||||
inst->conditional_mod == BRW_CONDITIONAL_NZ) &&
|
||||
|
|
@ -277,7 +285,6 @@ brw_fs_opt_algebraic(fs_visitor &s)
|
|||
break;
|
||||
|
||||
case BRW_OPCODE_MUL:
|
||||
case BRW_OPCODE_ADD:
|
||||
case BRW_OPCODE_AND:
|
||||
if (brw_constant_fold_instruction(devinfo, inst))
|
||||
progress = true;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue