public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/105261] New: schedule-insns2 and ipa-sra make alive constant variables not available
@ 2022-04-13 11:28 assaiante at diag dot uniroma1.it
  2022-04-13 13:34 ` [Bug debug/105261] " assaiante at diag dot uniroma1.it
  2022-11-07  5:05 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: assaiante at diag dot uniroma1.it @ 2022-04-13 11:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105261
           Summary: schedule-insns2 and ipa-sra make alive constant
                    variables not available
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: assaiante at diag dot uniroma1.it
  Target Milestone: ---

In this minimized C example, none of the local variables from function b is
available when stepping on the call to function test() from another module,
despite the function taking them all as arguments. This happens when the
optimization level is -O2/-O3 or -Os/-Oz.

At -O2/-O3, a combination of schedule-insns2 and ipa-sra is behind the
incomplete DWARF information for variables l_5, l_53, l_54, l_55 and l_362
(note that all them are constant), as there is no const value or location
attribute for them. DWARF information for i and j is correctly computed but the
variables are not shown when debugging due to a possible gdb 11.2 bug.

At -Os/-Oz, the issue is caused by ipa-sra alone. By disabling it, all
variables appear in the frame and with their value available. 

Please find below a detailed analysis for -O2 on x64 and a quick assessment on
past gcc versions where the issue is sometimes not present.


$ cat a.c
int a;
static int b()
{
    int l_5 = 0,  l_54 = 5,  l_362 = 4,  i, j;
    short l_53 = 4,  l_55 = 0;
    i = 0;
    for (; i < 6; i++)
        j = a ;
    test(l_5, l_53, l_54, l_55, l_362, i, j);
}
int main ()
{
    b();
}

$ cat lib.c
#include <stdio.h>

void test(int l_5, int l_53, int l_54, int l_55, int l_362, int i, int j) {
    printf("%d %d %d %d %d %d %d", l_5, l_53, l_54, l_55, l_362, i, j);
}

GCC and GDB version:
- gcc (GCC) 12.0.0 20211227 (experimental) - commit id: 500d3f0a302
- GNU gdb (GDB) 11.2

GDB trace:
$ gcc -O2 -g a.c lib.c -o opt
$ gdb -q opt
Reading symbols from opt...
(gdb) b 9
Breakpoint 1 at 0x400410: file a.c, line 9.
(gdb) r
Starting program: /tmp/opt 

Breakpoint 1, main () at a.c:9
9           test(l_5, l_53, l_54, l_55, l_362, i, j);
(gdb) info loc
No locals.

ASM at -O2:
0000000000400410 <main>:
  400410:       48 83 ec 10             sub    $0x10,%rsp
  400414:       8b 05 1a 0c 20 00       mov    0x200c1a(%rip),%eax        #
601034 <a>
  40041a:       31 c9                   xor    %ecx,%ecx
  40041c:       31 ff                   xor    %edi,%edi
  40041e:       41 b9 06 00 00 00       mov    $0x6,%r9d
  400424:       41 b8 04 00 00 00       mov    $0x4,%r8d
  40042a:       ba 05 00 00 00          mov    $0x5,%edx
  40042f:       be 04 00 00 00          mov    $0x4,%esi
  400434:       50                      push   %rax
  400435:       31 c0                   xor    %eax,%eax
  400437:       e8 04 01 00 00          callq  400540 <test>
  40043c:       31 c0                   xor    %eax,%eax
  40043e:       48 83 c4 18             add    $0x18,%rsp
  400442:       c3                      retq


DWARF info at -O2:
0x00000093:         DW_TAG_variable
                      DW_AT_abstract_origin     (0x00000104 "l_5")

0x00000098:         DW_TAG_variable
                      DW_AT_abstract_origin     (0x0000010e "l_54")

0x0000009d:         DW_TAG_variable
                      DW_AT_abstract_origin     (0x00000119 "l_362")

0x000000a2:         DW_TAG_variable
                      DW_AT_abstract_origin     (0x00000124 "i")
                      DW_AT_location    (0x0000001a: 
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit0,
DW_OP_stack_value
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit1,
DW_OP_stack_value
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit2,
DW_OP_stack_value
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit3,
DW_OP_stack_value
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit4,
DW_OP_stack_value
                         [0x0000000000400410, 0x0000000000400410): DW_OP_lit5,
DW_OP_stack_value
                         [0x0000000000400410, 0x000000000040043c): DW_OP_lit6,
DW_OP_stack_value)
                      DW_AT_GNU_locviews        (0x0000000c)

0x000000af:         DW_TAG_variable
                      DW_AT_abstract_origin     (0x0000012c "j")
                      DW_AT_location    (0x00000050: 
                         [0x0000000000400410, 0x000000000040043b): DW_OP_addr
0x601034)
                      DW_AT_GNU_locviews        (0x0000004e)

0x000000bc:         DW_TAG_variable
                      DW_AT_abstract_origin     (0x00000134 "l_53")

0x000000c1:         DW_TAG_variable
                      DW_AT_abstract_origin     (0x0000013f "l_55")

>From DWARF info we can see how only variables i and j have correctly defined
locations and values, but those are not shown during debugging due to a
possible bug in gdb 11.2 that we report separately.

All the other variables have no const value or location attribute associated
with, thus they are not available regardless of the debugger.

Through some testing we found out that the optimizations that make the variable
not available are -fschedule-insns2 and -fipa-sra. If we add
-fno-schedule-insns2 and -fno-ipa-sra to the previous compilation command line,
all the variables are available.

In particular, if we add only -fno-schedule-insns2, only variables i and j
become available (the DWARF changes and gdb 11.2 can display them). If we add
both flags, all the variables become available, but if we add only -fipa-sra
nothing changes and no locals are displayed.

ASM at -O2 with -fno-schedule-insns2 and -fno-ipa-sra:
0000000000400410 <main>:
  400410:       48 83 ec 10             sub    $0x10,%rsp
  400414:       8b 05 1a 0c 20 00       mov    0x200c1a(%rip),%eax        #
601034 <a>
  40041a:       50                      push   %rax
  40041b:       41 b9 06 00 00 00       mov    $0x6,%r9d
  400421:       41 b8 04 00 00 00       mov    $0x4,%r8d
  400427:       31 c9                   xor    %ecx,%ecx
  400429:       ba 05 00 00 00          mov    $0x5,%edx
  40042e:       be 04 00 00 00          mov    $0x4,%esi
  400433:       31 ff                   xor    %edi,%edi
  400435:       31 c0                   xor    %eax,%eax
  400437:       e8 04 01 00 00          callq  400540 <test>
  40043c:       31 c0                   xor    %eax,%eax
  40043e:       48 83 c4 18             add    $0x18,%rsp
  400442:       c3                      retq


DWARF at -O2 with -fno-schedule-insns2 and -fno-ipa-sra:
0x0000009a:       DW_TAG_variable
                    DW_AT_abstract_origin       (0x0000010f "l_5")
                    DW_AT_const_value   (0x00)

0x000000a0:       DW_TAG_variable
                    DW_AT_abstract_origin       (0x00000119 "l_54")
                    DW_AT_const_value   (0x05)

0x000000a6:       DW_TAG_variable
                    DW_AT_abstract_origin       (0x00000124 "l_362")
                    DW_AT_const_value   (0x04)

0x000000ac:       DW_TAG_variable
                    DW_AT_abstract_origin       (0x0000012f "i")
                    DW_AT_location      (0x0000001a: 
                       [0x0000000000400414, 0x0000000000400414): DW_OP_lit0,
DW_OP_stack_value
                       [0x0000000000400414, 0x0000000000400414): DW_OP_lit1,
DW_OP_stack_value
                       [0x0000000000400414, 0x0000000000400414): DW_OP_lit2,
DW_OP_stack_value
                       [0x0000000000400414, 0x0000000000400414): DW_OP_lit3,
DW_OP_stack_value
                       [0x0000000000400414, 0x0000000000400414): DW_OP_lit4,
DW_OP_stack_value
                       [0x0000000000400414, 0x0000000000400414): DW_OP_lit5,
DW_OP_stack_value
                       [0x0000000000400414, 0x000000000040043c): DW_OP_lit6,
DW_OP_stack_value)
                    DW_AT_GNU_locviews  (0x0000000c)

0x000000b9:       DW_TAG_variable
                    DW_AT_abstract_origin       (0x00000137 "j")
                    DW_AT_location      (0x00000050: 
                       [0x0000000000400414, 0x000000000040043b): DW_OP_addr
0x601034)
                    DW_AT_GNU_locviews  (0x0000004e)

0x000000c6:       DW_TAG_variable
                    DW_AT_abstract_origin       (0x0000013f "l_53")
                    DW_AT_const_value   (0x04)

0x000000cc:       DW_TAG_variable
                    DW_AT_abstract_origin       (0x0000014a "l_55")
                    DW_AT_const_value   (0x00)


For -O2/O3 we tested older gcc versions (6.4, 7.5, 8.4, 9.3, 10.3, 11.1) and
the results are identical to the git version starting with gcc-8. For previous
versions the variables and their values are correctly available. For -Os/Oz the
issue appears instead starting with gcc-10.

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

* [Bug debug/105261] schedule-insns2 and ipa-sra make alive constant variables not available
  2022-04-13 11:28 [Bug debug/105261] New: schedule-insns2 and ipa-sra make alive constant variables not available assaiante at diag dot uniroma1.it
@ 2022-04-13 13:34 ` assaiante at diag dot uniroma1.it
  2022-11-07  5:05 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: assaiante at diag dot uniroma1.it @ 2022-04-13 13:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Cristian Assaiante <assaiante at diag dot uniroma1.it> ---
The gdb bug report can be found at:
https://sourceware.org/bugzilla/show_bug.cgi?id=29060

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

* [Bug debug/105261] schedule-insns2 and ipa-sra make alive constant variables not available
  2022-04-13 11:28 [Bug debug/105261] New: schedule-insns2 and ipa-sra make alive constant variables not available assaiante at diag dot uniroma1.it
  2022-04-13 13:34 ` [Bug debug/105261] " assaiante at diag dot uniroma1.it
@ 2022-11-07  5:05 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-07  5:05 UTC (permalink / raw)
  To: gcc-bugs

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

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> ---
The IPA-SRA issue seems to be fixed on the trunk.

That is in the optimized dump we now have:

  # DEBUG BEGIN_STMT
  # DEBUG INLINE_ENTRY b
  # DEBUG BEGIN_STMT
  # DEBUG l_5 => 0
  # DEBUG l_54 => 5
  # DEBUG l_362 => 4
  # DEBUG BEGIN_STMT
  # DEBUG l_53 => 4
  # DEBUG l_55 => 0

While in GCC 12 we did not have that.


The scheduler issue I have not looked into at all since it is harder to figure
out RTL level debug info really.

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

end of thread, other threads:[~2022-11-07  5:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13 11:28 [Bug debug/105261] New: schedule-insns2 and ipa-sra make alive constant variables not available assaiante at diag dot uniroma1.it
2022-04-13 13:34 ` [Bug debug/105261] " assaiante at diag dot uniroma1.it
2022-11-07  5:05 ` pinskia 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).