From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A80B1385741A; Tue, 5 Apr 2022 11:50:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A80B1385741A From: "nsz at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/105160] New: [12 regression] ipa modref marks functions with asm volatile as const or pure Date: Tue, 05 Apr 2022 11:50:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nsz 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 cc 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Apr 2022 11:50:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105160 Bug ID: 105160 Summary: [12 regression] ipa modref marks functions with asm volatile as const or pure Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: nsz at gcc dot gnu.org CC: marxin at gcc dot gnu.org Target Milestone: --- the following code is miscompiled with gcc -O1 #define sysreg_read(regname) \ ({ \ unsigned long __sr_val; \ asm volatile( \ "mrs %0, " #regname "\n" \ : "=3Dr" (__sr_val)); \ \ __sr_val; \ }) #define sysreg_write(regname, __sw_val) \ do { \ asm volatile( \ "msr " #regname ", %0\n" \ : \ : "r" (__sw_val)); \ } while (0) #define isb() \ do { \ asm volatile( \ "isb" \ : \ : \ : "memory"); \ } while (0) static unsigned long sctlr_read(void) { return sysreg_read(sctlr_el1); } static void sctlr_write(unsigned long val) { sysreg_write(sctlr_el1, val); } static void sctlr_rmw(void) { unsigned long val; val =3D sctlr_read(); val |=3D 1UL << 7; sctlr_write(val); } void sctlr_read_multiple(void) { sctlr_read(); sctlr_read(); sctlr_read(); sctlr_read(); } void sctlr_write_multiple(void) { sctlr_write(0); sctlr_write(0); sctlr_write(0); sctlr_write(0); sctlr_write(0); } void sctlr_rmw_multiple(void) { sctlr_rmw(); sctlr_rmw(); sctlr_rmw(); sctlr_rmw(); } void function(void) { sctlr_read_multiple(); sctlr_write_multiple(); sctlr_rmw_multiple(); isb(); } aarch64-linux-gnu-gcc -O1 compiles it to (note 'function' and 'sctlr_rmw_multiple'): sctlr_rmw: mrs x0, sctlr_el1 orr x0, x0, 128 msr sctlr_el1, x0 ret sctlr_read_multiple: mrs x0, sctlr_el1 mrs x0, sctlr_el1 mrs x0, sctlr_el1 mrs x0, sctlr_el1 ret sctlr_write_multiple: mov x0, 0 msr sctlr_el1, x0 msr sctlr_el1, x0 msr sctlr_el1, x0 msr sctlr_el1, x0 msr sctlr_el1, x0 ret sctlr_rmw_multiple: ret function: isb ret a similar issue in linux (but lager source file) got bisected to https://gcc.gnu.org/git/gitweb.cgi?p=3Dgcc.git;h=3D1b62cddcf091fb8cadf57524= 6a7d3ff778650a6b commit 1b62cddcf091fb8cadf575246a7d3ff778650a6b Author: Jan Hubicka Date: Fri Nov 12 14:00:47 2021 +0100 Fix ipa-modref pure/const discovery PR ipa/103200 * ipa-modref.c (analyze_function, modref_propagate_in_scc): Do not mark pure/const function if there are side-effects. with -fdump-ipa-all $ grep found t.c.087i.modref Function found to be const: sctlr_rmw/2 Function found to be const: sctlr_read_multiple/3 Function found to be const: sctlr_write_multiple/4 Function found to be const: sctlr_rmw_multiple/5 even though t.c.086i.pure-const correctly identifies asm volatile as not const/pure.=