Bug 112107 - [14 Regression] bootstrap failure on i686-linux: gcc/ira-build.o differs since r14-4944-gf55cdce3f8dd85
Summary: [14 Regression] bootstrap failure on i686-linux: gcc/ira-build.o differs sinc...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: 14.0
Assignee: Not yet assigned to anyone
URL:
Keywords: compare-debug-failure, ra
Depends on:
Blocks:
 
Reported: 2023-10-27 12:38 UTC by Sergei Trofimovich
Modified: 2023-10-27 21:11 UTC (History)
3 users (show)

See Also:
Host: i686-unknown-linux-gnu
Target: i686-unknown-linux-gnu
Build: i686-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2023-10-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2023-10-27 12:38:07 UTC
Noticed on this week's build on i686-unknown-linux-gnu build/host/target.

How to reproduce against r14-4967-g8697d3a1dcf327:

  $ ../gcc/configure --disable-multilib --enable-languages=c,c++ --enable-languages=c,c++ --enable-checking=release
  $ make STAGE1_CFLAGS=-O2
  ...
   Comparing stages 2 and 3
   Bootstrap comparison failure!
   gcc/ira-build.o differs

$ stage3-gcc/xgcc -Bstage3-gcc -v
Reading specs from stage3-gcc/specs
COLLECT_GCC=stage3-gcc/xgcc
COLLECT_LTO_WRAPPER=stage3-gcc/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: /home/slyfox/dev/git/gcc/configure --disable-multilib --enable-languages=c,c++ --enable-checking=release
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20231027 (experimental) (GCC)
Comment 1 Sergei Trofimovich 2023-10-27 12:54:19 UTC
`diffoscope` says there is a difference in generated code in one of the functions:

$ strip --strip-debug stage2-gcc-ira-build.o stage3-gcc-ira-build.o
$ diffoscope stage2-gcc-ira-build.o stage3-gcc-ira-build.o

│       add    $0x10,%esp
│       mov    $0x1,%edx
│       mov    %eax,0x4(%esi)
│       movl   $0x0,(%eax)
│       movl   $0x0,0x38(%esi)
│ -     jmp    363b <ira_allocate_object_conflicts(ira_object*, int)+0x5b>
│ -     lea    0x0(%esi,%eiz,1),%esi
│ -     lea    0x0(%esi),%esi
│ +     jmp    363c <ira_allocate_object_conflicts(ira_object*, int)+0x5c>
│ +     xchg   %ax,%ax
Comment 2 Sergei Trofimovich 2023-10-27 13:43:51 UTC
Reduced ira-build.cc down to the following:

// $ cat pp.cc.cc
typedef struct ira_object *ira_object_t;
struct ira_object {
  void *conflicts_array;
  int min, max;
};
void *ira_allocate(int);
int ira_conflict_vector_profitable_p_nbytes;
void ira_conflict_vector_profitable_p(ira_object_t obj) {
  int max(obj->max);
  if (max < obj->min)
    ira_conflict_vector_profitable_p_nbytes = max - obj->min;
}
void ira_allocate_object_conflicts(ira_object_t obj) {
  ira_conflict_vector_profitable_p(obj);
  int size((obj->max - obj->min) * sizeof 0);
  obj->conflicts_array = ira_allocate(size);
}

Reproducer:

# cat trigger.bash
#!/usr/bin/env bash

f() {
    stage3-gcc/xg++ -Bstage3-gcc -nostdinc++  -fno-PIE -g -O2 -fchecking=1 -DIN_GCC    -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -fno-PIE -c pp.cc.cc -o pp.o -Wall "$@"
    strip --strip-debug pp.o
    sha1sum pp.o
}

[[ "$(f)" == "$(f -gtoggle)" ]] && echo EQUAL || echo DIFF

Running:

$ ./trigger.bash
DIFF
Comment 3 Richard Biener 2023-10-27 13:48:43 UTC
Confirmed.

> ./xg++ -B. -c -g -O2 -fno-exceptions -fno-rtti t.ii -fcompare-debug -m32
xg++: error: t.ii: '-fcompare-debug' failure (length)
Comment 4 Andrew Pinski 2023-10-27 13:58:51 UTC
Looks like the first difference comes from reload (LRA) .
Comment 5 Sergei Trofimovich 2023-10-27 16:32:30 UTC
Bisected down to r14-4943-g8d2130a4e5ce36 "[RA]: Modfify cost calculation for dealing with equivalences"
Comment 6 Sergei Trofimovich 2023-10-27 16:33:40 UTC
(In reply to Sergei Trofimovich from comment #5)
> Bisected down to r14-4943-g8d2130a4e5ce36 "[RA]: Modfify cost calculation
> for dealing with equivalences"

Sorry, pasted wrong hash. That should be a r14-4944-gf55cdce3f8dd85 "[RA]: Modfify cost calculation for dealing with equivalences"
Comment 7 Vladimir Makarov 2023-10-27 18:07:10 UTC
Sorry for inconvenience because of my patch.

I reproduced the bug with the reproducer using stage1 gcc although strangely the standard bootstrap works ok for me on i686 debian.

I think I know the reason for this bug.  I'll fix it today.
Comment 8 Sergei Trofimovich 2023-10-27 18:11:23 UTC
bootstrap with default options did not fail for me either. I had to use --enable-checking=release to trigger the failure. I wonder if it exposes the failure for you as well.
Comment 9 Vladimir Makarov 2023-10-27 18:54:40 UTC
(In reply to Sergei Trofimovich from comment #8)
> bootstrap with default options did not fail for me either. I had to use
> --enable-checking=release to trigger the failure. I wonder if it exposes the
> failure for you as well.

Yes, with --enable-checking=release I managed to reproduce a failure on clean bootstrap.

BTW, thank you for the reproducer.  It was easier to start from it.
Comment 10 GCC Commits 2023-10-27 19:12:38 UTC
The trunk branch has been updated by Vladimir Makarov <vmakarov@gcc.gnu.org>:

https://gcc.gnu.org/g:4d3d2cdb574488223d023b590c3a34ddd93f4dae

commit r14-4986-g4d3d2cdb574488223d023b590c3a34ddd93f4dae
Author: Vladimir N. Makarov <vmakarov@redhat.com>
Date:   Fri Oct 27 14:50:40 2023 -0400

    [RA]: Fixing i686 bootstrap failure because of pushing the equivalence patch
    
    GCC with my recent patch improving cost calculation for pseudos with
    equivalence may generate different code with and without debug info
    and as the result i686 bootstrap fails on i686.  The patch fixes this
    bug.
    
    gcc/ChangeLog:
    
            PR rtl-optimization/112107
            * ira-costs.cc: (calculate_equiv_gains): Use NONDEBUG_INSN_P
            instead of INSN_P.
Comment 11 Sergei Trofimovich 2023-10-27 21:11:31 UTC
The change fixed bootstrap for me. Thank you!

Let's declare it fixed.