]> gcc.gnu.org Git - gcc.git/commit
optabs: Implement double-word ctz and ffs expansion
authorJakub Jelinek <jakub@redhat.com>
Thu, 8 Jun 2023 08:13:23 +0000 (10:13 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 8 Jun 2023 08:13:23 +0000 (10:13 +0200)
commitfcbef8e431c246c1f584537a08d58fcd5c5a1831
tree4a499fc25f8cc1c88e6c11b00b30b78eb3c6fc0f
parent2b2bf793d3fb8980cb2b83e9e2a8c236ad2434f5
optabs: Implement double-word ctz and ffs expansion

We have expand_doubleword_clz for a couple of years, where we emit
double-word CLZ as if (high_word == 0) return CLZ (low_word) + word_size;
else return CLZ (high_word);
We can do something similar for CTZ and FFS IMHO, just with the 2
words swapped.  So if (low_word == 0) return CTZ (high_word) + word_size;
else return CTZ (low_word); for CTZ and
if (low_word == 0) { return high_word ? FFS (high_word) + word_size : 0;
else return FFS (low_word);

The following patch implements that.

Note, on some targets which implement both word_mode ctz and ffs patterns,
it might be better to incrementally implement those double-word ffs expansion
patterns in md files, because we aren't able to optimize it correctly;
nothing can detect we have just made sure that argument is not 0 and so
don't need to bother with handling that case.  So, on ia32 just using
CTZ patterns would be better there, but I think we can even do better and
instead of doing the comparisons of the operands against 0 do the CTZ
expansion followed by testing of flags.

2023-06-08  Jakub Jelinek  <jakub@redhat.com>

* optabs.cc (expand_ffs): Add forward declaration.
(expand_doubleword_clz): Rename to ...
(expand_doubleword_clz_ctz_ffs): ... this.  Add UNOPTAB argument,
handle also doubleword CTZ and FFS in addition to CLZ.
(expand_unop): Adjust caller.  Also call it for doubleword
ctz_optab and ffs_optab.

* gcc.target/i386/ctzll-1.c: New test.
* gcc.target/i386/ffsll-1.c: New test.
gcc/optabs.cc
gcc/testsuite/gcc.target/i386/ctzll-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/ffsll-1.c [new file with mode: 0644]
This page took 0.078388 seconds and 5 git commands to generate.