1 /*
2 * Copyright © 2024 Intel Corporation
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "brw_fs.h"
7 #include "brw_fs_builder.h"
8 #include "brw_cfg.h"
9 #include "brw_eu.h"
10
11 /** @file brw_fs_opt_address_reg_load.cpp
12 *
13 * Turn this sequence :
14 *
15 * add(8) vgrf64:UD, vgrf63:UD, 192u
16 * mov(1) a0.4:UD, vgrf64+0.0<0>:UD
17 *
18 * into :
19 *
20 * add(1) a0.4:UD, vgrf63+0.0<0>:UD, 192u
21 */
22
23 using namespace brw;
24
25 static bool
opt_address_reg_load_local(fs_visitor & s,bblock_t * block,const brw::def_analysis & defs)26 opt_address_reg_load_local(fs_visitor &s, bblock_t *block, const brw::def_analysis &defs)
27 {
28 bool progress = false;
29
30 foreach_inst_in_block_safe(fs_inst, inst, block) {
31 if (!inst->dst.is_address() || inst->opcode != BRW_OPCODE_MOV)
32 continue;
33
34 fs_inst *src_inst = defs.get(inst->src[0]);
35 if (src_inst == NULL)
36 continue;
37
38 if (src_inst->uses_address_register_implicitly() ||
39 src_inst->sources > 2)
40 continue;
41
42 fs_builder ubld = fs_builder(&s).at(block, inst).exec_all().group(1, 0);
43 brw_reg sources[3];
44 for (unsigned i = 0; i < src_inst->sources; i++) {
45 sources[i] = inst->src[i].file == VGRF ? component(src_inst->src[i], 0) : src_inst->src[i];
46 }
47 ubld.emit(src_inst->opcode, inst->dst, sources, src_inst->sources);
48
49 inst->remove(block);
50
51 progress = true;
52 }
53
54 return progress;
55 }
56
57 bool
brw_opt_address_reg_load(fs_visitor & s)58 brw_opt_address_reg_load(fs_visitor &s)
59 {
60 bool progress = false;
61 const brw::def_analysis &defs = s.def_analysis.require();
62
63 foreach_block(block, s.cfg) {
64 foreach_inst_in_block_safe(fs_inst, inst, block) {
65 progress = opt_address_reg_load_local(s, block, defs) || progress;
66 }
67 }
68
69 if (progress) {
70 s.cfg->adjust_block_ips();
71 s.invalidate_analysis(DEPENDENCY_INSTRUCTIONS);
72 }
73
74 return progress;
75 }
76