PR 52125: Detecting which operands are used in an asm

Jeff Law law@redhat.com
Thu Jan 23 04:12:00 GMT 2014


On 01/19/14 10:33, Richard Sandiford wrote:
> The MIPS %hi and %lo relocation operators act as a pair on REL targets;
> you need to see the partnering %lo in order to calculate the addend for
> a %hi and detect carries properly.  The assembler therefore complains if
> %hi is used without a corresponding %lo.
>
> The MIPS backend tries to remove unmatched %his in mips_reorg.
> The problem is that it can wrongly keep a %hi(foo) in cases like:
>
>     asm ("" : "=m" (foo));
>
> where a LO_SUM MEM appears as an operand at the rtl level but where
> %lo(foo) doesn't appear in the assembly code.
>
> It's very hard without fully parsing an asm to know whether it will need
> the LO_SUM or not.  E.g. the operand could appear in the asm string
> but could be protected by an .if or only be used in a comment.  But it
> should be safe to assume that the LO_SUM in operand N isn't needed if
> %N or %<letter>N doesn't appear in the string, since AFAIK there's
> no other way for the asm to know which register contains the high part.
> Specifically, things like:
>
>     asm ("sw $0,foo" : "=m" (foo));
>
> work fine either way, since the %hi is implicit in the SW macro.
>
> I split out the routine to detect which operands are used since it
> seemed like it might be more generally useful.
>
> Tested on mips64-linux-gnu, where it fixes the gcc.dg/guality/pr36728-2.c
> failures for -mabi=32.  OK for the target-independent bits?
>
> Thanks,
> Richard
>
>
> gcc/
> 	PR target/52125
> 	* rtl.h (get_referenced_operands): Declare.
> 	* recog.c (get_referenced_operands): New function.
> 	* config/mips/mips.c (mips_reorg_process_insns): Check which asm
> 	operands have been referenced when recording LO_SUM references.
>
> gcc/testsuite/
> 	PR target/52125
> 	* gcc.dg/pr48774.c: Remove skip for mips_rel.
> 	* gcc.target/mips/pr52125.c: New test.
Machine independent bits are fine with me.

Jeff



More information about the Gcc-patches mailing list