public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "prathamesh3492 at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/111048] [14 Regression] Wrong AVX2 code on highway-1.0.6 on -O2 and above since r14-3243-ga7dba4a1c05a76
Date: Fri, 18 Aug 2023 14:27:38 +0000	[thread overview]
Message-ID: <bug-111048-4-vMQnfVNbvB@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-111048-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111048

--- Comment #8 from prathamesh3492 at gcc dot gnu.org ---
(In reply to rsandifo@gcc.gnu.org from comment #7)
>         = ((q1 & 0) == 0) ? VECTOR_CST_NPATTERNS (arg0)
>                           : VECTOR_CST_NPATTERNS (arg1);
> 
> should be q1 & 1 :)

Oops, sorry for the typo :/
And yes, that fixes the issue.

For more context we have following inputs to VEC_PERM_EXPR:
arg0 (1, 1): { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
arg1: (4, 1): { 255, 63, 15, 3, 255, 63, 15, 3, 255, 63, 15, 3, 255, 63, 15, 3
}
sel (2, 3):  { 0, 16, 1, 17, 2, 18, ... }
arg0 len: 16
sel nelts: 16

In valid_mask_for_fold_vec_perm_cst_p for the pattern: {16, 17, 18, ...}
arg_npatterns is erroneously set to VECTOR_CST_NPATTERNS (arg0) and we have:
step = 1, arg_npatterns = 1
Thus, step becomes a "multiple" of arg_npatterns and we (wrongly) return true
for this case.

So in the loop below in fold_vec_perm_cst, we have res with following encoding:
res (4, 3): { 0, 255, 0, 63, 0, 15, 0, 3, 0, 255, 0, 63, ... }

Since len = 16, it has to compute the remaining elements.
For index 13, it comes as "a3" in pattern: { 255, 15, 255, ... }
So the step gets computed as: 255 - 15 = 240
And IIUC the next element thus becomes: (255 + 240)%256 = 239.

By correctly setting arg_npatterns = VECTOR_CST_NPATTERNS (arg1) for this
case, arg_npatterns becomes 4.
Since step == 1 is not a multiple of arg_npatterns we return false,
and use the fallback:
res_npatterns = 16, res_nelts_per_pattern = 1.
and the loop below correctly encodes the elements.

I will shortly send a patch after validating it.

Thanks,
Prathamesh

  parent reply	other threads:[~2023-08-18 14:27 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-17 11:40 [Bug target/111048] New: [14 Regression] Wrong AVX2 code on highway-1.0.6 on -O2 and above slyfox at gcc dot gnu.org
2023-08-17 12:35 ` [Bug target/111048] " slyfox at gcc dot gnu.org
2023-08-17 18:32 ` [Bug middle-end/111048] " pinskia at gcc dot gnu.org
2023-08-17 18:39 ` [Bug tree-optimization/111048] " pinskia at gcc dot gnu.org
2023-08-18  7:39 ` rguenth at gcc dot gnu.org
2023-08-18  8:24 ` cvs-commit at gcc dot gnu.org
2023-08-18  8:25 ` rguenth at gcc dot gnu.org
2023-08-18  9:08 ` prathamesh3492 at gcc dot gnu.org
2023-08-18  9:35 ` rsandifo at gcc dot gnu.org
2023-08-18 14:27 ` prathamesh3492 at gcc dot gnu.org [this message]
2023-08-21  9:57 ` [Bug tree-optimization/111048] [14 Regression] Wrong AVX2 code on highway-1.0.6 on -O2 and above since r14-3243-ga7dba4a1c05a76 cvs-commit at gcc dot gnu.org
2023-08-21 11:04 ` prathamesh3492 at gcc dot gnu.org
2023-08-21 17:49 ` slyfox at gcc dot gnu.org

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=bug-111048-4-vMQnfVNbvB@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).