public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/106144] New: wide_int shifted_mask() and mask() do not agree
@ 2022-06-30 11:03 aldyh at gcc dot gnu.org
  2022-06-30 18:18 ` [Bug middle-end/106144] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: aldyh at gcc dot gnu.org @ 2022-06-30 11:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106144
           Summary: wide_int shifted_mask() and mask() do not agree
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aldyh at gcc dot gnu.org
                CC: amacleod at redhat dot com, mikestump at comcast dot net,
                    rsandifo at gcc dot gnu.org
  Target Milestone: ---

A mask of 128 bits should match a shifted mask of 128 bits where the shift is
0, but the following assert is failing:

      {
        wide_int mask1 = wi::mask (128, false, 128);
        wide_int mask2 = wi::shifted_mask (0, 128, false, 128);
        mask1.dump ();
        mask2.dump ();
        gcc_assert (mask1 == mask2);
      }

The output is:

[...,0xffffffffffffffff], precision = 128
[0xffffffffffffffff,0xffffffffffffffff], precision = 128

I would expect both masks to be the same.

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

* [Bug middle-end/106144] wide_int shifted_mask() and mask() do not agree
  2022-06-30 11:03 [Bug middle-end/106144] New: wide_int shifted_mask() and mask() do not agree aldyh at gcc dot gnu.org
@ 2022-06-30 18:18 ` jakub at gcc dot gnu.org
  2022-06-30 18:50 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-30 18:18 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think this is a bug in wi::shifted_mask, { -1 } with len = 1 from wi::mask is
canonical 128-bit precision -1, { -1, -1 } with len = 2 from wi::shifted_mask
is not.

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

* [Bug middle-end/106144] wide_int shifted_mask() and mask() do not agree
  2022-06-30 11:03 [Bug middle-end/106144] New: wide_int shifted_mask() and mask() do not agree aldyh at gcc dot gnu.org
  2022-06-30 18:18 ` [Bug middle-end/106144] " jakub at gcc dot gnu.org
@ 2022-06-30 18:50 ` jakub at gcc dot gnu.org
  2022-07-01  8:09 ` aldyh at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-30 18:50 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
   Last reconfirmed|                            |2022-06-30
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 53228
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53228&action=edit
gcc13-pr106144.patch

Untested fix.

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

* [Bug middle-end/106144] wide_int shifted_mask() and mask() do not agree
  2022-06-30 11:03 [Bug middle-end/106144] New: wide_int shifted_mask() and mask() do not agree aldyh at gcc dot gnu.org
  2022-06-30 18:18 ` [Bug middle-end/106144] " jakub at gcc dot gnu.org
  2022-06-30 18:50 ` jakub at gcc dot gnu.org
@ 2022-07-01  8:09 ` aldyh at gcc dot gnu.org
  2022-07-01  9:19 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: aldyh at gcc dot gnu.org @ 2022-07-01  8:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #2)
> Created attachment 53228 [details]
> gcc13-pr106144.patch
> 
> Untested fix.

Thanks.

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

* [Bug middle-end/106144] wide_int shifted_mask() and mask() do not agree
  2022-06-30 11:03 [Bug middle-end/106144] New: wide_int shifted_mask() and mask() do not agree aldyh at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-07-01  8:09 ` aldyh at gcc dot gnu.org
@ 2022-07-01  9:19 ` cvs-commit at gcc dot gnu.org
  2022-07-30  9:34 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-01  9:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:e52592073f6df3d7a3acd9f0436dcc32a8b7493d

commit r13-1381-ge52592073f6df3d7a3acd9f0436dcc32a8b7493d
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jul 1 11:17:41 2022 +0200

    wide-int: Fix up wi::shifted_mask [PR106144]

    As the following self-test testcase shows, wi::shifted_mask sometimes
    doesn't create canonicalized wide_ints, which then fail to compare equal
    to canonicalized wide_ints with the same value.
    In particular, wi::mask (128, false, 128) gives { -1 } with len 1 and prec
128,
    while wi::shifted_mask (0, 128, false, 128) gives { -1, -1 } with len 2
    and prec 128.
    The problem is that the code is written with the assumption that there are
    3 bit blocks (or 2 if start is 0), but doesn't consider the possibility
    where there are 2 bit blocks (or 1 if start is 0) where the highest block
    isn't present.  In that case, there is the optional block of negate ? 0 :
-1
    elts, followed by just one elt (either one from the if (shift) or just
    negate ? -1 : 0) and the rest is implicit sign-extension.
    Only if end < prec there is 1 or more bits above it that have different bit
    value and so we need to emit all the elts till end and then one more elt.

    if (end == prec) would work too, because we have:
      if (width > prec - start)
        width = prec - start;
      unsigned int end = start + width;
    so end is guaranteed to be end <= prec, dunno what is preferred.

    2022-07-01  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/106144
            * wide-int.cc (wi::shifted_mask): If end >= prec, return right
after
            emitting element for shift or if shift is 0 first element after
start.
            (wide_int_cc_tests): Add tests for equivalency of wi::mask and
            wi::shifted_mask with 0 start.

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

* [Bug middle-end/106144] wide_int shifted_mask() and mask() do not agree
  2022-06-30 11:03 [Bug middle-end/106144] New: wide_int shifted_mask() and mask() do not agree aldyh at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-07-01  9:19 ` cvs-commit at gcc dot gnu.org
@ 2022-07-30  9:34 ` cvs-commit at gcc dot gnu.org
  2022-11-04  8:30 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-30  9:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:527dccb33e54ffe49fb1507fc4539968f48a9d12

commit r12-8643-g527dccb33e54ffe49fb1507fc4539968f48a9d12
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jul 1 11:17:41 2022 +0200

    wide-int: Fix up wi::shifted_mask [PR106144]

    As the following self-test testcase shows, wi::shifted_mask sometimes
    doesn't create canonicalized wide_ints, which then fail to compare equal
    to canonicalized wide_ints with the same value.
    In particular, wi::mask (128, false, 128) gives { -1 } with len 1 and prec
128,
    while wi::shifted_mask (0, 128, false, 128) gives { -1, -1 } with len 2
    and prec 128.
    The problem is that the code is written with the assumption that there are
    3 bit blocks (or 2 if start is 0), but doesn't consider the possibility
    where there are 2 bit blocks (or 1 if start is 0) where the highest block
    isn't present.  In that case, there is the optional block of negate ? 0 :
-1
    elts, followed by just one elt (either one from the if (shift) or just
    negate ? -1 : 0) and the rest is implicit sign-extension.
    Only if end < prec there is 1 or more bits above it that have different bit
    value and so we need to emit all the elts till end and then one more elt.

    if (end == prec) would work too, because we have:
      if (width > prec - start)
        width = prec - start;
      unsigned int end = start + width;
    so end is guaranteed to be end <= prec, dunno what is preferred.

    2022-07-01  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/106144
            * wide-int.cc (wi::shifted_mask): If end >= prec, return right
after
            emitting element for shift or if shift is 0 first element after
start.
            (wide_int_cc_tests): Add tests for equivalency of wi::mask and
            wi::shifted_mask with 0 start.

    (cherry picked from commit e52592073f6df3d7a3acd9f0436dcc32a8b7493d)

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

* [Bug middle-end/106144] wide_int shifted_mask() and mask() do not agree
  2022-06-30 11:03 [Bug middle-end/106144] New: wide_int shifted_mask() and mask() do not agree aldyh at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-07-30  9:34 ` cvs-commit at gcc dot gnu.org
@ 2022-11-04  8:30 ` cvs-commit at gcc dot gnu.org
  2023-05-03 15:18 ` cvs-commit at gcc dot gnu.org
  2023-05-04  7:18 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-04  8:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:4d853d49202a3b9fdaade64a6d5f920304c2b38d

commit r11-10355-g4d853d49202a3b9fdaade64a6d5f920304c2b38d
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jul 1 11:17:41 2022 +0200

    wide-int: Fix up wi::shifted_mask [PR106144]

    As the following self-test testcase shows, wi::shifted_mask sometimes
    doesn't create canonicalized wide_ints, which then fail to compare equal
    to canonicalized wide_ints with the same value.
    In particular, wi::mask (128, false, 128) gives { -1 } with len 1 and prec
128,
    while wi::shifted_mask (0, 128, false, 128) gives { -1, -1 } with len 2
    and prec 128.
    The problem is that the code is written with the assumption that there are
    3 bit blocks (or 2 if start is 0), but doesn't consider the possibility
    where there are 2 bit blocks (or 1 if start is 0) where the highest block
    isn't present.  In that case, there is the optional block of negate ? 0 :
-1
    elts, followed by just one elt (either one from the if (shift) or just
    negate ? -1 : 0) and the rest is implicit sign-extension.
    Only if end < prec there is 1 or more bits above it that have different bit
    value and so we need to emit all the elts till end and then one more elt.

    if (end == prec) would work too, because we have:
      if (width > prec - start)
        width = prec - start;
      unsigned int end = start + width;
    so end is guaranteed to be end <= prec, dunno what is preferred.

    2022-07-01  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/106144
            * wide-int.cc (wi::shifted_mask): If end >= prec, return right
after
            emitting element for shift or if shift is 0 first element after
start.
            (wide_int_cc_tests): Add tests for equivalency of wi::mask and
            wi::shifted_mask with 0 start.

    (cherry picked from commit e52592073f6df3d7a3acd9f0436dcc32a8b7493d)

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

* [Bug middle-end/106144] wide_int shifted_mask() and mask() do not agree
  2022-06-30 11:03 [Bug middle-end/106144] New: wide_int shifted_mask() and mask() do not agree aldyh at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-11-04  8:30 ` cvs-commit at gcc dot gnu.org
@ 2023-05-03 15:18 ` cvs-commit at gcc dot gnu.org
  2023-05-04  7:18 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-03 15:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:6e7bf9bc3e51d2d0d0df3d810cb20624594573cf

commit r10-11334-g6e7bf9bc3e51d2d0d0df3d810cb20624594573cf
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jul 1 11:17:41 2022 +0200

    wide-int: Fix up wi::shifted_mask [PR106144]

    As the following self-test testcase shows, wi::shifted_mask sometimes
    doesn't create canonicalized wide_ints, which then fail to compare equal
    to canonicalized wide_ints with the same value.
    In particular, wi::mask (128, false, 128) gives { -1 } with len 1 and prec
128,
    while wi::shifted_mask (0, 128, false, 128) gives { -1, -1 } with len 2
    and prec 128.
    The problem is that the code is written with the assumption that there are
    3 bit blocks (or 2 if start is 0), but doesn't consider the possibility
    where there are 2 bit blocks (or 1 if start is 0) where the highest block
    isn't present.  In that case, there is the optional block of negate ? 0 :
-1
    elts, followed by just one elt (either one from the if (shift) or just
    negate ? -1 : 0) and the rest is implicit sign-extension.
    Only if end < prec there is 1 or more bits above it that have different bit
    value and so we need to emit all the elts till end and then one more elt.

    if (end == prec) would work too, because we have:
      if (width > prec - start)
        width = prec - start;
      unsigned int end = start + width;
    so end is guaranteed to be end <= prec, dunno what is preferred.

    2022-07-01  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/106144
            * wide-int.cc (wi::shifted_mask): If end >= prec, return right
after
            emitting element for shift or if shift is 0 first element after
start.
            (wide_int_cc_tests): Add tests for equivalency of wi::mask and
            wi::shifted_mask with 0 start.

    (cherry picked from commit e52592073f6df3d7a3acd9f0436dcc32a8b7493d)

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

* [Bug middle-end/106144] wide_int shifted_mask() and mask() do not agree
  2022-06-30 11:03 [Bug middle-end/106144] New: wide_int shifted_mask() and mask() do not agree aldyh at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-05-03 15:18 ` cvs-commit at gcc dot gnu.org
@ 2023-05-04  7:18 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-04  7:18 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 10.5 too.

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

end of thread, other threads:[~2023-05-04  7:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-30 11:03 [Bug middle-end/106144] New: wide_int shifted_mask() and mask() do not agree aldyh at gcc dot gnu.org
2022-06-30 18:18 ` [Bug middle-end/106144] " jakub at gcc dot gnu.org
2022-06-30 18:50 ` jakub at gcc dot gnu.org
2022-07-01  8:09 ` aldyh at gcc dot gnu.org
2022-07-01  9:19 ` cvs-commit at gcc dot gnu.org
2022-07-30  9:34 ` cvs-commit at gcc dot gnu.org
2022-11-04  8:30 ` cvs-commit at gcc dot gnu.org
2023-05-03 15:18 ` cvs-commit at gcc dot gnu.org
2023-05-04  7:18 ` jakub 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).