public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/108132] New: Wrong instruction scheduling around function call with longjmp on aarch64 at O2
@ 2022-12-15 17:51 qinzhao at gcc dot gnu.org
  2022-12-15 17:55 ` [Bug rtl-optimization/108132] " qinzhao at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-12-15 17:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108132
           Summary: Wrong instruction scheduling around function call with
                    longjmp on aarch64 at O2
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qinzhao at gcc dot gnu.org
  Target Milestone: ---

The error only happens on aarch64 (fine on X86). 

The following testing case:
[opc@qinzhao-aarch64-ol8]$ cat t.c
#include <stdio.h> 
#include <setjmp.h> 
#include <stdbool.h> 

jmp_buf ex_buf__; 

int f(int x) 
{ 
  int arr[] = {1,2,6,8,9,10}; 
  int lo=0; 
  int hi=5; 

  while(lo<=hi) { 
        int mid=(lo+hi)/2; 

        if(arr[mid]==x) { 
          longjmp(ex_buf__, 1); 
        } else if(arr[mid]<x) { 
          lo=mid+1; 
        } else if(arr[mid]>x) { 
          hi=mid-1; 
        } 
  } 

  return -1; 
} 

int 
main(int argc, char** argv) 
{ 
  int a=2; 
  bool b=false; 

  do {
    if( !setjmp(ex_buf__) ){
        a=f(a); 
        b=true; 
    } else { 
      printf("a : %d\n",a); 
      printf("Got Exception!\n"); 
    } 
  } while(0);

  if(b) { 
        printf("b is true!\n"); 
  } 
  return 0; 
}

when compiled with the latest upstream gcc13 on aarch64 with -O2, the variable
"b" was set to true, which is wrong. 
when disable insn scheduling by adding -fno-schedule-insns, the issue gone:
[opc@qinzhao-aarch64-ol8]$ /home/opc/Install/latest/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/home/opc/Install/latest/bin/gcc
COLLECT_LTO_WRAPPER=/home/opc/Install/latest/libexec/gcc/aarch64-unknown-linux-gnu/13.0.0/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with: ../latest_gcc/configure --prefix=/home/opc/Install/latest
--enable-languages=c,c++ --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.0.0 20221215 (experimental) (GCC) 
[opc@qinzhao-aarch64-ol8]$ /home/opc/Install/latest/bin/gcc -O2 t.c
[opc@qinzhao-aarch64-ol8]$ ./a.out
a : 2
Got Exception!
b is true!
[opc@qinzhao-aarch64-ol8]$ /home/opc/Install/latest/bin/gcc -O2
-fno-schedule-insns t.c
[opc@qinzhao-aarch64-ol8]$ ./a.out
a : 2
Got Exception!
[opc@qinzhao-aarch64-ol8]$

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

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

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-15 17:51 [Bug rtl-optimization/108132] New: Wrong instruction scheduling around function call with longjmp on aarch64 at O2 qinzhao at gcc dot gnu.org
2022-12-15 17:55 ` [Bug rtl-optimization/108132] " qinzhao at gcc dot gnu.org
2022-12-15 17:56 ` qinzhao at gcc dot gnu.org
2022-12-15 18:02 ` pinskia at gcc dot gnu.org
2022-12-15 18:06 ` pinskia at gcc dot gnu.org
2022-12-15 19:30 ` qinzhao at gcc dot gnu.org
2022-12-15 19:33 ` pinskia at gcc dot gnu.org
2022-12-15 19:40 ` qing.zhao at oracle dot com
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).