public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/57281] New: x86_64-linux loop fails to terminate at -O3 -m32
@ 2013-05-15  3:41 dhazeghi at yahoo dot com
  2013-05-15  9:18 ` [Bug target/57281] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: dhazeghi at yahoo dot com @ 2013-05-15  3:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57281
           Summary: x86_64-linux loop fails to terminate at -O3 -m32
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dhazeghi at yahoo dot com

The testcase below is miscompiled with current gcc trunk at -O3 optimization
level in 32-bit mode on x86_64-linux-gnu, and fails to terminate.  With other
optimizations levels in 64-bit mode, it executes successfully.  This is a
regression from 4.8, where the code works at all optimizations levels.

$ gcc-trunk -v
...
Target: x86_64-unknown-linux-gnu
gcc version 4.9.0 20130514 (experimental) [trunk revision 198875] (GCC)
$ gcc-trunk -O2 -m32 test.c
$ ./a.out
$ gcc-4.8 -O3 -m32 test.c
$ ./a.out
$ gcc-trunk -O3 -m32 test
$ ./a.out
<hangs>


--------------

int a = 1, b = 0, d;
long long c;
int *e = &d;
volatile long long f;
long long *g = &c;

int foo(int h)
{
  int j = *g = b;
  return h == 0 ? j : 0;
}

int
main ()
{
    int h = a;
    for (; b != -20; b--)
    {
        int i = f;
        *e = 0;
        *e = foo(h);
    }
    return 0;
}


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

* [Bug target/57281] x86_64-linux loop fails to terminate at -O3 -m32
  2013-05-15  3:41 [Bug target/57281] New: x86_64-linux loop fails to terminate at -O3 -m32 dhazeghi at yahoo dot com
@ 2013-05-15  9:18 ` rguenth at gcc dot gnu.org
  2013-05-15  9:37 ` [Bug target/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32, bogus extendsidi2_1 splitter rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-15  9:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2013-05-15
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  It's loop unswitching triggering this.


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

* [Bug target/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32, bogus extendsidi2_1 splitter
  2013-05-15  3:41 [Bug target/57281] New: x86_64-linux loop fails to terminate at -O3 -m32 dhazeghi at yahoo dot com
  2013-05-15  9:18 ` [Bug target/57281] " rguenth at gcc dot gnu.org
@ 2013-05-15  9:37 ` rguenth at gcc dot gnu.org
  2013-05-15  9:41 ` [Bug rtl-optimization/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32 rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-15  9:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Target|                            |i?86-*-*
             Status|ASSIGNED                    |NEW
   Target Milestone|---                         |4.9.0
            Summary|x86_64-linux loop fails to  |[4.9 Regression]
                   |terminate at -O3 -m32       |x86_64-linux loop fails to
                   |                            |terminate at -O3 -m32,
                   |                            |bogus extendsidi2_1
                   |                            |splitter

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
But the miscompile happens during RTL opts:

  <bb 5>:
  f.0_13 ={v} f;
  *pretmp_4 = 0;
  b.5_1 = b;
  _23 = (long long int) b.5_1;
  *pretmp_18 = _23;
  *pretmp_4 = 0;
  b.2_27 = b;
  b.3_28 = b.2_27 + -1;
  b = b.3_28;
  if (b.3_28 != -20)
    goto <bb 6>;
  else
    goto <bb 10>;

  <bb 6>:
  goto <bb 5>;

is ok, while

.L4:
        movl    f, %eax
        movl    f+4, %edx
        movl    $0, (%ecx)
        movl    b, %eax
        movl    %eax, (%ebx)
        sarl    $31, %eax
        movl    %eax, 4(%ebx)
        subl    $1, %eax
        cmpl    $-20, %eax
        movl    %eax, b
        jne     .L4

messes up the IV value - the store of the upper half of the long long
extended b into *pretmp_18 invalidates b (%eax) but that value is then
still used for the IV.

Ok pre-IRA/LRA:

(insn 19 18 20 4 (parallel [
            (set (mem:DI (reg/f:SI 68 [ D.1736 ]) [4 *_18+0 S8 A64])
                (sign_extend:DI (reg:SI 75 [ b ])))
            (clobber (reg:CC 17 flags))
            (clobber (scratch:SI))
        ]) t.c:9 137 {extendsidi2_1}
     (expr_list:REG_DEAD (reg:SI 75 [ b ])
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))
...
(insn 21 20 22 4 (set (reg:SI 76 [ b ])
        (mem/c:SI (symbol_ref:SI ("b") [flags 0x2]  <var_decl 0x7fccdf73b098
b>) [2 b+0 S4 A32])) t.c:17 85 {*movsi_internal}
     (nil))
(insn 22 21 23 4 (parallel [
            (set (reg:SI 72 [ b.3 ])
                (plus:SI (reg:SI 76 [ b ])
                    (const_int -1 [0xffffffffffffffff])))
            (clobber (reg:CC 17 flags))

and after:

(insn 19 78 20 4 (parallel [
            (set (mem:DI (reg/f:SI 3 bx [orig:68 D.1736 ] [68]) [4 *_18+0 S8
A64])
                (sign_extend:DI (reg:SI 0 ax [orig:75 b ] [75])))
            (clobber (reg:CC 17 flags))
            (clobber (reg:SI 1 dx [80]))
        ]) t.c:9 137 {extendsidi2_1}
     (expr_list:REG_UNUSED (reg:SI 1 dx [80])
        (expr_list:REG_DEAD (reg:SI 0 ax [orig:75 b ] [75])
            (nil))))
(insn 20 19 21 4 (set (mem:SI (reg/f:SI 2 cx [orig:61 D.1734 ] [61]) [2 *_4+0
S4 A32])
        (const_int 0 [0])) t.c:21 85 {*movsi_internal}
     (nil))
(note 21 20 80 4 NOTE_INSN_DELETED)
(insn 80 21 22 4 (set (reg:SI 0 ax [82])
        (mem/c:SI (symbol_ref:SI ("b") [flags 0x2]  <var_decl 0x7fccdf73b098
b>) [2 b+0 S4 A32])) t.c:17 85 {*movsi_internal}
     (nil))

and postreload optimizes it to

(insn 78 18 19 4 (set (reg:SI 0 ax [orig:75 b ] [75])
        (mem/c:SI (symbol_ref:SI ("b") [flags 0x2]  <var_decl 0x7fccdf73b098
b>) [2 b+0 S4 A32])) t.c:9 85 {*movsi_internal}
     (expr_list:REG_EQUIV (mem/c:SI (symbol_ref:SI ("b") [flags 0x2]  <var_decl
0x7fccdf73b098 b>) [2 b+0 S4 A32])
        (nil)))
(insn 19 78 21 4 (parallel [
            (set (mem:DI (reg/f:SI 3 bx [orig:68 D.1736 ] [68]) [4 *_18+0 S8
A64])
                (sign_extend:DI (reg:SI 0 ax [orig:75 b ] [75])))
            (clobber (reg:CC 17 flags))
            (clobber (reg:SI 1 dx [80]))
        ]) t.c:9 137 {extendsidi2_1}
     (expr_list:REG_UNUSED (reg:SI 1 dx [80])
        (expr_list:REG_DEAD (reg:SI 0 ax [orig:75 b ] [75])
            (nil))))
(note 21 19 80 4 NOTE_INSN_DELETED)
(insn 80 21 22 4 (set (reg:SI 0 ax [82])
        (reg:SI 0 ax [orig:75 b ] [75])) t.c:17 85 {*movsi_internal}
     (nil))
(insn 22 80 23 4 (parallel [
            (set (reg:SI 0 ax [orig:72 b.3 ] [72])
                (plus:SI (reg:SI 0 ax [82])
                    (const_int -1 [0xffffffffffffffff])))
            (clobber (reg:CC 17 flags))

but broken by split, which clobbers ax:

(insn 78 18 89 4 (set (reg:SI 0 ax [orig:75 b ] [75])
        (mem/c:SI (symbol_ref:SI ("b") [flags 0x2]  <var_decl 0x7fccdf73b098
b>) [2 b+0 S4 A32])) t.c:9 85 {*movsi_internal}
     (expr_list:REG_EQUIV (mem/c:SI (symbol_ref:SI ("b") [flags 0x2]  <var_decl
0x7fccdf73b098 b>) [2 b+0 S4 A32])
        (nil)))
(insn 89 78 90 4 (set (mem:SI (reg/f:SI 3 bx [orig:68 D.1736 ] [68]) [4 *_18+0
S4 A64])
        (reg:SI 0 ax [orig:75 b ] [75])) t.c:9 85 {*movsi_internal}
     (nil))
(insn 90 89 91 4 (parallel [
            (set (reg:SI 0 ax [orig:75 b ] [75])
                (ashiftrt:SI (reg:SI 0 ax [orig:75 b ] [75])
                    (const_int 31 [0x1f])))
            (clobber (reg:CC 17 flags))
        ]) t.c:9 529 {ashrsi3_cvt}
     (nil))
(insn 91 90 21 4 (set (mem:SI (plus:SI (reg/f:SI 3 bx [orig:68 D.1736 ] [68])
                (const_int 4 [0x4])) [4 *_18+4 S4 A32])
        (reg:SI 0 ax [orig:75 b ] [75])) t.c:9 85 {*movsi_internal}
     (nil))
(note 21 91 22 4 NOTE_INSN_DELETED)
(insn 22 21 23 4 (parallel [
            (set (reg:SI 0 ax [orig:72 b.3 ] [72])
                (plus:SI (reg:SI 0 ax [82])
                    (const_int -1 [0xffffffffffffffff])))
            (clobber (reg:CC 17 flags))
        ]) t.c:17 260 {*addsi_1}
     (expr_list:REG_DEAD (reg:SI 0 ax [82])
        (expr_list:REG_EQUAL (plus:SI (mem/c:SI (symbol_ref:SI ("b") [flags
0x2]  <var_decl 0x7fccdf73b098 b>) [2 b+0 S4 A32])
                (const_int -1 [0xffffffffffffffff]))
            (nil))))
(insn 23 22 24 4 (set (mem/c:SI (symbol_ref:SI ("b") [flags 0x2]  <var_decl
0x7fccdf73b098 b>) [2 b+0 S4 A32])
        (reg:SI 0 ax [orig:72 b.3 ] [72])) t.c:17 85 {*movsi_internal}
     (nil))


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

* [Bug rtl-optimization/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32
  2013-05-15  3:41 [Bug target/57281] New: x86_64-linux loop fails to terminate at -O3 -m32 dhazeghi at yahoo dot com
  2013-05-15  9:18 ` [Bug target/57281] " rguenth at gcc dot gnu.org
  2013-05-15  9:37 ` [Bug target/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32, bogus extendsidi2_1 splitter rguenth at gcc dot gnu.org
@ 2013-05-15  9:41 ` rguenth at gcc dot gnu.org
  2013-05-15  9:48 ` steven at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-15  9:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|target                      |rtl-optimization
            Summary|[4.9 Regression]            |[4.9 Regression]
                   |x86_64-linux loop fails to  |x86_64-linux loop fails to
                   |terminate at -O3 -m32,      |terminate at -O3 -m32
                   |bogus extendsidi2_1         |
                   |splitter                    |

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
postreload leaves a REG_DEAD note on the

(insn 19 78 21 4 (parallel [
            (set (mem:DI (reg/f:SI 3 bx [orig:68 D.1736 ] [68]) [4 *_18+0 S8
A64])
                (sign_extend:DI (reg:SI 0 ax [orig:75 b ] [75])))
            (clobber (reg:CC 17 flags))
            (clobber (reg:SI 1 dx [80]))
        ]) t.c:9 137 {extendsidi2_1}
     (expr_list:REG_UNUSED (reg:SI 1 dx [80])
        (expr_list:REG_DEAD (reg:SI 0 ax [orig:75 b ] [75])
            (nil))))

which is bogus.


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

* [Bug rtl-optimization/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32
  2013-05-15  3:41 [Bug target/57281] New: x86_64-linux loop fails to terminate at -O3 -m32 dhazeghi at yahoo dot com
                   ` (2 preceding siblings ...)
  2013-05-15  9:41 ` [Bug rtl-optimization/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32 rguenth at gcc dot gnu.org
@ 2013-05-15  9:48 ` steven at gcc dot gnu.org
  2013-05-15 10:55 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: steven at gcc dot gnu.org @ 2013-05-15  9:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Steven Bosscher <steven at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #2)
> messes up the IV value - the store of the upper half of the long long
> extended b into *pretmp_18 invalidates b (%eax) but that value is then
> still used for the IV.

Re-emergence of bug 56833?


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

* [Bug rtl-optimization/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32
  2013-05-15  3:41 [Bug target/57281] New: x86_64-linux loop fails to terminate at -O3 -m32 dhazeghi at yahoo dot com
                   ` (3 preceding siblings ...)
  2013-05-15  9:48 ` steven at gcc dot gnu.org
@ 2013-05-15 10:55 ` rguenth at gcc dot gnu.org
  2013-05-15 11:05 ` ebotcazou at gcc dot gnu.org
  2013-05-20  7:13 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-05-15 10:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Eric Botcazou from comment #5)
> > postreload leaves a REG_DEAD note on the
> > 
> > (insn 19 78 21 4 (parallel [
> >             (set (mem:DI (reg/f:SI 3 bx [orig:68 D.1736 ] [68]) [4 *_18+0 S8
> > A64])
> >                 (sign_extend:DI (reg:SI 0 ax [orig:75 b ] [75])))
> >             (clobber (reg:CC 17 flags))
> >             (clobber (reg:SI 1 dx [80]))
> >         ]) t.c:9 137 {extendsidi2_1}
> >      (expr_list:REG_UNUSED (reg:SI 1 dx [80])
> >         (expr_list:REG_DEAD (reg:SI 0 ax [orig:75 b ] [75])
> >             (nil))))
> > 
> > which is bogus.
> 
> Leaving REG_DEAD/REG_UNUSED notes at the end of a pass is OK, it's up to the
> next pass using them to make sure they are valid by invoking DF.

Which means that split has to do that?  Or that the use of dead_or_set_p ()
in

;; Extend to memory case when source register does die.
(define_split
  [(set (match_operand:DI 0 "memory_operand")
        (sign_extend:DI (match_operand:SI 1 "register_operand")))
   (clobber (reg:CC FLAGS_REG))
   (clobber (match_operand:SI 2 "register_operand"))]
  "(reload_completed
    && dead_or_set_p (insn, operands[1])
    && !reg_mentioned_p (operands[1], operands[0]))"
  [(set (match_dup 3) (match_dup 1))
   (parallel [(set (match_dup 1) (ashiftrt:SI (match_dup 1) (const_int 31)))
              (clobber (reg:CC FLAGS_REG))])
   (set (match_dup 4) (match_dup 1))]
  "split_double_mode (DImode, &operands[0], 1, &operands[3], &operands[4]);")

is bogus?


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

* [Bug rtl-optimization/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32
  2013-05-15  3:41 [Bug target/57281] New: x86_64-linux loop fails to terminate at -O3 -m32 dhazeghi at yahoo dot com
                   ` (4 preceding siblings ...)
  2013-05-15 10:55 ` rguenth at gcc dot gnu.org
@ 2013-05-15 11:05 ` ebotcazou at gcc dot gnu.org
  2013-05-20  7:13 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2013-05-15 11:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> Which means that split has to do that?

Presumably, yes.  peephole2 already does it.


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

* [Bug rtl-optimization/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32
  2013-05-15  3:41 [Bug target/57281] New: x86_64-linux loop fails to terminate at -O3 -m32 dhazeghi at yahoo dot com
                   ` (5 preceding siblings ...)
  2013-05-15 11:05 ` ebotcazou at gcc dot gnu.org
@ 2013-05-20  7:13 ` jakub at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-20  7:13 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|---                         |FIXED

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Fri May 17 15:22:24 2013
New Revision: 199018

URL: http://gcc.gnu.org/viewcvs?rev=199018&root=gcc&view=rev
Log:
    PR rtl-optimization/57281
    PR rtl-optimization/57300
    * config/i386/i386.md (extendsidi2_1 dead reg splitter): Remove.
    (extendsidi2_1 peephole2s): Add instead 2 new peephole2s, that undo
    what the other splitter did if the registers are dead.

    * gcc.dg/pr57300.c: New test.
    * gcc.c-torture/execute/pr57281.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr57281.c
    trunk/gcc/testsuite/gcc.dg/pr57300.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.md
    trunk/gcc/testsuite/ChangeLog

Author: jakub
Date: Fri May 17 15:32:50 2013
New Revision: 199021

URL: http://gcc.gnu.org/viewcvs?rev=199021&root=gcc&view=rev
Log:
    PR rtl-optimization/57281
    PR rtl-optimization/57300
    * config/i386/i386.md (extendsidi2_1 dead reg splitter): Remove.
    (extendsidi2_1 peephole2s): Add instead 2 new peephole2s, that undo
    what the other splitter did if the registers are dead.

    * gcc.dg/pr57300.c: New test.
    * gcc.c-torture/execute/pr57281.c: New test.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr57281.c
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/pr57300.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/config/i386/i386.md
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog


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

end of thread, other threads:[~2013-05-20  7:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-15  3:41 [Bug target/57281] New: x86_64-linux loop fails to terminate at -O3 -m32 dhazeghi at yahoo dot com
2013-05-15  9:18 ` [Bug target/57281] " rguenth at gcc dot gnu.org
2013-05-15  9:37 ` [Bug target/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32, bogus extendsidi2_1 splitter rguenth at gcc dot gnu.org
2013-05-15  9:41 ` [Bug rtl-optimization/57281] [4.9 Regression] x86_64-linux loop fails to terminate at -O3 -m32 rguenth at gcc dot gnu.org
2013-05-15  9:48 ` steven at gcc dot gnu.org
2013-05-15 10:55 ` rguenth at gcc dot gnu.org
2013-05-15 11:05 ` ebotcazou at gcc dot gnu.org
2013-05-20  7:13 ` jakub 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).