public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/108117] New: Wrong instruction scheduling on value coming from abnormal SSA
@ 2022-12-15  5:36 fxue at os dot amperecomputing.com
  2022-12-15  5:42 ` [Bug rtl-optimization/108117] " pinskia at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: fxue at os dot amperecomputing.com @ 2022-12-15  5:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108117
           Summary: Wrong instruction scheduling on value coming from
                    abnormal SSA
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fxue at os dot amperecomputing.com
  Target Milestone: ---

Compile the following code with "-O2" on AArch64.

#include <stdio.h>
#include <setjmp.h>

jmp_buf ex_buf;

__attribute__((noinline)) int fn_throw(int x)
{
   if (x == 1)
      longjmp(ex_buf, 1);
   return 1;
}

int main(int argc, char** argv)
{
    int va = 0;
    int vb = 0;

    if (!setjmp(ex_buf)) {
        va = fn_throw(1); /* throw via longjmp */
        vb = 1;
    } else
        printf("Got exception, va = %d\n", va);

    if (vb)
        printf("Failed, vb should not = %d!\n", vb);

    return 0;
}

Since "fn_throw" involves abnormal control flow transferring, any statement
after "va = fn_throw(1)" should not be hoisted prior to the call. In this case,
"vb = 1" is moved before it by RTL inst sched, and leads to incorrect result.

Similar to C++ exception handling, setjmp/longjmp would generate SSA names
occurring in abnormal phi, these should be specially treated. Though, it looks
like that RTL passes do not respect this characteristics in any kind of code
motions. Now the issue is only exposed on AArch64, for while inst sched1 pass
is enabled, but it is also a potential one on other backends.

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

end of thread, other threads:[~2023-01-13 18:33 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-15  5:36 [Bug rtl-optimization/108117] New: Wrong instruction scheduling on value coming from abnormal SSA fxue at os dot amperecomputing.com
2022-12-15  5:42 ` [Bug rtl-optimization/108117] " pinskia at gcc dot gnu.org
2022-12-15  5:44 ` pinskia at gcc dot gnu.org
2022-12-15  5:46 ` pinskia at gcc dot gnu.org
2022-12-15  7:15 ` amonakov at gcc dot gnu.org
2022-12-15  8:30 ` amonakov at gcc dot gnu.org
2022-12-15  8:54 ` fxue at os dot amperecomputing.com
2022-12-15  9:01 ` pinskia at gcc dot gnu.org
2022-12-15 11:38 ` fxue at os dot amperecomputing.com
2022-12-15 12:44 ` amonakov at gcc dot gnu.org
2022-12-15 18:04 ` pinskia at gcc dot gnu.org
2022-12-15 18:06 ` pinskia at gcc dot gnu.org
2022-12-15 18:17 ` amonakov at gcc dot gnu.org
2022-12-15 18:19 ` pinskia at gcc dot gnu.org
2022-12-15 18:26 ` amonakov at gcc dot gnu.org
2022-12-15 18:33 ` amonakov at gcc dot gnu.org
2022-12-23  7:37 ` amonakov at gcc dot gnu.org
2023-01-13 18:33 ` cvs-commit 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).