public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/101596] New: vect_recog_mulhs_pattern could use incorrect precision to check shift count
@ 2021-07-23  7:50 linkw at gcc dot gnu.org
  2021-07-23  7:51 ` [Bug middle-end/101596] " linkw at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: linkw at gcc dot gnu.org @ 2021-07-23  7:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101596
           Summary: vect_recog_mulhs_pattern could use incorrect precision
                    to check shift count
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: linkw at gcc dot gnu.org
  Target Milestone: ---

I happened to spot this when I was working to add one new pattern for Power10
divide extended. Now vect_recog_mulhs_pattern uses target_precision to check
the scale_term is expected or not, it's wrong when the precision of the actual
used new_type larger than target_precision, since we use the new_type for the
internal function call.

Test case:

```
#define N 32

typedef signed long long sLL;
signed int si_a[N], si_b[N];
signed short sh_c[N];

#define SH_CNT 48
//#define SH_CNT 32

__attribute__ ((noipa)) void
test_ui ()
{
  for (int i = 0; i < N; i++)
    sh_c[i] = ((sLL) si_a[i] * (sLL) si_b[i]) >> SH_CNT;
}

__attribute__ ((optimize ("O0"))) int
main ()
{
  for (int i = 0; i < N; i++)
    {
      si_a[i] = 0x12345678;
      si_b[i] = 0x76543210;
    }
  test_ui ();
  for (int i = 0; i < N; i++)
    {
      signed short exp = ((sLL) si_a[i] * (sLL) si_b[i]) >> SH_CNT;
      if (exp != sh_c[i])
        __builtin_abort ();
    }
  return 0;
}
```

gcc test.c -mcpu=power10 -O2 -ftree-vectorize

$ ./a.out
Aborted (core dumped)

test.c:13:21: note:   vect_recog_mulhs_pattern: detected: _6 = _5 >> 48;

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-25  2:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-23  7:50 [Bug middle-end/101596] New: vect_recog_mulhs_pattern could use incorrect precision to check shift count linkw at gcc dot gnu.org
2021-07-23  7:51 ` [Bug middle-end/101596] " linkw at gcc dot gnu.org
2021-07-23  7:57 ` linkw at gcc dot gnu.org
2021-07-27  3:26 ` linkw at gcc dot gnu.org
2021-07-28  3:40 ` cvs-commit at gcc dot gnu.org
2021-07-28  3:49 ` linkw at gcc dot gnu.org
2021-08-25  2:40 ` pinskia at gcc dot gnu.org

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).