From: Robin Dapp <rdapp.gcc@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: rdapp.gcc@gmail.com, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] vect: Add a popcount fallback.
Date: Wed, 9 Aug 2023 12:23:47 +0200 [thread overview]
Message-ID: <8af42de5-c897-aecf-aad4-66f4a80d4551@gmail.com> (raw)
In-Reply-To: <CAFiYyc09YD0WdmOefF0tO4k6ft2kdePOL3H=06xCGvG6wMM47A@mail.gmail.com>
> We seem to be looking at promotions of the call argument, lhs_type
> is the same as the type of the call LHS. But the comment mentions .POPCOUNT
> and the following code also handles others, so maybe handling should be
> moved. Also when we look to vectorize popcount (x) instead of popcount((T)x)
> we can simply promote the result accordingly.
IMHO lhs_type is the type of the conversion
lhs_oprnd = gimple_assign_lhs (last_stmt);
lhs_type = TREE_TYPE (lhs_oprnd);
and rhs/unprom_diff has the type of the call's input argument
rhs_oprnd = gimple_call_arg (call_stmt, 0);
vect_look_through_possible_promotion (vinfo, rhs_oprnd, &unprom_diff);
So we can potentially have
T0 arg
T1 in = (T1)arg
T2 ret = __builtin_popcount (in)
T3 lhs = (T3)ret
and we're checking if precision (T0) == precision (T3).
This will never be true for a proper __builtin_popcountll except if
the return value is cast to uint64_t (which I just happened to do
in my test...). Therefore it still doesn't really make sense to me.
Interestingly though, it helps for an aarch64 __builtin_popcountll
testcase where we abort here and then manage to vectorize via
vectorizable_call. When we skip this check, recognition succeeds
and replaces the call with the pattern. Then scalar costs are lower
than in the vectorizable_call case because __builtin_popcountll is
not STMT_VINFO_RELEVANT_P anymore (not live or so?).
Then, vectorization costs are too high compared to the wrong scalar
costs and we don't vectorize... Odd, might require fixing separately.
We might need to calculate the scalar costs in advance?
> It looks like vect_recog_popcount_clz_ctz_ffs_pattern is specifcally for
> the conversions, so your fallback should possibly apply even when not
> matching them.
Mhm, yes it appears to only match when casting the return value to
something else than an int. So we'd need a fallback in vectorizable_call?
And it would potentially look a bit out of place there only handling
popcount and not ctz, clz, ... Not sure if it is worth it then?
Regards
Robin
next prev parent reply other threads:[~2023-08-09 10:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-07 20:20 Robin Dapp
2023-08-08 6:21 ` Richard Biener
2023-08-08 8:55 ` Robin Dapp
2023-08-08 10:02 ` Richard Biener
2023-08-08 11:37 ` Robin Dapp
2023-08-08 12:49 ` Richard Biener
2023-08-08 13:06 ` Robin Dapp
2023-08-08 13:28 ` Richard Biener
2023-08-09 10:23 ` Robin Dapp [this message]
2023-08-09 11:58 ` Richard Biener
2023-08-08 14:14 ` Jeff Law
2023-08-08 14:21 ` Robin Dapp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8af42de5-c897-aecf-aad4-66f4a80d4551@gmail.com \
--to=rdapp.gcc@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.guenther@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).