This is the mail archive of the gcc-bugs@gcc.gnu.org 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: label reference missed


On Thu, Aug 22, 2002 at 08:38:36PM -0700, Ulrich Drepper wrote:
> 
> I have this little piece of code:
...
>   asm volatile ("jmp %0"::"m" (*&&fff));

This is just the classic "you can't jump out of an asm()" issue.

> I imagine that the change necessary to achieve this is minimal.  It 
> would only require to recognize label references and mark the basic 
> blocks they introduce as alive.

Not so simple; the optimizer would also have to be able to synthesize
an edge from the asm to the label, and in general this could be quite
difficult.

> The possibilities opened by code like that above are quite big.  On x86, 
> for instance, we often have sequences like this (after macro expansion) 
> in lowlevel code:
> 
>   if (({ unsigned char r;
>          asm ("cmpxchgl %3, %0; sete %1"
>               : "=m" (mem), "=q" (r)
>               : "0" (mem), "r" (oldval));
>          r; }) != 0)
>     ...

Counterproposal: There is a longstanding note in the description of
the extended asm syntax to the effect that it's not practical to give
access to the condition codes left by an asm(), because output reloads
might interfere.  However, this is a non-problem for machines that
don't use cc0, which includes the i386.  Notation like

   if (({ __builtin_flags_t __r;
	  asm ("cmpxchgl %3, %0"
	       : "=m" (mem), "=C" (__r)
	       : "0" (mem), "r" (oldval));
	  __r; }))

should be practical: where __builtin_flags_t is a magic type that maps
to CCmode, and the "C" constraint allows only (reg:CC 17).  (We might
need __builtin_cc_t, _ccz_t, _ccno_t, etc.)  This seems both easier to
implement, and cleaner notation to boot.  Bonus points for permitting

 if (asm ("cmpxchgl %3, %0"
	  : "=m" (mem), "=C"
	  : "0" (mem), "r" (oldval)))

which however might require modifying the parser.

(Seems to me that tagging such an asm() such that sets_cc0_p is true
for it, should suffice to make this work on cc0 machines too, but
since cc0 is not used by modern ports, it's likely to be a nonissue.)

zw


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