This is the mail archive of the gcc@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: Question regarding constraint usage within inline asm


On Mon, Feb 18, 2019 at 01:13:31PM -0600, Peter Bergner wrote:
> I have a question about constraint usage in inline asm when we have
> an early clobber output operand.  The test case is from PR89313 and
> looks like the code below (I'm using "r3" for the reg on ppc, but
> you could also use "rax" on x86_64, etc.).
> 
> long input;
> long
> bug (void)
> {
>   register long output asm ("r3");
>   asm ("blah %0, %1, %2" : "=&r" (output) : "r" (input), "0" (input));
>   return output;
> }
> 
> I know an input operand can have a matching constraint associated with
> an early clobber operand, as there seems to be code that explicitly
> mentions this scenario.  In this case, the user has to manually ensure
> that the input operand is not clobbered by the early clobber operand.
> In the case that the input operand uses an "r" constraint, we just
> ensure that the early clobber operand and the input operand are assigned
> different registers.  My question is, what about the case above where
> we have the same variable being used for two different inputs with
> constraints that seem to be incompatible?

Without the asm("r3") gcc will provide your "blah" instruction with
one register for %0 and %2, and another register for %1.  Both
registers will be initialised with the value of "input".

>  Clearly, we cannot assign
> a register to the "input" variable that is both the same and different
> to the register that is assigned to "output".

No, you certainly can do that.  I think you have found a bug in lra.

-- 
Alan Modra
Australia Development Lab, IBM


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