xref: /aosp_15_r20/external/mesa3d/src/amd/compiler/tests/test_reduce_assign.cpp (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2022 Valve Corporation
3  *
4  * SPDX-License-Identifier: MIT
5  */
6 #include "helpers.h"
7 
8 using namespace aco;
9 
10 BEGIN_TEST(setup_reduce_temp.divergent_if_phi)
11    /*
12     * This must have an end_linear_vgpr after the phi (to ensure it's live during the phi copies):
13     * v0 = start_linear_vgpr
14     * divergent_if (...) {
15     *
16     * } else {
17     *    use_linear_vgpr(v0)
18     * }
19     * ... = phi ...
20     */
21    // TODO: fix the RA validator to spot this
22    //>> s2: %_, v1: %a = p_startpgm
23    if (!setup_cs("s2 v1", GFX9))
24       return;
25 
26    //>> p_logical_start
27    //>> p_logical_end
28    bld.pseudo(aco_opcode::p_logical_start);
29    bld.pseudo(aco_opcode::p_logical_end);
30 
31    //>> lv1: %lv = p_start_linear_vgpr
32    emit_divergent_if_else(
33       program.get(), bld, Operand(inputs[0]),
34       [&]() -> void
__anonb484ab630102() 35       {
36          //>> s1: %_, s2: %_, s1: %_:scc = p_reduce %a, %lv, lv1: undef op:umin32 cluster_size:64
37          Instruction* reduce =
38             bld.reduction(aco_opcode::p_reduce, bld.def(s1), bld.def(bld.lm), bld.def(s1, scc),
39                           inputs[1], Operand(v1.as_linear()), Operand(v1.as_linear()), umin32);
40          reduce->reduction().cluster_size = bld.lm.bytes() * 8;
41       },
42       [&]() -> void
__anonb484ab630202() 43       {
44          /* nothing */
45       });
46    bld.pseudo(aco_opcode::p_phi, bld.def(v1), Operand::c32(1), Operand::zero());
47    //>> /* logical preds: BB1, BB4, / linear preds: BB4, BB5, / kind: uniform, top-level, merge, */
48    //! p_end_linear_vgpr %lv
49 
50    finish_setup_reduce_temp_test();
51 END_TEST
52