This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Optimization breaks inline asm code w/ptrs

On 2017/8/14 20:41, Alan Modra wrote:
On Sun, Aug 13, 2017 at 10:25:14PM +0930, Alan Modra wrote:
On Sun, Aug 13, 2017 at 03:35:15AM -0700, David Wohlferd wrote:
Using "m"(*pStr) as an (unused) input parameter has no effect.

Use "m" (*(const void *)pStr) and ignore the warning, or use
"m" (*(const struct {char a; char x[];} *) pStr).

or even better "m" (*(const char (*)[]) pStr).

This should work in the sense that GCC now thinks bytes adjacent to `pStr` are subject to modification by the asm statement.

But I just tried GCC 7.2 and it seems that even if such a "+m" constraint is the only output parameter of an asm statement and there is no `volatile` or the "memory" clobber, GCC optimizer will not optimize the asm statement away, which is the case if a plain `"+m"(*pStr)` is used.

The issue is one of letting gcc know what memory is accessed by the
asm, if you don't want to use a "memory" clobber.  And there are very
good reasons to avoid clobbering all memory.

"m"(*pStr) ought to work IMO, but apparently just tells gcc you are
only interested in the first character.  Of course that is exactly
what *pStr is, but in this context it would be nicer if it meant the
entire array.

I take that back.  The relatively simple cast to differentiate a
pointer to a char from a pointer to an indeterminate length char array
makes it quite unnecessary for "m"(*pStr) to be treated as as array

I've opened to
track the lack of documentation.

Yes. I hope there will be a memory-range constraint in the future.

Best regards,

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]