[PATCH] V7, #4 of 7, Add explicit (0),1 to @pcrel references

Michael Meissner meissner@linux.ibm.com
Mon Nov 25 23:00:00 GMT 2019


On Fri, Nov 22, 2019 at 06:52:42PM -0600, Segher Boessenkool wrote:
> On Thu, Nov 14, 2019 at 05:51:14PM -0500, Michael Meissner wrote:
> > In some of my previous work, I had make a mistake forgetting that the PADDI
> > instruction did not allow adding a PC-relative reference to a register (you can
> > either load up a PC-relative address without adding a register, or you can add
> > a register to a constant).  The assembler allowed the instruction, but it
> > didn't do what I expected.
> 
> So, what was the instruction?

If you write:

	paddi 10,9,foo@pcrel

The assembler will interpret this as:

	paddi 10,9,(.-foo),0

I.e. it will add the difference from current instruction to foo and register 2
and place it in register 10.  But it will not add the current location for the
paddi.

Of course it might make sense if the assembler could flag the first line as an
error, and if you really wanted to write that, you should use:

	paddi 10,9,foo@pcrel,0

> > --- gcc/config/rs6000/rs6000.c	(revision 278175)
> > +++ gcc/config/rs6000/rs6000.c	(working copy)
> > @@ -13241,7 +13241,10 @@ print_operand_address (FILE *file, rtx x
> >        if (SYMBOL_REF_P (x) && !SYMBOL_REF_LOCAL_P (x))
> >  	fprintf (file, "@got");
> >  
> > -      fprintf (file, "@pcrel");
> > +      /* Specifically add (0),1 to catch uses where a @pcrel was added to a an
> > +	 address with a base register, since the hardware does not support
> > +	 adding a base register to a PC-relative address.  */
> > +      fprintf (file, "@pcrel(0),1");
> 
> But this is print_operand_address, it shouldn't know anything about
> specific instructions, it certainly shouldn't print commas and other
> fields.
> 
> Can you fix this in the caller?

Since the code was invalid, the add insn modification to allow adding an
address has been removed.  It was a suggestion after I made the mistake to make
sure that nobody else would make that mistake.

As I said, this is an optional patch.  The idea was to be helpful to other
people in the future, in that if they try to generate an add between a register
and a PC-relative label, that the assembler would give a warnging (due to (0),1
present).

If you don't think it is important to do that protection, I can leave it out.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.ibm.com, phone: +1 (978) 899-4797



More information about the Gcc-patches mailing list