public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2
@ 2021-05-26 21:12 tlwang at uwaterloo dot ca
  2021-05-26 21:30 ` [Bug tree-optimization/100781] [12 Regression] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: tlwang at uwaterloo dot ca @ 2021-05-26 21:12 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100781
           Summary: Emitted binary code changes when -g is enabled at -O2
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tlwang at uwaterloo dot ca
  Target Milestone: ---

The .text section for the following program (transformed_program0.c) changes
after toggling the -g flag. 

$ cat transformed_program0.c
struct a {
  int b;
};
long c(short d, long e, struct a f) {
g:;
  int h = f.b <= e, i = d, n = h >= d;
  if (!n)
    goto j;
  goto k;
j:;
  long l = 5;
  if (l)
    goto m;
  d = 0;
m:
  if (d)
    return f.b;
k:
  goto g;
}
int main() {}
$
$ 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.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/tmp.tVhv2eaPzV-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.0 20210526 (experimental) [master revision
:21638bbbf:1fd76b24306ed4df4cf9e797d900699ed59ce7f7] (GCC)
$
$ gcc-trunk transformed_program0.c -O2 -w ; objdump --disassemble a.out >
"no-g.txt"
$ gcc-trunk transformed_program0.c -O2 -w -g; objdump --disassemble a.out >
"g.txt"
$ diff no-g.txt g.txt
108,111c108,111
<   401125:     89 f9                   mov    %edi,%ecx
<   401127:     0f bf ff                movswl %di,%edi
<   40112a:     49 39 f0                cmp    %rsi,%r8
<   40112d:     0f 9e c0                setle  %al
---
>   401125:	0f bf ff             	movswl %di,%edi
>   401128:	4c 39 c6             	cmp    %r8,%rsi
>   40112b:	0f 9d c0             	setge  %al
>   40112e:	66 90                	xchg   %ax,%ax
114,118c114,117
<   401134:     66 85 c9                test   %cx,%cx
<   401137:     74 f7                   je     401130 <c+0x10>
<   401139:     4c 89 c0                mov    %r8,%rax
<   40113c:     c3                      retq
<   40113d:     0f 1f 00                nopl   (%rax)
---
>   401134:	4c 89 c0             	mov    %r8,%rax
>   401137:	c3                   	retq
>   401138:	0f 1f 84 00 00 00 00 	nopl   0x0(%rax,%rax,1)
>   40113f:	00

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

* [Bug tree-optimization/100781] [12 Regression] Emitted binary code changes when -g is enabled at -O2
  2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
@ 2021-05-26 21:30 ` pinskia at gcc dot gnu.org
  2021-05-26 21:31 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-26 21:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Emitted binary code changes |[12 Regression] Emitted
                   |when -g is enabled at -O2   |binary code changes when -g
                   |                            |is enabled at -O2
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-05-26
   Target Milestone|---                         |12.0

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
apinski@xeond:~/src/upstream-gcc/gcc/objdir/stage1-gcc$ ./xgcc -B.
-fcompare-debug -O2 t.c
xgcc: error: t.c: ‘-fcompare-debug’ failure (length)

This is a recent regression, it worked with 20210523.

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

* [Bug tree-optimization/100781] [12 Regression] Emitted binary code changes when -g is enabled at -O2
  2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
  2021-05-26 21:30 ` [Bug tree-optimization/100781] [12 Regression] " pinskia at gcc dot gnu.org
@ 2021-05-26 21:31 ` pinskia at gcc dot gnu.org
  2021-05-26 21:33 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-26 21:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
apinski@xeond:~/src/upstream-gcc/gcc/objdir/stage1-gcc$ ./xgcc -B.
-fcompare-debug -O2 t.c
xgcc: error: t.c: ‘-fcompare-debug’ failure (length)

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

* [Bug tree-optimization/100781] [12 Regression] Emitted binary code changes when -g is enabled at -O2
  2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
  2021-05-26 21:30 ` [Bug tree-optimization/100781] [12 Regression] " pinskia at gcc dot gnu.org
  2021-05-26 21:31 ` pinskia at gcc dot gnu.org
@ 2021-05-26 21:33 ` pinskia at gcc dot gnu.org
  2021-05-26 21:38 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-26 21:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
At least I thought this is related to PR 100774 but this was introduced after
the patch which introduced that one.

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

* [Bug tree-optimization/100781] [12 Regression] Emitted binary code changes when -g is enabled at -O2
  2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
                   ` (2 preceding siblings ...)
  2021-05-26 21:33 ` pinskia at gcc dot gnu.org
@ 2021-05-26 21:38 ` pinskia at gcc dot gnu.org
  2021-05-27  6:20 ` aldyh at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-05-26 21:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The first major difference shows up in evrp.

With debugging info turned on we get:

Merging blocks 4 and 6
Merging blocks 5 and 7

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

* [Bug tree-optimization/100781] [12 Regression] Emitted binary code changes when -g is enabled at -O2
  2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
                   ` (3 preceding siblings ...)
  2021-05-26 21:38 ` pinskia at gcc dot gnu.org
@ 2021-05-27  6:20 ` aldyh at gcc dot gnu.org
  2021-05-27 18:13 ` amacleod at redhat dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-05-27  6:20 UTC (permalink / raw)
  To: gcc-bugs

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

Aldy Hernandez <aldyh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aldyh at gcc dot gnu.org,
                   |                            |amacleod at redhat dot com

--- Comment #5 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
Started with: c21644704160710a17d1ea6c1cd212e079cd5e36

commit c21644704160710a17d1ea6c1cd212e079cd5e36 (HEAD)
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Tue May 25 14:15:50 2021 -0400

    Add imports and strengthen the export definition in range_def and gori_map.

    All add up to 2 direct dependencies for each ssa-name.
    Add gori import/export iterators.

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

* [Bug tree-optimization/100781] [12 Regression] Emitted binary code changes when -g is enabled at -O2
  2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
                   ` (4 preceding siblings ...)
  2021-05-27  6:20 ` aldyh at gcc dot gnu.org
@ 2021-05-27 18:13 ` amacleod at redhat dot com
  2021-06-01  1:32 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: amacleod at redhat dot com @ 2021-05-27 18:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Macleod <amacleod at redhat dot com> ---
So the new code base provides a more complete/consistent export list, and makes
use of imports now.  An import is the incoming value which can change an
outgoing value.
In this particular case we see:
<bb 3> :
  _2 = (long int) f$b_17;
 _3 = _2 <= e_12(D);
 h_13 = (int) _3;
 i_14 = (int) d_10(D);
 _5 = h_13 >= i_14;
 n_15 = (int) _5;
 if (h_13 < i_14)
   goto <bb 4>; [INV]
 else
   goto <bb 5>; [INV]

 <bb 4> :
 // predicted unlikely by goto predictor.
 // predicted unlikely by goto predictor.
 if (d_10(D) != 0)
   goto <bb 6>; [INV]
 else
   goto <bb 7>; [INV]

We look at more of these names than we use to, and f$b_17 is now taken into
account. bb3 has a back edge from bb9, so we do a little back edge tracking
earlier than we use to.
Long story short:  During the initial traversal, none of the other names in the
block have yet been fully fleshed out when we arrive back at bb3 from the
bottom, so the propagation engine uses global values as an initial value.
In particular, we use h_13 which has none, so defaults to VARYING. And in "if
h_13 < i_14", that gives us nothing for d_10.
however, we later process h_13 = (int)_3, and discover it is actually [0,1]
since _3 is a boolean.
We propagate this new [0,1] value, but since it isnt in the dependency chain
for d_10, we never re-evaluate d_10.

Previously, the first time we evaluate d_10 we see that the edge 3->4 requires  
[0,1] < i_14 to be true, which means i_14 = [1, +INF] which also means that
d_10 is non-zero and we fold the condition.

The next round of GORI code I'm about to check in makes it fair straightforward
to grab an initial value for h_13 even if it hasn't been fully evaluated yet..
so instead of VARYING, we'll get the [0,1] range for h_13, and everything will
return to the way it was.

There is more update/propagation/ordering stuff to come, but I suspect the
forthcoming changes will resolve most of these sorts of issues.

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

* [Bug tree-optimization/100781] [12 Regression] Emitted binary code changes when -g is enabled at -O2
  2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
                   ` (5 preceding siblings ...)
  2021-05-27 18:13 ` amacleod at redhat dot com
@ 2021-06-01  1:32 ` cvs-commit at gcc dot gnu.org
  2021-06-01  1:36 ` amacleod at redhat dot com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-01  1:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Andrew Macleod <amacleod@gcc.gnu.org>:

https://gcc.gnu.org/g:715914d3f9e4e40af58d22103c7650cdd720ef92

commit r12-1137-g715914d3f9e4e40af58d22103c7650cdd720ef92
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Mon May 31 12:13:50 2021 -0400

    Do not calculate new values when evaluating a debug statement.

    Add a flag to enable/disable immediately improving poor values found during
    cache propagation. Then disable it when processing debug statements.

            gcc/
            PR tree-optimization/100781
            * gimple-range-cache.cc (ranger_cache::ranger_cache): Enable new
            value calculation by default.
            (ranger_cache::enable_new_values): New.
            (ranger_cache::disable_new_values): New.
            (ranger_cache::push_poor_value): Check if new values are allowed.
            * gimple-range-cache.h (class ranger_cache): New member/methods.
            * gimple-range.cc (gimple_ranger::range_of_expr): Check for debug
            statement, and disable/renable new value calculation.

            gcc/testsuite/
            PR tree-optimization/100781
            * gcc.dg/pr100781.c: New.

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

* [Bug tree-optimization/100781] [12 Regression] Emitted binary code changes when -g is enabled at -O2
  2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
                   ` (6 preceding siblings ...)
  2021-06-01  1:32 ` cvs-commit at gcc dot gnu.org
@ 2021-06-01  1:36 ` amacleod at redhat dot com
  2021-06-01  1:36 ` amacleod at redhat dot com
  2021-07-14 21:58 ` cvs-commit at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: amacleod at redhat dot com @ 2021-06-01  1:36 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

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

* [Bug tree-optimization/100781] [12 Regression] Emitted binary code changes when -g is enabled at -O2
  2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
                   ` (7 preceding siblings ...)
  2021-06-01  1:36 ` amacleod at redhat dot com
@ 2021-06-01  1:36 ` amacleod at redhat dot com
  2021-07-14 21:58 ` cvs-commit at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: amacleod at redhat dot com @ 2021-06-01  1:36 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Macleod <amacleod at redhat dot com> changed:

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

--- Comment #8 from Andrew Macleod <amacleod at redhat dot com> ---
Should be Fixed.

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

* [Bug tree-optimization/100781] [12 Regression] Emitted binary code changes when -g is enabled at -O2
  2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
                   ` (8 preceding siblings ...)
  2021-06-01  1:36 ` amacleod at redhat dot com
@ 2021-07-14 21:58 ` cvs-commit at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-14 21:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Andrew Macleod
<amacleod@gcc.gnu.org>:

https://gcc.gnu.org/g:263a7e20c88a35bdfaebfac3c9abb313c5867590

commit r11-8747-g263a7e20c88a35bdfaebfac3c9abb313c5867590
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Tue Jun 8 09:43:17 2021 -0400

    Don't process lookups for debug statements in Ranger.

    Although PR 100781 is not an issue in GCC11, its possible that a similar
    situation may arise.  The identical fix cannot be easily introduced.
    With EVRP always running in hybrid mode, there is no need for ranger to
    spawn a lookup for a debug statement in this release.

            * gimple-range.cc (gimple_ranger::range_of_expr): Treat debug
statments
            as contextless queries to avoid additional lookups.

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

end of thread, other threads:[~2021-07-14 21:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-26 21:12 [Bug tree-optimization/100781] New: Emitted binary code changes when -g is enabled at -O2 tlwang at uwaterloo dot ca
2021-05-26 21:30 ` [Bug tree-optimization/100781] [12 Regression] " pinskia at gcc dot gnu.org
2021-05-26 21:31 ` pinskia at gcc dot gnu.org
2021-05-26 21:33 ` pinskia at gcc dot gnu.org
2021-05-26 21:38 ` pinskia at gcc dot gnu.org
2021-05-27  6:20 ` aldyh at gcc dot gnu.org
2021-05-27 18:13 ` amacleod at redhat dot com
2021-06-01  1:32 ` cvs-commit at gcc dot gnu.org
2021-06-01  1:36 ` amacleod at redhat dot com
2021-06-01  1:36 ` amacleod at redhat dot com
2021-07-14 21:58 ` cvs-commit 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).