]> git.ipfire.org Git - thirdparty/gcc.git/commit
expand: Add trivial folding for bit query builtins at expansion time [PR114044]
authorJakub Jelinek <jakub@redhat.com>
Tue, 27 Feb 2024 08:52:07 +0000 (09:52 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 27 Feb 2024 08:52:07 +0000 (09:52 +0100)
commitc3c44c01d20b00ab5228f32596153b7f4cbc6036
tree731e8b1f649d44cb6c11976b17f58abd3ada37b8
parent8a5d9409584aeb777b06f9c19c7d1a3552d496ad
expand: Add trivial folding for bit query builtins at expansion time [PR114044]

While it seems a lot of places in various optimization passes fold
bit query internal functions with INTEGER_CST arguments to INTEGER_CST
when there is a lhs, when lhs is missing, all the removals of such dead
stmts are guarded with -ftree-dce, so with -fno-tree-dce those unfolded
ifn calls remain in the IL until expansion.  If they have large/huge
BITINT_TYPE arguments, there is no BLKmode optab and so expansion ICEs,
and bitint lowering doesn't touch such calls because it doesn't know they
need touching, functions only containing those will not even be further
processed by the pass because there are no non-small BITINT_TYPE SSA_NAMEs
+ the 2 exceptions (stores of BITINT_TYPE INTEGER_CSTs and conversions
from BITINT_TYPE INTEGER_CSTs to floating point SSA_NAMEs) and when walking
there is no special case for calls with BITINT_TYPE INTEGER_CSTs either,
those are for normal calls normally handled at expansion time.

So, the following patch adjust the expansion of these 6 ifns, by doing
nothing if there is no lhs, and also just in case and user disabled all
possible passes that would fold this handles the case of setting lhs
to ifn call with INTEGER_CST argument.

2024-02-27  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/114044
* internal-fn.def (CLRSB, CLZ, CTZ, FFS, PARITY): Use
DEF_INTERNAL_INT_EXT_FN macro rather than DEF_INTERNAL_INT_FN.
* internal-fn.h (expand_CLRSB, expand_CLZ, expand_CTZ, expand_FFS,
expand_PARITY): Declare.
* internal-fn.cc (expand_bitquery, expand_CLRSB, expand_CLZ,
expand_CTZ, expand_FFS, expand_PARITY): New functions.
(expand_POPCOUNT): Use expand_bitquery.

* gcc.dg/bitint-95.c: New test.
gcc/internal-fn.cc
gcc/internal-fn.def
gcc/internal-fn.h
gcc/testsuite/gcc.dg/bitint-95.c [new file with mode: 0644]