avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] foo++, subi vs inc?


From: Marek Michalkiewicz
Subject: Re: [avr-gcc-list] foo++, subi vs inc?
Date: Wed, 12 Nov 2008 22:51:35 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

On Tue, Nov 11, 2008 at 06:24:09PM -0500, Sparr wrote:
>    Why does "foo++;" compile to "subi Rd,lo8(-(1))" instead of "inc Rd"?  I
>    am keeping global register variables in registers below 16, which are not
>    valid for subi so they get duplicated to perform the increment.  I am
>    preparing to check out the machine description for the avr target, but
>    thought I would ask here before I go that deep.

The addqi3 pattern already has alternatives that use inc/dec - listed
after the one using subi.  You could try to change the order so that
"subi" is the last one and inc/dec is preferred, all else being equal.
Not sure why this doesn't already work as expected in your case though,
despite this paragraph from gccint.info:

   If all the operands fit any one alternative, the instruction is valid.
  Otherwise, for each alternative, the compiler counts how many
  instructions must be added to copy the operands so that that
  alternative applies.  The alternative requiring the least copying is
  chosen.  If two alternatives need the same amount of copying, the one
  that comes first is chosen.  These choices can be altered with the `?'
  and `!' characters:

Based on the above, it seems GCC thinks the two alternatives require the
same amount of copying, even though subi may need more as it only works
with r16-r31.  You could also experiment with putting `?' in the second
alternative, to disparage "subi" slightly.

Hope this helps,
Marek




reply via email to

[Prev in Thread] Current Thread [Next in Thread]