nir: constant fold inverse_ballot
Foz-DB Navi21: Totals from 210 (0.26% of 79395) affected shaders: Instrs: 79583 -> 78892 (-0.87%) CodeSize: 435636 -> 431680 (-0.91%) VGPRs: 7208 -> 7224 (+0.22%) Latency: 660376 -> 658808 (-0.24%); split: -0.38%, +0.14% InvThroughput: 127489 -> 127544 (+0.04%); split: -0.35%, +0.39% VClause: 1503 -> 1504 (+0.07%) SClause: 3970 -> 3947 (-0.58%) Copies: 4932 -> 4682 (-5.07%); split: -5.17%, +0.10% Branches: 2411 -> 2406 (-0.21%); split: -0.33%, +0.12% PreSGPRs: 6395 -> 6434 (+0.61%); split: -0.31%, +0.92% PreVGPRs: 4100 -> 4103 (+0.07%) VALU: 48484 -> 48145 (-0.70%); split: -0.70%, +0.00% SALU: 12499 -> 12202 (-2.38%); split: -2.41%, +0.03% SMEM: 6448 -> 6420 (-0.43%) Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Daniel Schürmann <daniel@schuermann.dev> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30235>
This commit is contained in:
@@ -281,6 +281,23 @@ try_fold_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin,
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
case nir_intrinsic_inverse_ballot: {
|
||||||
|
if (!nir_src_is_const(intrin->src[0]))
|
||||||
|
return false;
|
||||||
|
bool constant_true = true;
|
||||||
|
bool constant_false = true;
|
||||||
|
for (unsigned i = 0; i < nir_src_num_components(intrin->src[0]); i++) {
|
||||||
|
int64_t value = nir_src_comp_as_int(intrin->src[0], i);
|
||||||
|
constant_true &= value == -1;
|
||||||
|
constant_false &= value == 0;
|
||||||
|
}
|
||||||
|
if (!constant_true && !constant_false)
|
||||||
|
return false;
|
||||||
|
b->cursor = nir_before_instr(&intrin->instr);
|
||||||
|
nir_def_replace(&intrin->def, nir_imm_bool(b, constant_true));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user