Re: GCC 12 miscompilation of volatile asm (was: Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect)

2022-04-11 Thread Jeremy Linton via Gcc
Hi, On 4/11/22 05:31, Mark Rutland wrote: On Tue, Apr 05, 2022 at 01:51:30PM +0100, Mark Rutland wrote: Hi all, [adding kernel folk who work on asm stuff] As a heads-up, GCC 12 (not yet released) appears to erroneously optimize away calls to functions with volatile asm. Szabolcs has raised a

Re: GCC 12 miscompilation of volatile asm (was: Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect)

2022-04-11 Thread Mark Rutland via Gcc
On Tue, Apr 05, 2022 at 01:51:30PM +0100, Mark Rutland wrote: > Hi all, > > [adding kernel folk who work on asm stuff] > > As a heads-up, GCC 12 (not yet released) appears to erroneously optimize away > calls to functions with volatile asm. Szabolcs has raised an issue on the GCC > bugzilla: >

Re: GCC 12 miscompilation of volatile asm (was: Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect)

2022-04-11 Thread Mark Rutland via Gcc
On Tue, Apr 05, 2022 at 04:05:22PM +0200, Peter Zijlstra wrote: > On Tue, Apr 05, 2022 at 01:51:30PM +0100, Mark Rutland wrote: > > Hi all, > > > > [adding kernel folk who work on asm stuff] > > > > As a heads-up, GCC 12 (not yet released) appears to erroneously optimize > > away > > calls to fu

Re: GCC 12 miscompilation of volatile asm (was: Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect)

2022-04-05 Thread Peter Zijlstra
On Tue, Apr 05, 2022 at 01:51:30PM +0100, Mark Rutland wrote: > Hi all, > > [adding kernel folk who work on asm stuff] > > As a heads-up, GCC 12 (not yet released) appears to erroneously optimize away > calls to functions with volatile asm. Szabolcs has raised an issue on the GCC > bugzilla: >

Re: GCC 12 miscompilation of volatile asm (was: Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect)

2022-04-05 Thread Andrew Cooper via Gcc
On 05/04/2022 14:04, Mark Rutland wrote: > On Tue, Apr 05, 2022 at 01:51:30PM +0100, Mark Rutland wrote: > My x86_64 test case is: > > Per compiler explorer (https://godbolt.org/z/cveff9hq5) GCC trunk currently > compiles this as: > > | msr_rmw_set_bits: > | mov rcx, rdi > | rdm

Re: GCC 12 miscompilation of volatile asm (was: Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect)

2022-04-05 Thread Mark Rutland via Gcc
Sorry, I copied the wrong version of the x86_64 assembly as generated by GCC 11.2.0). Updated below. On Tue, Apr 05, 2022 at 01:51:30PM +0100, Mark Rutland wrote: > My x86_64 test case is: > > | unsigned long rdmsr(unsigned long reg) > | { > | unsigned int lo, hi; > | > | asm volatile( >

GCC 12 miscompilation of volatile asm (was: Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect)

2022-04-05 Thread Mark Rutland via Gcc
Hi all, [adding kernel folk who work on asm stuff] As a heads-up, GCC 12 (not yet released) appears to erroneously optimize away calls to functions with volatile asm. Szabolcs has raised an issue on the GCC bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105160 ... which is a P1 rele

Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect

2022-04-04 Thread Will Deacon via Gcc
On Sun, Apr 03, 2022 at 09:47:47AM +0200, Ard Biesheuvel wrote: > On Sun, 3 Apr 2022 at 09:47, Ard Biesheuvel wrote: > > On Sun, 3 Apr 2022 at 09:38, Andrew Pinski wrote: > > > It might not be the most restricted fix but it is a fix. > > > The best fix is to tell that you are writing to that loca

Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect

2022-04-03 Thread Doug Berger via Gcc
On 4/3/2022 12:36 AM, Andrew Pinski wrote: On Fri, Apr 1, 2022 at 10:24 AM Mark Rutland via Gcc wrote: Hi Jeremy, Thanks for raising this. On Fri, Apr 01, 2022 at 11:44:06AM -0500, Jeremy Linton wrote: The relaxed variants of read/write macros are only declared as `asm volatile()` which for

Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect

2022-04-03 Thread Ard Biesheuvel via Gcc
On Sun, 3 Apr 2022 at 09:47, Ard Biesheuvel wrote: > > On Sun, 3 Apr 2022 at 09:38, Andrew Pinski wrote: > > > > On Fri, Apr 1, 2022 at 10:24 AM Mark Rutland via Gcc > > wrote: > > > > > > Hi Jeremy, > > > > > > Thanks for raising this. > > > > > > On Fri, Apr 01, 2022 at 11:44:06AM -0500, Jere

Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect

2022-04-03 Thread Ard Biesheuvel via Gcc
On Sun, 3 Apr 2022 at 09:38, Andrew Pinski wrote: > > On Fri, Apr 1, 2022 at 10:24 AM Mark Rutland via Gcc wrote: > > > > Hi Jeremy, > > > > Thanks for raising this. > > > > On Fri, Apr 01, 2022 at 11:44:06AM -0500, Jeremy Linton wrote: > > > The relaxed variants of read/write macros are only dec

Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect

2022-04-03 Thread Andrew Pinski via Gcc
On Fri, Apr 1, 2022 at 10:24 AM Mark Rutland via Gcc wrote: > > Hi Jeremy, > > Thanks for raising this. > > On Fri, Apr 01, 2022 at 11:44:06AM -0500, Jeremy Linton wrote: > > The relaxed variants of read/write macros are only declared > > as `asm volatile()` which forces the compiler to generate t

Re: [PATCH] arm64/io: Remind compiler that there is a memory side effect

2022-04-01 Thread Mark Rutland via Gcc
Hi Jeremy, Thanks for raising this. On Fri, Apr 01, 2022 at 11:44:06AM -0500, Jeremy Linton wrote: > The relaxed variants of read/write macros are only declared > as `asm volatile()` which forces the compiler to generate the > instruction in the code path as intended. The only problem > is that i