This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/26316] New: loop-invariant miscompiles openmp.c


__attribute__ ((noinline))
void
bar (int i)
{
  asm volatile ("" : : "r" (i));
}

struct S
{
  int v;
  struct S *w;
};

__attribute__ ((noinline))
void
foo (struct S *s, int l)
{
  for (; s; s = s->w)
    {
      if (s->v && (l < 6 || l > 17))
        bar (1);
      switch (l)
        {
        case 6:
        case 7:
        case 8:
          bar (2);
          break;
        case 9:
        case 10:
          bar (3);
          break;
        case 13:
        case 14:
          bar (4);
          break;
        case 17:
          bar (5);
          break;
        default:
          break;
        }
    }
}

int
main (void)
{
  struct S s = { 0, 0 };
  foo (&s, 0);
  return 0;
}

is miscompiled on x86_64 at -O1 and above.  Before *r.loop2_invariant dump
(insn 30 29 31 6 o.i:22 (parallel [
            (set (reg:SI 61)
                (plus:SI (reg/v:SI 59 [ l ])
                    (const_int -6 [0xfffffffffffffffa])))
            (clobber (reg:CC 17 flags))
        ]) 208 {*addsi_1} (nil)
    (nil))

(insn 31 30 32 6 o.i:22 (set (reg:CC 17 flags)
        (compare:CC (reg:SI 61)
            (const_int 11 [0xb]))) 5 {*cmpsi_1_insn} (nil)
    (nil))

(jump_insn 32 31 85 6 o.i:22 (set (pc)
        (if_then_else (gtu (reg:CC 17 flags)
                (const_int 0 [0x0]))
            (label_ref 70)
            (pc))) 511 {*jcc_1} (nil)
    (expr_list:REG_BR_PROB (const_int 5000 [0x1388])
        (nil)))

(insn 33 85 35 7 o.i:22 (set (reg:DI 62)
        (zero_extend:DI (reg:SI 61))) 111 {zero_extendsidi2_rex64} (nil)
    (nil))

(insn 35 33 36 7 o.i:22 (set (reg:DI 64)
        (mem/u/c:DI (plus:DI (mult:DI (reg:DI 62)
                    (const_int 8 [0x8]))
                (label_ref:DI 38)) [0 S8 A8])) 81 {*movdi_1_rex64} (nil)
    (insn_list:REG_LABEL 38 (nil)))

(jump_insn 36 35 41 7 o.i:22 (parallel [
            (set (pc)
                (reg:DI 64))
            (use (label_ref 38))
        ]) 530 {*tablejump_1_rtx64} (nil)
    (nil))

so insn 35 isn't executed if (unsigned int) (l - 6) > 11.
But in *r.loop2_invariant dump this becomes:
(insn 19 13 33 3 o.i:20 (parallel [
            (set (reg:SI 65)
                (plus:SI (reg/v:SI 59 [ l ])
                    (const_int -6 [0xfffffffffffffffa])))
            (clobber (reg:CC 17 flags))
        ]) 208 {*addsi_1} (nil)
    (nil))

(insn 33 19 35 3 o.i:22 (set (reg:DI 66)
        (zero_extend:DI (reg:SI 65))) 111 {zero_extendsidi2_rex64} (nil)
    (nil))

(insn 35 33 92 3 o.i:22 (set (reg:DI 67)
        (mem/u/c:DI (plus:DI (mult:DI (reg:DI 66)
                    (const_int 8 [0x8]))
                (label_ref:DI 38)) [0 S8 A8])) 81 {*movdi_1_rex64} (nil)
    (insn_list:REG_LABEL 38 (nil)))


-- 
           Summary: loop-invariant miscompiles openmp.c
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org
GCC target triplet: x86_64-linux


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]