public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "nsz at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-105160-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105160 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" \ : "=r" (__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 = sctlr_read(); val |= 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=gcc.git;h=1b62cddcf091fb8cadf575246a7d3ff778650a6b commit 1b62cddcf091fb8cadf575246a7d3ff778650a6b Author: Jan Hubicka <jh@suse.cz> 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.
next reply other threads:[~2022-04-05 11:50 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-05 11:50 nsz at gcc dot gnu.org [this message] 2022-04-05 11:58 ` [Bug ipa/105160] " rguenth at gcc dot gnu.org 2022-04-05 12:19 ` rguenth at gcc dot gnu.org 2022-04-05 12:30 ` rguenth at gcc dot gnu.org 2022-04-05 14:54 ` hubicka at gcc dot gnu.org 2022-04-05 21:01 ` hubicka at gcc dot gnu.org 2022-04-06 7:08 ` peterz at infradead dot org 2022-04-06 7:10 ` peterz at infradead dot org 2022-04-07 14:46 ` jeremy.linton at arm dot com 2022-04-07 14:48 ` jeremy.linton at arm dot com 2022-04-09 19:11 ` hubicka at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-105160-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).