[Bug ipa/113293] Incorrect code after inlining function containing extended asm

2024-01-09 Thread dories.spirits_0p at icloud dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113293

--- Comment #4 from KBDeveloper  ---
(In reply to Alexander Monakov from comment #3)
> (In reply to KBDeveloper from comment #2)
> > 
> > Ah, that makes sense. I had assumed that taking the address of arg would
> > force gcc to store it in memory somewhere. 
> > Is there a reason why gcc then allocates 8 bytes on the stack and fills r1
> > with sp - #7? Or is what I had just UB and gcc can do whatever?
> 
> The compiler allocates stack memory for 'arg' and passes the address of
> 'arg' to the asm; it is necessary in case the asm does something with it
> without reading 'arg' itself. One example would be installing a hardware
> watchpoint on that memory location.

That makes sense. Thanks for the explanation (and your time!)

[Bug ipa/113293] Incorrect code after inlining function containing extended asm

2024-01-09 Thread amonakov at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113293

Alexander Monakov  changed:

   What|Removed |Added

 CC||amonakov at gcc dot gnu.org

--- Comment #3 from Alexander Monakov  ---
(In reply to KBDeveloper from comment #2)
> 
> Ah, that makes sense. I had assumed that taking the address of arg would
> force gcc to store it in memory somewhere. 
> Is there a reason why gcc then allocates 8 bytes on the stack and fills r1
> with sp - #7? Or is what I had just UB and gcc can do whatever?

The compiler allocates stack memory for 'arg' and passes the address of 'arg'
to the asm; it is necessary in case the asm does something with it without
reading 'arg' itself. One example would be installing a hardware watchpoint on
that memory location.

[Bug ipa/113293] Incorrect code after inlining function containing extended asm

2024-01-09 Thread dories.spirits_0p at icloud dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113293

--- Comment #2 from KBDeveloper  ---
(In reply to Andrew Pinski from comment #1)
> The inline-asm is not marking as clobbering memory.
> 
> In this case since you just pass the address of the variable, gcc does not
> know the inline-asm will read memory at all, it deletes the store. Anyways
> adding "memory" as a clobber to the inline-asm, fixes the issue.

Ah, that makes sense. I had assumed that taking the address of arg would force
gcc to store it in memory somewhere. 
Is there a reason why gcc then allocates 8 bytes on the stack and fills r1 with
sp - #7? Or is what I had just UB and gcc can do whatever?

At any rate, thanks for the quick response.

[Bug ipa/113293] Incorrect code after inlining function containing extended asm

2024-01-09 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113293

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
   Keywords||inline-asm
 Resolution|--- |INVALID

--- Comment #1 from Andrew Pinski  ---
The inline-asm is not marking as clobbering memory.

In this case since you just pass the address of the variable, gcc does not know
the inline-asm will read memory at all, it deletes the store. Anyways adding
"memory" as a clobber to the inline-asm, fixes the issue.