public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104156] New: -fcompare-debug failure with -O3
@ 2022-01-21  4:57 cnsun at uwaterloo dot ca
  2022-01-21  8:17 ` [Bug tree-optimization/104156] [12 Regression] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: cnsun at uwaterloo dot ca @ 2022-01-21  4:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104156
           Summary: -fcompare-debug failure with -O3
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cnsun at uwaterloo dot ca
  Target Milestone: ---

$ gcc-trunk -fcompare-debug -O3 small.c
gcc-trunk: error: small.c: ‘-fcompare-debug’ failure (length)
$ 
$ cat small.c
short a, d;
int b, c;
static int e() {
  int f = -2L, g = 9, h = 0;
  for (; h < 2; h++)
    if (a <= 5) {
      g = 0;
      if (c && a)
        break;
      if (c - 1)
        goto i;
    }
  if (b) {
    int *j[] = {&f};
    if (d)
      for (; f < 9; f++)
        if (g)
          for (; f; f++)
            ;
  i:
    while (f) {
      a--;
      break;
    }
  }
}
int main() { e(); }
$ 
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/scratch/software/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/12.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/tmp.ahmEMGgtK2-gcc-builder/gcc/configure
--enable-languages=c,c++,lto --enable-checking-yes --enable-multiarch
--prefix=/scratch/software/gcc-trunk --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.1 20220120 (experimental) [master -g30f2c22de] (GCC) 
$

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

* [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O3
  2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
@ 2022-01-21  8:17 ` pinskia at gcc dot gnu.org
  2022-01-21  8:27 ` [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b marxin at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-21  8:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
   Last reconfirmed|                            |2022-01-21
            Version|unknown                     |12.0
     Ever confirmed|0                           |1
           Keywords|                            |needs-bisection
             Status|UNCONFIRMED                 |NEW
          Component|middle-end                  |tree-optimization

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. -O2 -funswitch-loops is enough to produce the failure. and yes the
first difference in the IR (minus the debug statements) between -g and -g0 is
150t.unswitch .

--- t.gk.c.150t.unswitch        2022-01-21 07:55:45.860933512 +0000
+++ t.c.150t.unswitch   2022-01-21 07:55:45.623933488 +0000
@@ -1,6 +1,30 @@

 ;; Function main (main, funcdef_no=1, decl_uid=2004, cgraph_uid=2,
symbol_order=5) (executed once)

+
+SSA replacement table
+N_i -> { O_1 ... O_j } means that N_i replaces O_1, ..., O_j
+
+.MEM_24 -> { .MEM_42 }
+Incremental SSA update started at block: 2
+Number of blocks in CFG: 36
+Number of blocks to update: 5 ( 14%)

Without the debug statements unswitch does something.

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

* [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b
  2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
  2022-01-21  8:17 ` [Bug tree-optimization/104156] [12 Regression] " pinskia at gcc dot gnu.org
@ 2022-01-21  8:27 ` marxin at gcc dot gnu.org
  2022-01-21  8:42 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-01-21  8:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marxin at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org
           Keywords|needs-bisection             |
            Summary|[12 Regression]             |[12 Regression]
                   |-fcompare-debug failure     |-fcompare-debug failure
                   |with -O2 -funswitch-loops   |with -O2 -funswitch-loops
                   |                            |since
                   |                            |r12-4526-gd8edfadfc7a9795b

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r12-4526-gd8edfadfc7a9795b.

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

* [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b
  2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
  2022-01-21  8:17 ` [Bug tree-optimization/104156] [12 Regression] " pinskia at gcc dot gnu.org
  2022-01-21  8:27 ` [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b marxin at gcc dot gnu.org
@ 2022-01-21  8:42 ` pinskia at gcc dot gnu.org
  2022-01-21  9:00 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-21  8:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #2)
> Started with r12-4526-gd8edfadfc7a9795b.

I suspect this just exposed the issue inside loop unswitch though.

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

* [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b
  2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
                   ` (2 preceding siblings ...)
  2022-01-21  8:42 ` pinskia at gcc dot gnu.org
@ 2022-01-21  9:00 ` rguenth at gcc dot gnu.org
  2022-01-21 11:19 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-21  9:00 UTC (permalink / raw)
  To: gcc-bugs

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

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 #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think it's fixed by

diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc
index a405119b58a..ec1468ab0af 100644
--- a/gcc/tree-ssa-loop-unswitch.cc
+++ b/gcc/tree-ssa-loop-unswitch.cc
@@ -745,6 +745,9 @@ empty_bb_without_guard_p (class loop *loop, basic_block bb)
        !gsi_end_p (gsi); gsi_next (&gsi))
     {
       gimple *stmt = gsi_stmt (gsi);
+      if (is_gimple_debug (stmt))
+       continue;
+
       if (gimple_has_side_effects (stmt))
        return false;

@@ -772,7 +775,8 @@ used_outside_loop_p (class loop *loop, tree name)
   FOR_EACH_IMM_USE_FAST (use, it, name)
     {
       gimple *stmt = USE_STMT (use);
-      if (!flow_bb_inside_loop_p (loop, gimple_bb (stmt)))
+      if (!is_gimple_debug (stmt)
+         && !flow_bb_inside_loop_p (loop, gimple_bb (stmt)))
        return true;
     }

but that exposes

> ./cc1 -quiet t.c -O2 -funswitch-loops -fdump-tree-unswitch-details -g
t.c: In function 'main':
t.c:27:5: error: definition in block 12 does not dominate use in block 15
   27 | int main() { e(); }
      |     ^~~~
for SSA_NAME: _13 in statement:
# DEBUG f => _13
during GIMPLE pass: unswitch
dump file: t.c.152t.unswitch
t.c:27:5: internal compiler error: verify_ssa failed
0x1783a48 verify_ssa(bool, bool)
        /home/rguenther/src/gcc3/gcc/tree-ssa.cc:1211

because we fail to reset debug stmts for such uses.  So there's some work to
be done.  The transform in question is that we're hoisting a guard.

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

* [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b
  2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
                   ` (3 preceding siblings ...)
  2022-01-21  9:00 ` rguenth at gcc dot gnu.org
@ 2022-01-21 11:19 ` cvs-commit at gcc dot gnu.org
  2022-01-21 11:22 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-21 11:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 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:f953c8bc5bf314a57a6ba347ee6f5f5e3f1dad53

commit r12-6790-gf953c8bc5bf314a57a6ba347ee6f5f5e3f1dad53
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 21 10:19:58 2022 +0100

    tree-optimization/104156 - fix unswitching compare-debug issue

    When hoisting guards the unswitching pass does not properly ignore
    debug stmts when looking for uses outside of the loop of defs
    produced in the skipped region.  The following rectifies this
    by instead collecting them and resetting them after the transform.

    2022-01-21  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/104156
            * tree-ssa-loop-unswitch.cc (tree_unswitch_outer_loop):
            Collect and reset debug stmts with out-of-loop uses when
            hoisting guards.
            (find_loop_guard): Adjust.
            (empty_bb_without_guard_p): Likewise.  Ignore debug stmts.
            (used_outside_loop_p): Push debug uses to a vector of
            debug stmts to reset.
            (hoist_guard): Adjust -fopt-info category.

            * gcc.dg/loop-unswitch-6.c: New testcase.

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

* [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b
  2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
                   ` (4 preceding siblings ...)
  2022-01-21 11:19 ` cvs-commit at gcc dot gnu.org
@ 2022-01-21 11:22 ` rguenth at gcc dot gnu.org
  2022-01-22  2:22 ` cnsun at uwaterloo dot ca
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-21 11:22 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk, but the issue is for sure latent everywhere - just not with
this testcase.

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

* [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b
  2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
                   ` (5 preceding siblings ...)
  2022-01-21 11:22 ` rguenth at gcc dot gnu.org
@ 2022-01-22  2:22 ` cnsun at uwaterloo dot ca
  2022-01-22 20:15 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cnsun at uwaterloo dot ca @ 2022-01-22  2:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Chengnian Sun <cnsun at uwaterloo dot ca> ---
A quick question. Besides the flags `-fcompare-debug -g3 -O3`, are there any
other flags I should enable to better/faster find such -fcompare-debug
failures?

Thanks.

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

* [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b
  2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
                   ` (6 preceding siblings ...)
  2022-01-22  2:22 ` cnsun at uwaterloo dot ca
@ 2022-01-22 20:15 ` pinskia at gcc dot gnu.org
  2022-01-22 21:37 ` cnsun at uwaterloo dot ca
  2022-01-24  7:57 ` rguenther at suse dot de
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-22 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Chengnian Sun from comment #7)
> A quick question. Besides the flags `-fcompare-debug -g3 -O3`, are there any
> other flags I should enable to better/faster find such -fcompare-debug
> failures?

-fcompare-debug failures will be spread out through the compiler so I really
doubt there are any flag besides -O2 or -O3 will help in finding the failures
really. Most passes are designed to ignore the debug information statements
(instructions in the case of RTL) but some mistakes happen so I doubt there is
any pattern to them really.

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

* [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b
  2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
                   ` (7 preceding siblings ...)
  2022-01-22 20:15 ` pinskia at gcc dot gnu.org
@ 2022-01-22 21:37 ` cnsun at uwaterloo dot ca
  2022-01-24  7:57 ` rguenther at suse dot de
  9 siblings, 0 replies; 11+ messages in thread
From: cnsun at uwaterloo dot ca @ 2022-01-22 21:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Chengnian Sun <cnsun at uwaterloo dot ca> ---
Thanks, Andrew. 

What about -flto? Does GCC still guarantee such a compilation consistency wrt
to debug info in the presence of -flto?

If yes, I can enable this flag for several testing runs.

Thanks.

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

* [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b
  2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
                   ` (8 preceding siblings ...)
  2022-01-22 21:37 ` cnsun at uwaterloo dot ca
@ 2022-01-24  7:57 ` rguenther at suse dot de
  9 siblings, 0 replies; 11+ messages in thread
From: rguenther at suse dot de @ 2022-01-24  7:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from rguenther at suse dot de <rguenther at suse dot de> ---
On Sat, 22 Jan 2022, cnsun at uwaterloo dot ca wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104156
> 
> --- Comment #9 from Chengnian Sun <cnsun at uwaterloo dot ca> ---
> Thanks, Andrew. 
> 
> What about -flto? Does GCC still guarantee such a compilation consistency wrt
> to debug info in the presence of -flto?

Yes, even with -flto we aim to produce the same code.  Note I'm not 100%
sure that -fcompare-debug works fine on the LTRANS level so you maybe
need to adjust to -flto-partiton=none.

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

end of thread, other threads:[~2022-01-24  7:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-21  4:57 [Bug c/104156] New: -fcompare-debug failure with -O3 cnsun at uwaterloo dot ca
2022-01-21  8:17 ` [Bug tree-optimization/104156] [12 Regression] " pinskia at gcc dot gnu.org
2022-01-21  8:27 ` [Bug tree-optimization/104156] [12 Regression] -fcompare-debug failure with -O2 -funswitch-loops since r12-4526-gd8edfadfc7a9795b marxin at gcc dot gnu.org
2022-01-21  8:42 ` pinskia at gcc dot gnu.org
2022-01-21  9:00 ` rguenth at gcc dot gnu.org
2022-01-21 11:19 ` cvs-commit at gcc dot gnu.org
2022-01-21 11:22 ` rguenth at gcc dot gnu.org
2022-01-22  2:22 ` cnsun at uwaterloo dot ca
2022-01-22 20:15 ` pinskia at gcc dot gnu.org
2022-01-22 21:37 ` cnsun at uwaterloo dot ca
2022-01-24  7:57 ` rguenther at suse dot de

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