[Bug rtl-optimization/58831] [4.8/4.9 Regression] wrong code at -O2 and -O3 on x86_64-linux-gnu in 64-bit mode

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Oct 23 11:19:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58831

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |rtl-optimization

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
It's instruction scheduling which in fn1 changes

.L8:
        movq    $d, (%rsi)
        movq    $d, b(%rip)
        cmpq    $0, r(%rip)
        je      .L15  // assert-fail

to


.L8:
        cmpq    $0, r(%rip)
        movq    $d, (%rsi)
        movq    $d, b(%rip)
        je      .L15

but %rsi points to r.  Before sched2 we have

(note 22 21 23 4 [bb 4] NOTE_INSN_BASIC_BLOCK)
(insn 23 22 24 4 (set (mem/f:DI (reg/v/f:DI 4 si [orig:90 p2 ] [90]) [3
*p2_9(D)+0 S8 A64])
        (symbol_ref:DI ("d")  <var_decl 0x7f8900812720 d>)) t.c:12 85
{*movdi_internal}
     (expr_list:REG_DEAD (reg/v/f:DI 4 si [orig:90 p2 ] [90])
        (nil)))
(insn 24 23 25 4 (set (mem/f/c:DI (symbol_ref:DI ("b")  <var_decl
0x7f89008125f0 b>) [3 b+0 S8 A64])
        (symbol_ref:DI ("d")  <var_decl 0x7f8900812720 d>)) t.c:12 85
{*movdi_internal}
     (nil))
(insn 25 24 26 4 (set (reg:CCZ 17 flags)
        (compare:CCZ (mem/f/c:DI (symbol_ref:DI ("r")  <var_decl 0x7f8900812a18
r>) [3 r+0 S8 A64])
            (const_int 0 [0]))) t.c:14 4 {*cmpdi_ccno_1}
     (nil))
(jump_insn 26 25 35 4 (set (pc)

seems to be dependent on code-changes in random places :/

Somewhat shorter testcase:

#include<assert.h>

int a, *b, c, d, f, **i, p, q, *r;
short o, j;

static int __attribute__((noinline, noclone))
fn1 (int *p1, int **p2)
{
  int **e = &b;
  for (; p; p++)
    *p1 = 1;
  *e = *p2 = &d;

  assert (r);

  return c;
}

static int ** __attribute__((noinline, noclone))
fn2 ()
{
  for (f = 0; f != 42; f++)
    {
      int *g[3] = {0, 0, 0};
      for (o = 0; o; o--)
        for (; a > 1;)
          {
            int **h[1] = { &g[2] };
          }
    }
  return &r;
}

int
main ()
{
  i = fn2 ();
  fn1 (b, i);
  return 0;
}



More information about the Gcc-bugs mailing list