From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0F158383A0C2; Thu, 15 Dec 2022 17:51:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F158383A0C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671126689; bh=y2rzuWrudL+ymy4ZuGDSscKhURFaF8Z1/zNra4zF9E4=; h=From:To:Subject:Date:From; b=E23P/JT1dCm/MSElpEFGkTeQX03DBBRd4BECJ3/byfj++putExhsIpSvO62ZTZTeO Nz8cbQJrkuQe5E4aA8qe5CqPUyolNRnLWzuDfBfQfujrFXQIHc12APoLz592LUYKvS ggxrTTRepcdR28SG1PQaioCOM2avRp4QnqYGR0qI= From: "qinzhao at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/108132] New: Wrong instruction scheduling around function call with longjmp on aarch64 at O2 Date: Thu, 15 Dec 2022 17:51:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: qinzhao at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108132 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).=20 The following testing case: [opc@qinzhao-aarch64-ol8]$ cat t.c #include =20 #include =20 #include =20 jmp_buf ex_buf__;=20 int f(int x)=20 {=20 int arr[] =3D {1,2,6,8,9,10};=20 int lo=3D0;=20 int hi=3D5;=20 while(lo<=3Dhi) {=20 int mid=3D(lo+hi)/2;=20 if(arr[mid]=3D=3Dx) {=20 longjmp(ex_buf__, 1);=20 } else if(arr[mid]x) {=20 hi=3Dmid-1;=20 }=20 }=20 return -1;=20 }=20 int=20 main(int argc, char** argv)=20 {=20 int a=3D2;=20 bool b=3Dfalse;=20 do { if( !setjmp(ex_buf__) ){ a=3Df(a);=20 b=3Dtrue;=20 } else {=20 printf("a : %d\n",a);=20 printf("Got Exception!\n");=20 }=20 } while(0); if(b) {=20 printf("b is true!\n");=20 }=20 return 0;=20 } when compiled with the latest upstream gcc13 on aarch64 with -O2, the varia= ble "b" was set to true, which is wrong.=20 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=3D/home/opc/Install/latest/bin/gcc COLLECT_LTO_WRAPPER=3D/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=3D/home/opc/Install/latest --enable-languages=3Dc,c++ --disable-bootstrap Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.0.0 20221215 (experimental) (GCC)=20 [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]$=