2015-02-03 01:49:44 -05:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2015 Connor Abbott
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Authors:
|
|
|
|
|
* Connor Abbott (cwabbott0@gmail.com)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "nir.h"
|
2016-09-02 19:07:57 -04:00
|
|
|
#include "nir_builder.h"
|
2015-02-03 01:49:44 -05:00
|
|
|
|
nir/opt_remove_phis: rematerialize constants
Foz-DB Navi31:
Totals from 749 (0.94% of 79395) affected shaders:
Instrs: 1224359 -> 1223722 (-0.05%); split: -0.07%, +0.02%
CodeSize: 6468392 -> 6466296 (-0.03%); split: -0.06%, +0.03%
Latency: 9764410 -> 9766457 (+0.02%); split: -0.01%, +0.03%
InvThroughput: 1017401 -> 1017380 (-0.00%); split: -0.03%, +0.03%
VClause: 19902 -> 19873 (-0.15%); split: -0.16%, +0.02%
SClause: 38441 -> 38424 (-0.04%); split: -0.05%, +0.01%
Copies: 86880 -> 86304 (-0.66%); split: -0.73%, +0.06%
Branches: 34206 -> 34159 (-0.14%); split: -0.14%, +0.01%
PreSGPRs: 45557 -> 45527 (-0.07%); split: -0.08%, +0.01%
PreVGPRs: 32406 -> 32408 (+0.01%)
VALU: 671633 -> 671533 (-0.01%); split: -0.02%, +0.01%
SALU: 155284 -> 154675 (-0.39%); split: -0.40%, +0.00%
VMEM: 27303 -> 27271 (-0.12%)
SMEM: 67490 -> 67455 (-0.05%)
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31031>
2024-09-04 18:33:59 +02:00
|
|
|
static bool
|
|
|
|
|
phi_srcs_equal(nir_def *a, nir_def *b)
|
2016-07-29 01:29:12 -07:00
|
|
|
{
|
nir/opt_remove_phis: rematerialize constants
Foz-DB Navi31:
Totals from 749 (0.94% of 79395) affected shaders:
Instrs: 1224359 -> 1223722 (-0.05%); split: -0.07%, +0.02%
CodeSize: 6468392 -> 6466296 (-0.03%); split: -0.06%, +0.03%
Latency: 9764410 -> 9766457 (+0.02%); split: -0.01%, +0.03%
InvThroughput: 1017401 -> 1017380 (-0.00%); split: -0.03%, +0.03%
VClause: 19902 -> 19873 (-0.15%); split: -0.16%, +0.02%
SClause: 38441 -> 38424 (-0.04%); split: -0.05%, +0.01%
Copies: 86880 -> 86304 (-0.66%); split: -0.73%, +0.06%
Branches: 34206 -> 34159 (-0.14%); split: -0.14%, +0.01%
PreSGPRs: 45557 -> 45527 (-0.07%); split: -0.08%, +0.01%
PreVGPRs: 32406 -> 32408 (+0.01%)
VALU: 671633 -> 671533 (-0.01%); split: -0.02%, +0.01%
SALU: 155284 -> 154675 (-0.39%); split: -0.40%, +0.00%
VMEM: 27303 -> 27271 (-0.12%)
SMEM: 67490 -> 67455 (-0.05%)
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31031>
2024-09-04 18:33:59 +02:00
|
|
|
if (a == b)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (a->parent_instr->type != b->parent_instr->type)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (a->parent_instr->type != nir_instr_type_alu &&
|
|
|
|
|
a->parent_instr->type != nir_instr_type_load_const)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!nir_instrs_equal(a->parent_instr, b->parent_instr))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* nir_instrs_equal ignores exact/fast_math */
|
|
|
|
|
if (a->parent_instr->type == nir_instr_type_alu) {
|
2025-07-31 09:49:36 -04:00
|
|
|
nir_alu_instr *a_alu = nir_def_as_alu(a);
|
|
|
|
|
nir_alu_instr *b_alu = nir_def_as_alu(b);
|
nir/opt_remove_phis: rematerialize constants
Foz-DB Navi31:
Totals from 749 (0.94% of 79395) affected shaders:
Instrs: 1224359 -> 1223722 (-0.05%); split: -0.07%, +0.02%
CodeSize: 6468392 -> 6466296 (-0.03%); split: -0.06%, +0.03%
Latency: 9764410 -> 9766457 (+0.02%); split: -0.01%, +0.03%
InvThroughput: 1017401 -> 1017380 (-0.00%); split: -0.03%, +0.03%
VClause: 19902 -> 19873 (-0.15%); split: -0.16%, +0.02%
SClause: 38441 -> 38424 (-0.04%); split: -0.05%, +0.01%
Copies: 86880 -> 86304 (-0.66%); split: -0.73%, +0.06%
Branches: 34206 -> 34159 (-0.14%); split: -0.14%, +0.01%
PreSGPRs: 45557 -> 45527 (-0.07%); split: -0.08%, +0.01%
PreVGPRs: 32406 -> 32408 (+0.01%)
VALU: 671633 -> 671533 (-0.01%); split: -0.02%, +0.01%
SALU: 155284 -> 154675 (-0.39%); split: -0.40%, +0.00%
VMEM: 27303 -> 27271 (-0.12%)
SMEM: 67490 -> 67455 (-0.05%)
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31031>
2024-09-04 18:33:59 +02:00
|
|
|
if (a_alu->exact != b_alu->exact || a_alu->fp_fast_math != b_alu->fp_fast_math)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-07-29 01:29:12 -07:00
|
|
|
|
nir/opt_remove_phis: rematerialize constants
Foz-DB Navi31:
Totals from 749 (0.94% of 79395) affected shaders:
Instrs: 1224359 -> 1223722 (-0.05%); split: -0.07%, +0.02%
CodeSize: 6468392 -> 6466296 (-0.03%); split: -0.06%, +0.03%
Latency: 9764410 -> 9766457 (+0.02%); split: -0.01%, +0.03%
InvThroughput: 1017401 -> 1017380 (-0.00%); split: -0.03%, +0.03%
VClause: 19902 -> 19873 (-0.15%); split: -0.16%, +0.02%
SClause: 38441 -> 38424 (-0.04%); split: -0.05%, +0.01%
Copies: 86880 -> 86304 (-0.66%); split: -0.73%, +0.06%
Branches: 34206 -> 34159 (-0.14%); split: -0.14%, +0.01%
PreSGPRs: 45557 -> 45527 (-0.07%); split: -0.08%, +0.01%
PreVGPRs: 32406 -> 32408 (+0.01%)
VALU: 671633 -> 671533 (-0.01%); split: -0.02%, +0.01%
SALU: 155284 -> 154675 (-0.39%); split: -0.40%, +0.00%
VMEM: 27303 -> 27271 (-0.12%)
SMEM: 67490 -> 67455 (-0.05%)
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31031>
2024-09-04 18:33:59 +02:00
|
|
|
return true;
|
2016-07-29 01:29:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
nir/opt_remove_phis: rematerialize equal alu
Foz-DB Navi31:
Totals from 943 (1.19% of 79395) affected shaders:
MaxWaves: 24672 -> 24722 (+0.20%)
Instrs: 1541665 -> 1544956 (+0.21%); split: -0.23%, +0.44%
CodeSize: 8085180 -> 8109212 (+0.30%); split: -0.16%, +0.46%
VGPRs: 57768 -> 57624 (-0.25%)
Latency: 18043743 -> 17948245 (-0.53%); split: -1.28%, +0.75%
InvThroughput: 2692605 -> 2677049 (-0.58%); split: -2.07%, +1.49%
VClause: 25321 -> 25343 (+0.09%); split: -0.48%, +0.57%
SClause: 38473 -> 38614 (+0.37%); split: -0.00%, +0.37%
Copies: 86089 -> 86236 (+0.17%); split: -0.46%, +0.63%
Branches: 36719 -> 36777 (+0.16%); split: -0.60%, +0.76%
PreSGPRs: 44138 -> 44303 (+0.37%); split: -0.05%, +0.42%
PreVGPRs: 43319 -> 43009 (-0.72%)
VALU: 893684 -> 894272 (+0.07%); split: -0.42%, +0.48%
SALU: 189561 -> 191358 (+0.95%); split: -0.05%, +1.00%
VMEM: 42294 -> 42313 (+0.04%); split: -0.44%, +0.49%
SMEM: 72916 -> 73144 (+0.31%)
Instruction count regressions are largly caused by additional
loop unrolling.
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31028>
2024-09-06 14:29:36 +02:00
|
|
|
src_dominates_block(nir_src *src, void *state)
|
|
|
|
|
{
|
|
|
|
|
nir_block *block = state;
|
2025-07-31 09:37:16 -04:00
|
|
|
return nir_block_dominates(nir_def_block(src->ssa), block);
|
nir/opt_remove_phis: rematerialize equal alu
Foz-DB Navi31:
Totals from 943 (1.19% of 79395) affected shaders:
MaxWaves: 24672 -> 24722 (+0.20%)
Instrs: 1541665 -> 1544956 (+0.21%); split: -0.23%, +0.44%
CodeSize: 8085180 -> 8109212 (+0.30%); split: -0.16%, +0.46%
VGPRs: 57768 -> 57624 (-0.25%)
Latency: 18043743 -> 17948245 (-0.53%); split: -1.28%, +0.75%
InvThroughput: 2692605 -> 2677049 (-0.58%); split: -2.07%, +1.49%
VClause: 25321 -> 25343 (+0.09%); split: -0.48%, +0.57%
SClause: 38473 -> 38614 (+0.37%); split: -0.00%, +0.37%
Copies: 86089 -> 86236 (+0.17%); split: -0.46%, +0.63%
Branches: 36719 -> 36777 (+0.16%); split: -0.60%, +0.76%
PreSGPRs: 44138 -> 44303 (+0.37%); split: -0.05%, +0.42%
PreVGPRs: 43319 -> 43009 (-0.72%)
VALU: 893684 -> 894272 (+0.07%); split: -0.42%, +0.48%
SALU: 189561 -> 191358 (+0.95%); split: -0.05%, +1.00%
VMEM: 42294 -> 42313 (+0.04%); split: -0.44%, +0.49%
SMEM: 72916 -> 73144 (+0.31%)
Instruction count regressions are largly caused by additional
loop unrolling.
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31028>
2024-09-06 14:29:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
|
can_rematerialize_phi_src(nir_block *imm_dom, nir_def *def)
|
2016-07-29 01:29:12 -07:00
|
|
|
{
|
nir/opt_remove_phis: rematerialize constants
Foz-DB Navi31:
Totals from 749 (0.94% of 79395) affected shaders:
Instrs: 1224359 -> 1223722 (-0.05%); split: -0.07%, +0.02%
CodeSize: 6468392 -> 6466296 (-0.03%); split: -0.06%, +0.03%
Latency: 9764410 -> 9766457 (+0.02%); split: -0.01%, +0.03%
InvThroughput: 1017401 -> 1017380 (-0.00%); split: -0.03%, +0.03%
VClause: 19902 -> 19873 (-0.15%); split: -0.16%, +0.02%
SClause: 38441 -> 38424 (-0.04%); split: -0.05%, +0.01%
Copies: 86880 -> 86304 (-0.66%); split: -0.73%, +0.06%
Branches: 34206 -> 34159 (-0.14%); split: -0.14%, +0.01%
PreSGPRs: 45557 -> 45527 (-0.07%); split: -0.08%, +0.01%
PreVGPRs: 32406 -> 32408 (+0.01%)
VALU: 671633 -> 671533 (-0.01%); split: -0.02%, +0.01%
SALU: 155284 -> 154675 (-0.39%); split: -0.40%, +0.00%
VMEM: 27303 -> 27271 (-0.12%)
SMEM: 67490 -> 67455 (-0.05%)
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31031>
2024-09-04 18:33:59 +02:00
|
|
|
if (def->parent_instr->type == nir_instr_type_alu) {
|
nir/opt_remove_phis: rematerialize equal alu
Foz-DB Navi31:
Totals from 943 (1.19% of 79395) affected shaders:
MaxWaves: 24672 -> 24722 (+0.20%)
Instrs: 1541665 -> 1544956 (+0.21%); split: -0.23%, +0.44%
CodeSize: 8085180 -> 8109212 (+0.30%); split: -0.16%, +0.46%
VGPRs: 57768 -> 57624 (-0.25%)
Latency: 18043743 -> 17948245 (-0.53%); split: -1.28%, +0.75%
InvThroughput: 2692605 -> 2677049 (-0.58%); split: -2.07%, +1.49%
VClause: 25321 -> 25343 (+0.09%); split: -0.48%, +0.57%
SClause: 38473 -> 38614 (+0.37%); split: -0.00%, +0.37%
Copies: 86089 -> 86236 (+0.17%); split: -0.46%, +0.63%
Branches: 36719 -> 36777 (+0.16%); split: -0.60%, +0.76%
PreSGPRs: 44138 -> 44303 (+0.37%); split: -0.05%, +0.42%
PreVGPRs: 43319 -> 43009 (-0.72%)
VALU: 893684 -> 894272 (+0.07%); split: -0.42%, +0.48%
SALU: 189561 -> 191358 (+0.95%); split: -0.05%, +1.00%
VMEM: 42294 -> 42313 (+0.04%); split: -0.44%, +0.49%
SMEM: 72916 -> 73144 (+0.31%)
Instruction count regressions are largly caused by additional
loop unrolling.
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31028>
2024-09-06 14:29:36 +02:00
|
|
|
return nir_foreach_src(def->parent_instr, src_dominates_block, imm_dom);
|
nir/opt_remove_phis: rematerialize constants
Foz-DB Navi31:
Totals from 749 (0.94% of 79395) affected shaders:
Instrs: 1224359 -> 1223722 (-0.05%); split: -0.07%, +0.02%
CodeSize: 6468392 -> 6466296 (-0.03%); split: -0.06%, +0.03%
Latency: 9764410 -> 9766457 (+0.02%); split: -0.01%, +0.03%
InvThroughput: 1017401 -> 1017380 (-0.00%); split: -0.03%, +0.03%
VClause: 19902 -> 19873 (-0.15%); split: -0.16%, +0.02%
SClause: 38441 -> 38424 (-0.04%); split: -0.05%, +0.01%
Copies: 86880 -> 86304 (-0.66%); split: -0.73%, +0.06%
Branches: 34206 -> 34159 (-0.14%); split: -0.14%, +0.01%
PreSGPRs: 45557 -> 45527 (-0.07%); split: -0.08%, +0.01%
PreVGPRs: 32406 -> 32408 (+0.01%)
VALU: 671633 -> 671533 (-0.01%); split: -0.02%, +0.01%
SALU: 155284 -> 154675 (-0.39%); split: -0.40%, +0.00%
VMEM: 27303 -> 27271 (-0.12%)
SMEM: 67490 -> 67455 (-0.05%)
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31031>
2024-09-04 18:33:59 +02:00
|
|
|
} else if (def->parent_instr->type == nir_instr_type_load_const) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2016-07-29 01:29:12 -07:00
|
|
|
}
|
|
|
|
|
|
2015-02-03 01:49:44 -05:00
|
|
|
/*
|
|
|
|
|
* This is a pass for removing phi nodes that look like:
|
|
|
|
|
* a = phi(b, b, b, ...)
|
|
|
|
|
*
|
2020-08-17 12:18:24 +01:00
|
|
|
* Note that we can't always ignore undef sources here, or else we may create a
|
2015-02-03 01:49:44 -05:00
|
|
|
* situation where the definition of b isn't dominated by its uses. We're
|
|
|
|
|
* allowed to do this since the definition of b must dominate all of the
|
|
|
|
|
* phi node's predecessors, which means it must dominate the phi node as well
|
|
|
|
|
* as all of the phi node's uses. In essence, the phi node acts as a copy
|
|
|
|
|
* instruction. b can't be another phi node in the same block, since the only
|
|
|
|
|
* time when phi nodes can source other phi nodes defined in the same block is
|
|
|
|
|
* at the loop header, and in that case one of the sources of the phi has to
|
|
|
|
|
* be from before the loop and that source can't be b.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static bool
|
2025-02-22 13:14:20 +01:00
|
|
|
remove_phis_instr(nir_builder *b, nir_phi_instr *phi, void *unused)
|
2015-02-03 01:49:44 -05:00
|
|
|
{
|
2025-02-22 13:14:20 +01:00
|
|
|
nir_block *block = phi->instr.block;
|
|
|
|
|
nir_def *def = NULL;
|
|
|
|
|
bool needs_remat = false;
|
|
|
|
|
|
2025-07-04 11:48:07 +02:00
|
|
|
/* Skip unreachable phis, they should be removed by nir_opt_dead_cf. */
|
|
|
|
|
if (nir_block_is_unreachable(block))
|
|
|
|
|
return false;
|
|
|
|
|
|
2025-02-22 13:14:20 +01:00
|
|
|
nir_foreach_phi_src(src, phi) {
|
|
|
|
|
/* For phi nodes at the beginning of loops, we may encounter some
|
|
|
|
|
* sources from backedges that point back to the destination of the
|
|
|
|
|
* same phi, i.e. something like:
|
|
|
|
|
*
|
|
|
|
|
* a = phi(a, b, ...)
|
|
|
|
|
*
|
|
|
|
|
* We can safely ignore these sources, since if all of the normal
|
|
|
|
|
* sources point to the same definition, then that definition must
|
|
|
|
|
* still dominate the phi node, and the phi will still always take
|
|
|
|
|
* the value of that definition.
|
|
|
|
|
*/
|
|
|
|
|
if (src->src.ssa == &phi->def)
|
|
|
|
|
continue;
|
2015-02-03 01:49:44 -05:00
|
|
|
|
2025-02-22 13:14:20 +01:00
|
|
|
/* Ignore undef sources. */
|
|
|
|
|
if (nir_src_is_undef(src->src))
|
|
|
|
|
continue;
|
2015-02-03 01:49:44 -05:00
|
|
|
|
2025-02-22 13:14:20 +01:00
|
|
|
if (def == NULL) {
|
|
|
|
|
def = src->src.ssa;
|
2025-07-31 09:37:16 -04:00
|
|
|
if (!nir_block_dominates(nir_def_block(def), block->imm_dom)) {
|
2025-02-22 13:14:20 +01:00
|
|
|
if (!can_rematerialize_phi_src(block->imm_dom, def))
|
|
|
|
|
return false;
|
|
|
|
|
needs_remat = true;
|
2015-02-03 01:49:44 -05:00
|
|
|
}
|
2025-02-22 13:14:20 +01:00
|
|
|
} else if (!phi_srcs_equal(src->src.ssa, def)) {
|
|
|
|
|
return false;
|
2015-02-03 01:49:44 -05:00
|
|
|
}
|
2025-02-22 13:14:20 +01:00
|
|
|
}
|
2015-02-03 01:49:44 -05:00
|
|
|
|
2025-02-22 13:14:20 +01:00
|
|
|
if (!def) {
|
|
|
|
|
/* In this case, the phi had no non undef sources. So turn it into an undef. */
|
|
|
|
|
b->cursor = nir_after_phis(block);
|
|
|
|
|
def = nir_undef(b, phi->def.num_components, phi->def.bit_size);
|
|
|
|
|
} else if (needs_remat) {
|
|
|
|
|
b->cursor = nir_after_block_before_jump(block->imm_dom);
|
|
|
|
|
nir_instr *remat = nir_instr_clone(b->shader, def->parent_instr);
|
|
|
|
|
nir_builder_instr_insert(b, remat);
|
|
|
|
|
def = nir_instr_def(remat);
|
|
|
|
|
}
|
2016-09-02 19:07:57 -04:00
|
|
|
|
2025-02-22 13:14:20 +01:00
|
|
|
nir_def_replace(&phi->def, def);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-02-03 01:49:44 -05:00
|
|
|
|
2025-02-22 13:14:20 +01:00
|
|
|
bool
|
|
|
|
|
nir_opt_remove_phis(nir_shader *shader)
|
|
|
|
|
{
|
|
|
|
|
nir_foreach_function_impl(impl, shader)
|
|
|
|
|
nir_metadata_require(impl, nir_metadata_dominance);
|
2015-02-03 01:49:44 -05:00
|
|
|
|
2025-02-22 13:14:20 +01:00
|
|
|
return nir_shader_phi_pass(shader, remove_phis_instr,
|
|
|
|
|
nir_metadata_control_flow, NULL);
|
2015-02-03 01:49:44 -05:00
|
|
|
}
|
|
|
|
|
|
2019-07-10 15:14:42 -05:00
|
|
|
bool
|
2024-09-06 14:01:30 +02:00
|
|
|
nir_remove_single_src_phis_block(nir_block *block)
|
2019-07-10 15:14:42 -05:00
|
|
|
{
|
2025-08-09 16:52:18 -04:00
|
|
|
assert(block->predecessors.entries <= 1);
|
2024-09-06 14:01:30 +02:00
|
|
|
bool progress = false;
|
|
|
|
|
nir_foreach_phi_safe(phi, block) {
|
|
|
|
|
nir_def *def = NULL;
|
|
|
|
|
nir_foreach_phi_src(src, phi) {
|
|
|
|
|
def = src->src.ssa;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!def) {
|
|
|
|
|
nir_builder b = nir_builder_create(nir_cf_node_get_function(&block->cf_node));
|
|
|
|
|
b.cursor = nir_after_phis(block);
|
|
|
|
|
def = nir_undef(&b, phi->def.num_components, phi->def.bit_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nir_def_replace(&phi->def, def);
|
|
|
|
|
progress = true;
|
|
|
|
|
}
|
|
|
|
|
return progress;
|
2019-07-10 15:14:42 -05:00
|
|
|
}
|