public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/41239]  New: Scheduler reorders division by zero before a call that might not return
@ 2009-09-03  8:29 jakub at gcc dot gnu dot org
  2009-09-03  9:24 ` [Bug rtl-optimization/41239] " jakub at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-09-03  8:29 UTC (permalink / raw)
  To: gcc-bugs

This testcase distilled from postgresql fails at runtime on s390x-linux with
-O2 -march=z9-109 -mtune=z10:

/* { dg-do run } */
/* { dg-options "-O2" } */
/* { dg-options "-O2 -march=z9-109 -mtune=z10" { target s390x-linux } } */

struct S
{
  short nargs;
  unsigned long arg[2];
};

extern void abort (void);
extern void exit (int);
extern char errstart (int, const char *, int, const char *, const char *);
extern void errfinish (int, ...);
extern int errcode (int);
extern int errmsg (const char *fmt, ...) __attribute__ ((format (printf, 1,
2)));

unsigned long
test (struct S *x)
{
  signed int arg1 = x->arg[0];
  long int arg2 = x->arg[1];

  if (arg2 == 0)
    (errstart (20, "int8.c", 924, __func__, ((void *) 0))
     ? (errfinish (errcode (0x2040082), errmsg ("division by zero")))
     : (void) 0);

  return (long int) arg1 / arg2;
}

int
main (void)
{
  struct S s = { 2, { 5, 0 } };
  test (&s);
  abort ();
}

__attribute__((noinline)) char
errstart (int x, const char *y, int z, const char *w, const char *v)
{
  asm volatile ("" : "+r" (x) : "r" (y), "r" (z), "r" (w), "r" (v) : "memory");
  return x;
}

__attribute__((noinline)) int
errcode (int x)
{
  asm volatile ("" : "+r" (x) : : "memory");
  return x;
}

__attribute__((noinline)) int
errmsg (const char *x, ...)
{
  asm volatile ("" : "+r" (x) : : "memory");
  return *x;
}

__attribute__((noinline)) void
errfinish (int x, ...)
{
  asm volatile ("" : "+r" (x) : : "memory");
  if (x)
    /* Could be a longjmp or throw too.  */
    exit (0);
}

The problem is that 2nd scheduler pass reorders the division before some of the
calls.  If the calls were guaranteed to return, that would be fine, the program
would crash sooner or later, but as shown in the testcase the call can not
return (exit, longjmp, throw) and in that case whether the division is
scheduled before or after the call matters.


-- 
           Summary: Scheduler reorders division by zero before a call that
                    might not return
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org
GCC target triplet: s390x-linux


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


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

* [Bug rtl-optimization/41239] Scheduler reorders division by zero before a call that might not return
  2009-09-03  8:29 [Bug rtl-optimization/41239] New: Scheduler reorders division by zero before a call that might not return jakub at gcc dot gnu dot org
@ 2009-09-03  9:24 ` jakub at gcc dot gnu dot org
  2009-09-03 10:32 ` rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-09-03  9:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from jakub at gcc dot gnu dot org  2009-09-03 09:24 -------
sched-deps.c uses may_trap_p only to find out what insns can't be speculated,
possibly trapping MEMs are handled by deps_may_trap_p.
I wonder what exactly we want to forbid to cure this testcase.
Just DIV/MOD/UDIV/UMOD that may_trap_p being moved across a function call that
might not return (all CALL_Ps or all except a few known builtins?  Say memcpy
or strcpy could be said to always return), or all may_trap_p insns across all
calls that might not return, or even across all such calls and all trapping
insns?
Ideas?


-- 


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


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

* [Bug rtl-optimization/41239] Scheduler reorders division by zero before a call that might not return
  2009-09-03  8:29 [Bug rtl-optimization/41239] New: Scheduler reorders division by zero before a call that might not return jakub at gcc dot gnu dot org
  2009-09-03  9:24 ` [Bug rtl-optimization/41239] " jakub at gcc dot gnu dot org
@ 2009-09-03 10:32 ` rguenth at gcc dot gnu dot org
  2009-09-03 20:12 ` jakub at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-09-03 10:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-09-03 10:31 -------
We can never move maybe trapping instructions across a function call that might
not return (and as we don't have an attribute for returns_always we have to
assume that a function may not return always apart from maybe some known
builtins).


-- 


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


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

* [Bug rtl-optimization/41239] Scheduler reorders division by zero before a call that might not return
  2009-09-03  8:29 [Bug rtl-optimization/41239] New: Scheduler reorders division by zero before a call that might not return jakub at gcc dot gnu dot org
  2009-09-03  9:24 ` [Bug rtl-optimization/41239] " jakub at gcc dot gnu dot org
  2009-09-03 10:32 ` rguenth at gcc dot gnu dot org
@ 2009-09-03 20:12 ` jakub at gcc dot gnu dot org
  2009-09-03 21:40 ` vmakarov at redhat dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-09-03 20:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jakub at gcc dot gnu dot org  2009-09-03 20:11 -------
Looking at sched-deps.c, it might be easiest for may_trap_p insns to be queued
onto deps->sched_before_next_call chain, but I'm not sure whether we want to do
that for all, or if it should ignore trapping memory as that's handled
elsewhere in sched-deps.c.  Vlad, any ideas?


-- 


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


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

* [Bug rtl-optimization/41239] Scheduler reorders division by zero before a call that might not return
  2009-09-03  8:29 [Bug rtl-optimization/41239] New: Scheduler reorders division by zero before a call that might not return jakub at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2009-09-03 20:12 ` jakub at gcc dot gnu dot org
@ 2009-09-03 21:40 ` vmakarov at redhat dot com
  2009-09-08  9:26 ` jakub at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: vmakarov at redhat dot com @ 2009-09-03 21:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from vmakarov at redhat dot com  2009-09-03 21:40 -------
  Oh well, another haifa-scheduler integration issue after so many years to
integrate it into GCC.  It looks like the original haifa-scheduler treated
calls as always returning.

  I think you should use last_function_call and make dependence for trapping
insn to calls on this list which might not return.  You could ignore issue with
already processed insn with trapping memory because you can add as many
dependencies between the two insns as you want.  Sched-deps.c code is pretty
smart with this point of view.


-- 


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


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

* [Bug rtl-optimization/41239] Scheduler reorders division by zero before a call that might not return
  2009-09-03  8:29 [Bug rtl-optimization/41239] New: Scheduler reorders division by zero before a call that might not return jakub at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2009-09-03 21:40 ` vmakarov at redhat dot com
@ 2009-09-08  9:26 ` jakub at gcc dot gnu dot org
  2009-09-08  9:36 ` jakub at gcc dot gnu dot org
  2009-10-05 21:43 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-09-08  9:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jakub at gcc dot gnu dot org  2009-09-08 09:26 -------
Subject: Bug 41239

Author: jakub
Date: Tue Sep  8 09:25:47 2009
New Revision: 151500

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151500
Log:
        PR rtl-optimization/41239
        * sched-int.h (struct deps): Add last_function_call_may_noreturn field.
        * sched-rgn.c (deps_join): Join also last_function_call_may_noreturn
        lists.
        * sched-deps.c (sched_analyze_insn): Prevent moving trapping insns
        across calls, as the calls might not always return normally.
        (call_may_noreturn_p): New function.
        (deps_analyze_insn): Update last_function_call_may_noreturn list.
        (init_deps): Initialize it.
        (remove_from_deps): Also remove calls from
        last_function_call_may_noreturn list.

        * gcc.c-torture/execute/pr41239.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr41239.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/sched-deps.c
    trunk/gcc/sched-int.h
    trunk/gcc/sched-rgn.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug rtl-optimization/41239] Scheduler reorders division by zero before a call that might not return
  2009-09-03  8:29 [Bug rtl-optimization/41239] New: Scheduler reorders division by zero before a call that might not return jakub at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2009-09-08  9:26 ` jakub at gcc dot gnu dot org
@ 2009-09-08  9:36 ` jakub at gcc dot gnu dot org
  2009-10-05 21:43 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-09-08  9:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2009-09-08 09:35 -------
Fixed on the trunk.


-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug rtl-optimization/41239] Scheduler reorders division by zero before a call that might not return
  2009-09-03  8:29 [Bug rtl-optimization/41239] New: Scheduler reorders division by zero before a call that might not return jakub at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2009-09-08  9:36 ` jakub at gcc dot gnu dot org
@ 2009-10-05 21:43 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-10-05 21:43 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.5.0


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


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

* [Bug rtl-optimization/41239] Scheduler reorders division by zero before a call that might not return
       [not found] <bug-41239-4@http.gcc.gnu.org/bugzilla/>
@ 2023-04-20 21:46 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-20 21:46 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tiamat at komi dot mts.ru

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 29968 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2023-04-20 21:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-03  8:29 [Bug rtl-optimization/41239] New: Scheduler reorders division by zero before a call that might not return jakub at gcc dot gnu dot org
2009-09-03  9:24 ` [Bug rtl-optimization/41239] " jakub at gcc dot gnu dot org
2009-09-03 10:32 ` rguenth at gcc dot gnu dot org
2009-09-03 20:12 ` jakub at gcc dot gnu dot org
2009-09-03 21:40 ` vmakarov at redhat dot com
2009-09-08  9:26 ` jakub at gcc dot gnu dot org
2009-09-08  9:36 ` jakub at gcc dot gnu dot org
2009-10-05 21:43 ` pinskia at gcc dot gnu dot org
     [not found] <bug-41239-4@http.gcc.gnu.org/bugzilla/>
2023-04-20 21:46 ` 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).