public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113756] New: Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87
@ 2024-02-04 14:14 shaohua.li at inf dot ethz.ch
  2024-02-04 18:13 ` [Bug tree-optimization/113756] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2024-02-04 14:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113756
           Summary: Wrong code at -O2 on x86_64-linux-gnu since
                    r14-2780-g39f117d6c87
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
                CC: aldyh at redhat dot com
  Target Milestone: ---

gcc at -O2 produced the wrong code.

Bisected to r14-2780-g39f117d6c87

Compiler explorer: https://godbolt.org/z/qWd4196h6

% cat reduced.c
int printf(const char *, ...);
int d, e, i, k, l = -8;
char h, j;
int m(int n, int o, int p3) {
  int a = o - p3, b = n - p3, c = a + b, f = -b, g = c < 0 ? -c : c;
  return a <= f && a <= g ? o : p3;
}
void q(int *n, unsigned short o) {
  unsigned p = 8896;
  for (; e >= 0; e--)
    p = 5377;
  for (; h <= 0; h++)
    for (; j <= 0; j++) {
      *n = 1611581749;
      i = m(34, p - 5294, *n - 1611581687);
      k = i + p + 65535 + o + *n - 1611718251;
      printf("%d\n", k);
    }
}
int main() {
  q(&l, l);
}
%
% gcc -O0 reduced.c &&./a.out
0
% gcc -O2 reduced.c &&./a.out
21
%

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

* [Bug tree-optimization/113756] Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87
  2024-02-04 14:14 [Bug tree-optimization/113756] New: Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87 shaohua.li at inf dot ethz.ch
@ 2024-02-04 18:13 ` pinskia at gcc dot gnu.org
  2024-02-04 18:17 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-04 18:13 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0
                 CC|                            |pinskia at gcc dot gnu.org

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

* [Bug tree-optimization/113756] Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87
  2024-02-04 14:14 [Bug tree-optimization/113756] New: Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87 shaohua.li at inf dot ethz.ch
  2024-02-04 18:13 ` [Bug tree-optimization/113756] " pinskia at gcc dot gnu.org
@ 2024-02-04 18:17 ` pinskia at gcc dot gnu.org
  2024-02-05  9:04 ` [Bug tree-optimization/113756] [14 regression] " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-04 18:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-02-04
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug tree-optimization/113756] [14 regression] Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87
  2024-02-04 14:14 [Bug tree-optimization/113756] New: Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87 shaohua.li at inf dot ethz.ch
  2024-02-04 18:13 ` [Bug tree-optimization/113756] " pinskia at gcc dot gnu.org
  2024-02-04 18:17 ` pinskia at gcc dot gnu.org
@ 2024-02-05  9:04 ` rguenth at gcc dot gnu.org
  2024-02-06 15:59 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-02-05  9:04 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1

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

* [Bug tree-optimization/113756] [14 regression] Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87
  2024-02-04 14:14 [Bug tree-optimization/113756] New: Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87 shaohua.li at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2024-02-05  9:04 ` [Bug tree-optimization/113756] [14 regression] " rguenth at gcc dot gnu.org
@ 2024-02-06 15:59 ` jakub at gcc dot gnu.org
  2024-02-06 16:05 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-06 15:59 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think the issue is that ABSU_EXPR is an unary operation with signed operand
and unsigned result.  And update_known_bitmask was using result rather than
operand sign to the operand's value/mask, so I think
--- gcc/range-op.cc.jj  2024-01-03 11:51:28.199777434 +0100
+++ gcc/range-op.cc     2024-02-06 16:51:55.549127825 +0100
@@ -435,8 +435,10 @@ update_known_bitmask (irange &r, tree_co
       bit_value_unop (code, sign, prec, &widest_value, &widest_mask,
                      TYPE_SIGN (lh.type ()),
                      TYPE_PRECISION (lh.type ()),
-                     widest_int::from (lh_bits.value (), sign),
-                     widest_int::from (lh_bits.mask (), sign));
+                     widest_int::from (lh_bits.value (),
+                                       TYPE_SIGN (lh.type ())),
+                     widest_int::from (lh_bits.mask (),
+                                       TYPE_SIGN (lh.type ())));
       break;
     case GIMPLE_BINARY_RHS:
       bit_value_binop (code, sign, prec, &widest_value, &widest_mask,
ought to fix this.  Of course even better would be rewrite tree-ssa-cpp.cc to
use wide_int rather than widest_int, but I'm afraid that is stage1 material.

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

* [Bug tree-optimization/113756] [14 regression] Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87
  2024-02-04 14:14 [Bug tree-optimization/113756] New: Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87 shaohua.li at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2024-02-06 15:59 ` jakub at gcc dot gnu.org
@ 2024-02-06 16:05 ` jakub at gcc dot gnu.org
  2024-02-07  9:59 ` cvs-commit at gcc dot gnu.org
  2024-02-07 10:00 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-06 16:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 57342
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57342&action=edit
gcc14-pr113756.patch

Full untested patch.

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

* [Bug tree-optimization/113756] [14 regression] Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87
  2024-02-04 14:14 [Bug tree-optimization/113756] New: Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87 shaohua.li at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2024-02-06 16:05 ` jakub at gcc dot gnu.org
@ 2024-02-07  9:59 ` cvs-commit at gcc dot gnu.org
  2024-02-07 10:00 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-07  9:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC 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:29998cc8a21b3a52f706275923166cd1f95d0555

commit r14-8837-g29998cc8a21b3a52f706275923166cd1f95d0555
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Feb 7 10:59:06 2024 +0100

    range-op: Fix up ABSU_EXPR handling [PR113756]

    ABSU_EXPR unary expr is special because it has a signed integer
    argument and unsigned integer result (of the same precision).

    The following testcase is miscompiled since ABSU_EXPR handling has
    been added to range-op because it uses widest_int::from with the
    result sign (i.e. UNSIGNED) rather than the operand sign (i.e. SIGNED),
    so e.g. for the 32-bit int argument mask ends up 0xffffffc1 or something
    similar and even when it has most significant bit in the precision set,
    in widest_int (tree-ssa-ccp.cc really should stop using widest_int, but
    that is I think stage1 task) it doesn't appear to be negative and so
    bit_value_unop ABSU_EXPR doesn't set the resulting mask/value from
    oring of the argument and its negation.

    Fixed thusly, not doing that for GIMPLE_BINARY_RHS because I don't know
    about a binary op that would need something similar.

    2024-02-06  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/113756
            * range-op.cc (update_known_bitmask): For GIMPLE_UNARY_RHS,
            use TYPE_SIGN (lh.type ()) instead of sign for widest_int::from
            of lh_bits value and mask.

            * gcc.dg/pr113756.c: New test.

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

* [Bug tree-optimization/113756] [14 regression] Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87
  2024-02-04 14:14 [Bug tree-optimization/113756] New: Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87 shaohua.li at inf dot ethz.ch
                   ` (5 preceding siblings ...)
  2024-02-07  9:59 ` cvs-commit at gcc dot gnu.org
@ 2024-02-07 10:00 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-02-07 10:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2024-02-07 10:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-04 14:14 [Bug tree-optimization/113756] New: Wrong code at -O2 on x86_64-linux-gnu since r14-2780-g39f117d6c87 shaohua.li at inf dot ethz.ch
2024-02-04 18:13 ` [Bug tree-optimization/113756] " pinskia at gcc dot gnu.org
2024-02-04 18:17 ` pinskia at gcc dot gnu.org
2024-02-05  9:04 ` [Bug tree-optimization/113756] [14 regression] " rguenth at gcc dot gnu.org
2024-02-06 15:59 ` jakub at gcc dot gnu.org
2024-02-06 16:05 ` jakub at gcc dot gnu.org
2024-02-07  9:59 ` cvs-commit at gcc dot gnu.org
2024-02-07 10:00 ` 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).