public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/105160] New: [12 regression] ipa modref marks functions with asm volatile as const or pure
@ 2022-04-05 11:50 nsz at gcc dot gnu.org
  2022-04-05 11:58 ` [Bug ipa/105160] " rguenth at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: nsz at gcc dot gnu.org @ 2022-04-05 11:50 UTC (permalink / raw)
  To: gcc-bugs

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.

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

end of thread, other threads:[~2022-04-09 19:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 11:50 [Bug ipa/105160] New: [12 regression] ipa modref marks functions with asm volatile as const or pure nsz at gcc dot gnu.org
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

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).