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

* [Bug middle-end/101596] vect_recog_mulhs_pattern could use incorrect precision to check shift count
  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 ` linkw at gcc dot gnu.org
  2021-07-23  7:57 ` linkw at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: linkw at gcc dot gnu.org @ 2021-07-23  7:51 UTC (permalink / raw)
  To: gcc-bugs

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

Kewen Lin <linkw at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-07-23
           Assignee|unassigned at gcc dot gnu.org      |linkw at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1

--- Comment #1 from Kewen Lin <linkw at gcc dot gnu.org> ---
I have a untested patch.

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

* [Bug middle-end/101596] vect_recog_mulhs_pattern could use incorrect precision to check shift count
  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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: linkw at gcc dot gnu.org @ 2021-07-23  7:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Kewen Lin <linkw at gcc dot gnu.org> ---
Created attachment 51200
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51200&action=edit
Untested patch

Still need test cases to be added.

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

* [Bug middle-end/101596] vect_recog_mulhs_pattern could use incorrect precision to check shift count
  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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: linkw at gcc dot gnu.org @ 2021-07-27  3:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Kewen Lin <linkw at gcc dot gnu.org> ---
Formal patch has been posted at
https://gcc.gnu.org/pipermail/gcc-patches/2021-July/576071.html

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

* [Bug middle-end/101596] vect_recog_mulhs_pattern could use incorrect precision to check shift count
  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
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-28  3:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Kewen Lin <linkw@gcc.gnu.org>:

https://gcc.gnu.org/g:89b3c97eed75c1e7c492bc727e0016003c5809cc

commit r12-2550-g89b3c97eed75c1e7c492bc727e0016003c5809cc
Author: Kewen Lin <linkw@linux.ibm.com>
Date:   Tue Jul 27 22:04:22 2021 -0500

    vect: Fix wrong check in vect_recog_mulhs_pattern [PR101596]

    As PR101596 showed, vect_recog_mulhs_pattern uses target_precision to
    check the scale_term is expected or not, it could be wrong when the
    precision of the actual used new_type larger than target_precision as
    shown by the example.

    This patch is to use precision of new_type instead of target_precision
    for the scale_term matching check.

    Bootstrapped & regtested on powerpc64le-linux-gnu P10,
    powerpc64-linux-gnu P8, x86_64-redhat-linux and aarch64-linux-gnu.

    gcc/ChangeLog:

            PR tree-optimization/101596
            * tree-vect-patterns.c (vect_recog_mulhs_pattern): Fix wrong check
            by using new_type's precision instead.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/101596
            * gcc.target/powerpc/pr101596-1.c: New test.
            * gcc.target/powerpc/pr101596-2.c: Likewise.
            * gcc.target/powerpc/pr101596-3.c: Likewise.

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

* [Bug middle-end/101596] vect_recog_mulhs_pattern could use incorrect precision to check shift count
  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
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: linkw at gcc dot gnu.org @ 2021-07-28  3:49 UTC (permalink / raw)
  To: gcc-bugs

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

Kewen Lin <linkw at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Kewen Lin <linkw at gcc dot gnu.org> ---
Should be fixed on trunk.

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

* [Bug middle-end/101596] vect_recog_mulhs_pattern could use incorrect precision to check shift count
  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
                   ` (4 preceding siblings ...)
  2021-07-28  3:49 ` linkw at gcc dot gnu.org
@ 2021-08-25  2:40 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-25  2:40 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
   Target Milestone|---                         |12.0

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