public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/107493] New: Wrong code at -Os on x86_64-linux-gnu
@ 2022-11-01 11:49 shaohua.li at inf dot ethz.ch
  2022-11-01 15:25 ` [Bug tree-optimization/107493] [13 Regression] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2022-11-01 11:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107493
           Summary: Wrong code at -Os on x86_64-linux-gnu
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

% gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-db55f1dda2692c3f778ae783bc7121891c79aec4/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-db55f1dda2692c3f778ae783bc7121891c79aec4
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.0 20221031 (experimental) (GCC) 
% 
% gcc-tk -O0 a.c && ./a.out
65525
% gcc-tk -Os a.c && ./a.out
65515
%
% cat a.c
int printf(const char *format, ...);
int a;
int b(int c) { 
    return c; 
}
int main() {
  a = -21;
  for (; a <= 0; a = (unsigned short)(b(a + 2) + 8))
    ;
  printf("%d\n", a);
}
%

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

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

* [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu
  2022-11-01 11:49 [Bug c/107493] New: Wrong code at -Os on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
@ 2022-11-01 15:25 ` pinskia at gcc dot gnu.org
  2022-11-01 15:27 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-01 15:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |12.1.0
   Last reconfirmed|                            |2022-11-01
      Known to fail|                            |13.0
     Ever confirmed|0                           |1
            Summary|Wrong code at -Os on        |[13 Regression] Wrong code
                   |x86_64-linux-gnu            |at -Os on x86_64-linux-gnu
   Target Milestone|---                         |13.0
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
sccp is broken:

Estimating # of iterations of loop 1
Statement (exit)if (a_lsm.10_13 <= 0)
 is executed at most 0 (bounded by 0) + 1 times in loop 1.
Induction variable (int) 65517 + 10 * iteration does not wrap in statement _1 =
a_lsm.10_13 + 2;
 in loop 1.
Statement _1 = a_lsm.10_13 + 2;
 is executed at most 429490178 (bounded by 429490178) + 1 times in loop 1.
Induction variable (int) 65525 + 10 * iteration does not wrap in statement _4 =
(int) _3;
 in loop 1.
Statement _4 = (int) _3;
 is executed at most 1 (bounded by 1) + 1 times in loop 1.

final value replacement:
  a_lsm.10_14 = PHI <a_lsm.10_13(4)>
 with expr: 65515
 final stmt:
  a_lsm.10_14 = 65515;

Confirmed.

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

* [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu
  2022-11-01 11:49 [Bug c/107493] New: Wrong code at -Os on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
  2022-11-01 15:25 ` [Bug tree-optimization/107493] [13 Regression] " pinskia at gcc dot gnu.org
@ 2022-11-01 15:27 ` pinskia at gcc dot gnu.org
  2022-11-05 10:37 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-01 15:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
self contained testcase:
int a;
int b(int c) { 
    return c; 
}
int main() {
  a = -21;
  for (; a <= 0; a = (unsigned short)(b(a + 2) + 8))
    ;
  if (a != 65525)
    __builtin_abort();
 // __builtin_printf("%d\n", a);
}

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

* [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu
  2022-11-01 11:49 [Bug c/107493] New: Wrong code at -Os on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
  2022-11-01 15:25 ` [Bug tree-optimization/107493] [13 Regression] " pinskia at gcc dot gnu.org
  2022-11-01 15:27 ` pinskia at gcc dot gnu.org
@ 2022-11-05 10:37 ` rguenth at gcc dot gnu.org
  2022-11-08 13:29 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-11-05 10:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
I will have a look, possibly fallout of the PR107176 fix.

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

* [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu
  2022-11-01 11:49 [Bug c/107493] New: Wrong code at -Os on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2022-11-05 10:37 ` rguenth at gcc dot gnu.org
@ 2022-11-08 13:29 ` rguenth at gcc dot gnu.org
  2022-11-21 12:17 ` [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3486-g4c5b116077638277 marxin at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-11-08 13:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
a_lsm.9_12 = PHI <-21(2), _4(3)>

(set_scalar_evolution
  instantiated_below = 2
  (scalar = a_lsm.9_12)
  (scalar_evolution = (int) {65515, +, 10}_1))

is definitely wrong since the initial value is off.  The evolution after
that looks OK though, so not sure why SCCP gets the wrong final value here,
we compute the number of iterations to zero (also wrong).

It goes wrong when we get to the truncation, we then do

        *evolution_of_loop = chrec_convert (type, *evolution_of_loop, at_stmt);

with {-21, + 2}_1 converting that to unsigned short.  This ends up in
convert_affine_scev but that assumes it converts the cycle and not that
the conversion is inside the cycle.

The old sanity checking of the initial value would have catched this but the
actual error is elsewhere.  The question is what's valid here.  I'm going to
try restricting this all further.

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

* [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3486-g4c5b116077638277
  2022-11-01 11:49 [Bug c/107493] New: Wrong code at -Os on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2022-11-08 13:29 ` rguenth at gcc dot gnu.org
@ 2022-11-21 12:17 ` marxin at gcc dot gnu.org
  2022-11-22  8:09 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-11-21 12:17 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[13 Regression] Wrong code  |[13 Regression] Wrong code
                   |at -Os on x86_64-linux-gnu  |at -Os on x86_64-linux-gnu
                   |                            |since
                   |                            |r13-3486-g4c5b116077638277
                 CC|                            |marxin at gcc dot gnu.org
           Keywords|needs-bisection             |

--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r13-3486-g4c5b116077638277.

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

* [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3486-g4c5b116077638277
  2022-11-01 11:49 [Bug c/107493] New: Wrong code at -Os on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2022-11-21 12:17 ` [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3486-g4c5b116077638277 marxin at gcc dot gnu.org
@ 2022-11-22  8:09 ` rguenth at gcc dot gnu.org
  2022-11-28 10:17 ` cvs-commit at gcc dot gnu.org
  2022-11-28 10:18 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-11-22  8:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

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


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107176
[Bug 107176] [10/11/12 Regression] Wrong code at -Os on x86_64-pc-linux-gnu
since r7-2012-g43aabfcfd4139e4c

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

* [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3486-g4c5b116077638277
  2022-11-01 11:49 [Bug c/107493] New: Wrong code at -Os on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
                   ` (5 preceding siblings ...)
  2022-11-22  8:09 ` rguenth at gcc dot gnu.org
@ 2022-11-28 10:17 ` cvs-commit at gcc dot gnu.org
  2022-11-28 10:18 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-28 10:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:2b293a949c0fbe21e47c4bc99f807dc941c02bb6

commit r13-4357-g2b293a949c0fbe21e47c4bc99f807dc941c02bb6
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Nov 28 10:25:44 2022 +0100

    tree-optimization/107493 - SCEV analysis with conversions

    This shows another case where trying to validate conversions during
    the CHREC SCC analysis fails because said analysis assumes we are
    converting a complete SCC.  Like the constraint on the initial
    conversion seen restrict all conversions handled to sign-changes.

            PR tree-optimization/107493
            * tree-scalar-evolution.cc (scev_dfs::follow_ssa_edge_expr):
            Only handle no-op and sign-changing conversions.

            * gcc.dg/torture/pr107493.c: New testcase.

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

* [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3486-g4c5b116077638277
  2022-11-01 11:49 [Bug c/107493] New: Wrong code at -Os on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
                   ` (6 preceding siblings ...)
  2022-11-28 10:17 ` cvs-commit at gcc dot gnu.org
@ 2022-11-28 10:18 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-11-28 10:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2022-11-28 10:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01 11:49 [Bug c/107493] New: Wrong code at -Os on x86_64-linux-gnu shaohua.li at inf dot ethz.ch
2022-11-01 15:25 ` [Bug tree-optimization/107493] [13 Regression] " pinskia at gcc dot gnu.org
2022-11-01 15:27 ` pinskia at gcc dot gnu.org
2022-11-05 10:37 ` rguenth at gcc dot gnu.org
2022-11-08 13:29 ` rguenth at gcc dot gnu.org
2022-11-21 12:17 ` [Bug tree-optimization/107493] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3486-g4c5b116077638277 marxin at gcc dot gnu.org
2022-11-22  8:09 ` rguenth at gcc dot gnu.org
2022-11-28 10:17 ` cvs-commit at gcc dot gnu.org
2022-11-28 10:18 ` rguenth 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).